X Forwarding with Amazon EC2

Thousands people use Amazon EC2 to run they Unix (read Linux) services on the cloud. Sometimes you need to run something that has UI, and you come up to the fact that you need to forward your “X” somewhere out of the EC2 to the available X Windows. You can do it just in 5 minutes.

1. You might need to install some “X” packets
[ec2-user@remote_ec2_box ~]$> sudo yum install xorg-x11-xauth.x86_64 xorg-x11-server-utils.x86_64
1. You should check your sshd config on your remote ec2 box to make sure that X forwarding is enabled:
[ec2-user@remote_ec2_box ~]$> sudo grep X11 /etc/ssh/sshd_config ~/.ssh/* | grep -v '#'
/etc/ssh/sshd_config:X11Forwarding yes

2. Now you need to make “X forwarding”
[user@local_box ~]$> echo $DISPLAY
:0.0 (or :10.0)
[user@local_box ~]$> ssh -X -i ec2-user@remote_ec2_box
[ec2-user@remote_ec2_box ~]$> echo $DISPLAY
[ec2-user@remote_ec2_box ~]$>

Now it should work. But make sure that it will be running very slowly, from/to computer in Seattle corpnet from/to US based EC2 datacenter.

Added later:
Just a snapshot of the steps to run the same scenario from non-EC2 hosts.


[host you want to see result]$ export DISPLAY=:0.0
[host you want to see result]$ echo $DISPLAY
:0.0
[host you want to see result]$ ssh -X -l[user] [host you want to run]
[host you want to run]$ echo $DISPLAY
localhost:10.0
[host you want to run]$ ./app
See the result on the [host you want to see result]

7 Comments

Filed under technology

Installing Redis 2.2.14 on CentOS 5/6 and running with an “init” script.

Here are simple steps to get Redis 2.2.14 running on CentOS 5/6 (local desktop running CentOS 5.4 and EC2 AMI running CentOS 6.1) using an init script.
The setup is intended to be used on developer desktop/laptop rather than production infrastructure.

As ever, first download and unzip Redis from here.

$> cd /tmp
$> wget http://redis.googlecode.com/files/redis-2.2.14.tar.gz
$> tar xvfz redis-2.2.14.tar.gz
$> cd redis-2.2.14
$> make
$> sudo make install

Your Redis binaries should now be located in /usr/local/bin.

To get an init script and Redis config working cleanly with this setup, download my init and config files from my development/redis repo.
My init script is pretty standard. However my redis.conf sets Redis up with 1Gb of virtual memory and 20Gb of swap space – intended for general development purposes.

$> wget http://www.zorranlabs.com/development/redis/redis.conf
$> wget http://www.zorranlabs.com/development/redis/redis-server

Runner “redis-server” is using start-stop-daemon from Debian distribution, so it needs to be compiled on CentOS. You can take it from my repo. Make sure you have gcc-c++, otherwise, you might get the following error: “exec: g++: not found”

$> sudo yum install gcc gcc-c++ m4 make automake libtool gettext openssl-devel
$> wget http://www.zorranlabs.com/development/start-stop-daemon/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
$> tar xvfz apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
$> cd apps/sys-utils/start-stop-daemon-IR1_9_18-2/
$> gcc start-stop-daemon.c -o start-stop-daemon
$> cp start-stop-daemon /usr/sbin/

There is a small difference between start-stop-daemon versions, so redis-server script should be update:
Please replace the following line

if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid redis:redis --exec $DAEMON -- $DAEMON_ARGS

to this one

if start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid redis:redis --exec $DAEMON -- $DAEMON_ARGS

Update redis.conf to change the following line

vm-enabled yes

to the following line

vm-enabled no

Otherwise, you will get the following error, trying to start redis-server:

“Redis Virtual Memory is going to be deprecated soon,
we think you should NOT use it, but use Redis only if
your data is suitable for an in-memory database.
If you *really* want VM add this in the config file:

really-use-vm yes

Copy init script, and redis.conf it their proper locations:

$> sudo cp redis-server /etc/init.d/redis-server
$> sudo chmod +x /etc/init.d/redis-server
$> sudo cp redis.conf /etc/redis.conf

Before you can fire up the Redis server for the first time, you’ll need add a redis user and prep a data and logging folder.

$> sudo /usr/sbin/useradd redis
$> sudo mkdir -p /var/lib/redis
$> sudo mkdir -p /var/log/redis
$> sudo chown redis.redis /var/lib/redis
$> sudo chown redis.redis /var/log/redis

Also, you need to activate your Redis services init script by adding it to your system’s run-level configuration. That way the service will startup during the boot sequence and stop nicely during the OS’ shutdown procedure.

## initial check, should show nothing
$> sudo /sbin/chkconfig --list | grep redis
$> sudo /sbin/chkconfig --add redis-server
## confirmation, should retruen something like that:
## redis-server 0:off 1:off 2:on 3:on 4:on 5:on 6:off
$> sudo /sbin/chkconfig --list | grep redis
#enable service, specifies run levels 3 and 5:
$> sudo /sbin/chkconfig --level 35 redis-server on

You’re now ready to launch Redis server with and should see that it is started:

$> sudo /etc/init.d/redis-server start
Starting redis-server: redis-server

Netstat should tell you that you listen on redis port, 6379

$> netstat -an | grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN

Do not forget to “open” port 6379 on your firewall to get it accessible outside of the host

Good luck and thanks authors of the following posts for the guides and ideas:


http://www.denofubiquity.com/nosql/412/

http://www.cyberciti.biz/faq/rhel5-update-rcd-command/
https://www.centos.org/modules/newbb/viewtopic.php?viewmode=flat&topic_id=24207&forum=40
http://chast.in/start-stop-daemon-on-centos.html

10 Comments

Filed under technology