Diciembre 10

Setting up cluster synchronization with csync2

Having to synchronize some data among a Debian linux cluster, i settled on using csync2 for the job.
Here’s a short guide to set it up.

We are assuming two machines here, 01.cluster and 02.cluster. The 01.cluster is gonna be our “master” in this setup.

First on both machines install csync2 by executing:

apt-get install csync2

On each node we now need to generate a certificate for csync2 to communicate. We do it by the following commands, When asked to set a challenge password leave it empty, and leave the common name empty.:

openssl genrsa -out /etc/csync2_ssl_key.pem 1024
openssl req -new -key /etc/csync2_ssl_key.pem -out /etc/csync2_ssl_cert.csr
openssl x509 -req -days 600 -in /etc/csync2_ssl_cert.csr -signkey /etc/csync2_ssl_key.pem -out /etc/csync2_ssl_cert.pem

On the master we need to generate a preshared key for the nodes to communicate with:

csync2 -k /etc/csync2_ssl_cert.key

Note: You might experience a somewhat hang on the command, this is because the /dev/random pool isn’t filling up fast enough. To remedy this open a secondary connection to the server, and jab a bit around. Look in files, download some big file whatever makes the /dev/random entropy fill up

Now we need to set up the configuration file on the master, which is in /etc/csync2.cfg.

# Csync2 configuration example
group cluster
	host 01.cluster;
	host (02.cluster); # Slave host

	key /etc/csync2_ssl_cert.key;

	include /var/www;
	exclude /var/www/sessions;

	auto none;

Note: the hostname of all the machines needs to match the output of the hostname command.
The parentheses around 02.cluster is to make the synchronization only work in one direction. Now we need to copy the csync.cfg and the csync2_ssl_cert.key to the slave server(s).

After all this do a /etc/init.d/openbsd-inetd restart on all machines.
And run csync -x on the master to synchronize data on the slaves. Note data on the slave(s) WILL be overwritten/deleted

A logical step now would be to run csync –x from within a cron job. Which i will leave for a later post.


If lsyncd doesn’t want to start, then check in the log file. In our case the log file is /var/log/lsyncd.log
If you encounter a last line like:
Tue Oct 30 18:59:40 2012 Error: Terminating since out of inotify watches.
Tue Oct 30 18:59:40 2012 Error: Consider increasing /proc/sys/fs/inotify/max_user_watches

Then do one of the followings:

To change immediately the limit, run:
# echo 32768 > /proc/sys/fs/inotify/max_user_watches

To make the change permanent, edit the file /etc/sysctl.conf and add this line to the end of the file:

After a crash of the start you should delete the lock file as follows:
rm /var/lock/lsyncd

To check if it runs, run the command:
root@ado:~# ps ax | grep lsyncd
12635 ? Ss 0:00 /usr/local/bin/lsyncd /etc/lsyncd.conf
12647 pts/2 S+ 0:00 grep lsyncd

First Synchronize with Csync2 Manually

Before setup cron job for handling Csync2 periodically, let’s trial manually at dev6c1:

csync2 -xv

If you get any error message you may try will following commands, too:

csync2 -xvvv
csync2 -TI

Else it should already works as expected.

Periodically Synchronize with Csync2

Now setup cron jobs with “crontab -e” as below:

*/1 * * * * csync2 -x >/dev/null 2>&1

Once save Csync2 will run once per 1 minute, check, synchronize and restart your service if required automatically.

Category: STORAGE, SYNC, SYNC | Los comentarios están deshabilitados en Setting up cluster synchronization with csync2