Marc

Burrows

Web Developer


Welcome to my blog.

Every so often I come across some information or I’ve developed something myself to solve a problem, I will post it here. Send me a Tweet or something to let me know if it has been of use to you. Thanks.

LsyncD with AWS

January 24, 2014Marc0 Comments

LsyncD is a live syncing daemon that watches a local directory for changes and then every few seconds will spawn processes to synchronize changes to another server. This is based on rsync. Having found nothing around on how to set up LsyncD with AWS, I worked it out, and then thought it may be of use to others who were in the same predicament to me. If you are deploying an application through Elastic Beanstalk, then please note, this can not be set up using Elastic Beanstalk. This must be done via the command line on the two (or more) EC2 servers. This assumes that you only have two servers, and have access to the command line on each one through Putty. If you have more than two servers, then you just need to repeat the processes for the original slave server.

This blog post is based on the following link, but tailored for Amazon Web Services: http://www.rackspace.com/knowledge_center/article/install-and-configure-lsyncd

Allow the Master Server to connect to the slave server without a password

  1. On the master server, log in through putty and run the following:

ssh-keygen -t rsa

  1. You will get asked to enter the file in which to save the key. You want to save it as “/home/ec2-user/.ssh/id_rsa”
  2. FTP into the master server and then download the file “/home/ec2-user/.ssh/id_rsa.pub”
  3. FTP into the slave server and upload this file to “/home/ec2-user/.ssh/” and rename to “master.pub”
  4. Putty onto the slave server and enter the following command:

cat ~/.ssh/master.pub >> ~/.ssh/authorized_keys

  1. Now Putty onto the master server and enter the following command. “Address-of-slave” is the Private IP of the slave server.

ssh -i home/ec2-user/.ssh/id_rsa ec2-user@address-of-slave

  1. it should ask you if you accept their public key. Accept it.

Installing LsyncD with AWS

Install Package Dependencies on the Master EC2 Server

  1. Run this command to install needed dependencies:

yum -y install lua lua-devel pkgconfig gcc asciidoc

Install LsyncD with AWS

  1. Perform the following commands, with each line being a separate command.

cd /var/tmp
wget http://lsyncd.googlecode.com/files/lsyncd-2.1.4.tar.gz (or latest version)
tar xzvf lsyncd-2.1.4.tar.gz
cd lsyncd-2.1.4
sudo ./configure && make
sudo make install

Set Up the Startup Scripts

  1. Do the following command and then paste the code under “Set Up the Startup Scripts”, “For Centos” from the link above into the file.

sudo nano /etc/init.d/lsyncd

  1. Once created, do

chkconfig lsyncd on

  1. Then go down to the “Configure Log Rotation” section from the link above, do the following command and then paste the code into the file.

sudo nano /etc/logrotate.d/lsyncd

Set Up the Config File

  1. The next file that is created lets LsyncD which folders need to be synced.
  2. Create the file:

sudo nano /etc/lsyncd.lua

  1. Paste the following into the file:

settings {
logfile = “/var/log/lsyncd/lsyncd.log”,
statusFile = “/var/log/lsyncd/lsyncd-status.log”,
statusInterval = 20
}
sync {
default.rsync,
source=”/var/app/”,
target=”your.clone.private.ip.address:/var/app/”,
rsync = {
compress = true,
acls = true,
verbose = true,
rsh = “/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no -i /home/ec2-user/.ssh/id_rsa -l ec2-user” }
}

  1. Change the “your.clone.private.ip.address” to the private IP address of the slave server
  2. Save the file
  3. Check that lsyncd is working by forcing it to run:

sudo /usr/local/bin/lsyncd /etc/lsyncd.lua -nodaemon

  1. Start Lsyncd:

sudo service lsyncd start

  1. FTP onto master server and upload a file.
  2. FTP onto the slave server and check to see that the file uploaded to the master server has transferred over to the slave server.