Apache2 Cluster with Csync2 on Ubuntu 12.04 mini-HOWTO
For building a LAMP cluster, besides identity, filesystem and database synchronize, the next step would be service configure synchronize, e.g. Apache2 and PHP. This can be done by using Csync2, including configuration file status monitoring, synchronize and service restart.
This HOWTO will guide you though installation of Csync2 on Ubuntu 12.04. We will therefore handle both Apache2 and PHP5 for clustering with it.
Server Requirement
In this example let's assume we have 2 servers: dev6c1 and dev6c2, with domain name "localdomain" and IP information as below:
172.24.145.25 dev6c1.localdomain dev6c1 172.24.145.26 dev6c2.localdomain dev6c2
Where dev6c1 will be the master for Apache2 and PHP, where dev6c2 will be slave that clone dev6c1's configuration.
Install Csync2
This is simple for Ubuntu, just execute following command on both server:
aptitude -y install csync2
Creating Key File
At dev6c1, first generate the key file for secure connection:
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
csync2 -k /etc/csync2.key
Create Configuration File
Edit /etc/csync2.cfg and update as below:
group dev6 {
host dev6c1 (dev6c2);
key /etc/csync2.key;
include /etc/apache2;
include /etc/php5;
action {
pattern /etc/apache2/sites-enabled/*;
pattern /etc/apache2/mods-enabled/*;
pattern /etc/apache2/apache2.conf;
pattern /etc/php5/*;
exec "/etc/init.d/apache2 restart";
do-local;
}
}
Initialize Csync2 Configuration by Synchronize Manually
Before real handy Csync2 cluster configuration synchronize start, we need to initialize Csync2 configuration manually with rsync as below at dev6c1:
rsync -av /etc/csync2* dev6c2:/etc/
Now restart daemon for both server:
/etc/init.d/openbsd-inetd restart
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.
Reference
- hswong3i's blog
- 1237 reads


Add new comment