Cluster Sinchronization Tool (CSync2)

As you may know, there are many tools for file synchronization between servers that can suit your needs, but Csync2 (Website and Paper) was specially designed for Cluster File Synchronization, which makes it a great tool to synchronize config files and folders.

Now, I’ll show you a simple way of configuring it, by having a master server (where we can make changes to the config files) and one or multiple slave servers, where the files will be synchronized. First of all, we have to install it along with other packages:

:~# sudo apt-get install csync2 sqlite3 openssl xinetd

After having everything installed, we have to create the certificates that will allow Csync2 authenticate between servers so that the files can be synchronized. To do that we do this:

:~# 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

So after having all the certificates, we have to create the Csync2 key by issuing the following:

:~# csync2 -k /etc/csync2_ssl_cert.key

Once all the keys and certificates have been generated, we have to copy them from the master server to the slaves. To do this we can use whatever method you are more familiarized with.

Now, we have to configure xinetd so that Csync2 can work, because it works as an xinetd service. To do this we create a Csync2 file on /etc/xinetd.d/ and edit it like this:

:~# vim /etc/xinetd.d/Csync2

service Csync2
disable = no
protocol = tcp
socket_type = stream
wait = no
user = root
server = /usr/sbin/csync2
server_args = -i

and then we have to add the port number to /etc/services, by doing this:

:~# echo “Csync2 30865/tcp” >> /etc/services

After having done everything, we are now going to configure Csync2 so that we can determine which files are going to be synchronized. For this example, we are going to synchronize /etc/apache2 and /etc/mysql. For that we open /etc/csync2.cfg and we configure it like this:

group testing #group name, we can have multiple groups
host node1; #master server
host (node2); #slave server
host (node3);

key /etc/csync2_ssl_cert.key;

include /etc/apache2/;
include /etc/mysql/;

backup-directory /var/backups/csync2;
backup-generations 3;
auto none; #no automatic sync

Note: This tool does not just synchronize files but issues commands (such as restarting services) after the synchronization process is finished, but, I’ll let you find out how :). We can also have multiple groups with different servers on it. For further information you can refer to its Paper.

Then, we create the Csync2 backup directory:

:~# mkdir /var/backups/csync2

and we restart xinetd:

:~# /etc/init.d/xinetd restart

And finally, we do the first sync by issuing:

:~# csync -x

If errors are displayed here, just ignore them and check if the files have been synchronized. Every time we make a changes to the files in /etc/apache2 or /etc/mysql on the master server, we have to synchronize the changes by issuing the command above.

This entry was posted in How-To, Planet, Ubuntu and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


This site uses Akismet to reduce spam. Learn how your comment data is processed.