Set Up A Simple High-Availability Web Server For A Small Company Using Debian Lenny - Page 2
4. Configure heartbeat And ldirectord
We have to create 3 configuration files for heartbeat.
lb01/lb02
pico /etc/ha.d/ha.cf
logfacility local0
bcast eth0 # Linux
mcast eth0 225.0.0.1 694 1 0
auto_failback off
node lb01
node lb02
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
Important: As node we must use the output of
uname -n
on lb01 and lb02.
lb01/lb02
pico /etc/ha.d/haresources
lb01 \
ldirectord::ldirectord.cf \
LVSSyncDaemonSwap::master \
IPaddr2::10.253.66.200/24/eth0/10.253.66.255
The first word is the output of
uname -n
on lb01, no matter if you create the file on lb01 or lb02! After IPaddr2 we put our virtual IP address 10.253.66.200.
lb01/lb02
pico /etc/ha.d/authkeys
auth 3
3 md5 secretstring
secretstring is a password which the two heartbeat daemons on lb01 and lb02 use to authenticate against each other. Use your own string here.
/etc/ha.d/authkeys should be readable by root only, therefore we do this:
lb01/lb02
chmod 600 /etc/ha.d/authkeys
ldirectord is the actual load balancer. We are going to configure our two load balancers (lb01.example.com and lb02.example.com) in an active/passive setup, which means we have one active load balancer, and the other one is a secondary and becomes active if the active one [Master] fails. To make it work, we must create the ldirectord configuration file /etc/ha.d/ldirectord.cf which again must be identical on lb01 and lb02.
lb01/lb02
pico /etc/ha.d/ldirectord.cf
checktimeout=10
checkinterval=2
autoreload=no
logfile="local0"
quiescent=yes
virtual=10.253.66.200:80
fallback=127.0.0.1:80 gate
In the virtual= line type your virtual IP address (10.253.66.200 in this tutorial).
lb01/lb02
update-rc.d heartbeat start 75 2 3 4 5 . stop 05 0 1 6 .
update-rc.d -f ldirectord remove
Finally we start heartbeat (and with it ldirectord):
lb01/lb02
/etc/init.d/ldirectord stop
/etc/init.d/heartbeat start
5. Test The Load Balancers
Let's check if both load balancers work as expected:
lb01/lb02:
ip addr sh eth0
The active load balancer [Master] should list the virtual IP address (10.253.66.200):
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:0c:29:b7:56:9c brd ff:ff:ff:ff:ff:ff inet 10.253.66.19/24 brd 10.253.66.255 scope global eth0 inet 10.253.66.200/24 brd 10.253.66.255 scope global secondary eth0
The secndary one[Backup] should show this:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:0c:29:b7:56:9c brd ff:ff:ff:ff:ff:ff inet 10.253.66.19/24 brd 10.253.66.255 scope global eth0
lb01/lb02:
ldirectord ldirectord.cf status
Output on the active load balancer [Master]:
ldirectord for /etc/ha.d/ldirectord.cf is running with pid: 3728
Output on the secondary [Backup]:
ldirectord is stopped for /etc/ha.d/ldirectord.cf
lb01/lb02:
ipvsadm -L -n
Output on the active load balancer [Master]:
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.253.66.200:80 wrr
-> 127.0.0.1:80 Local 1 0 0
Output on the secondary [Backup]:
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
lb01/lb02:
/etc/ha.d/resource.d/LVSSyncDaemonSwap master status
Output on the active load balancer [Master]:
master running (ipvs_syncmaster pid: 3815)
Output on the secondary [Backup]:
master stopped
To test your virtual ip:
ping -c 4 10.253.66.200
PING 10.253.66.200 (10.253.66.200) 56(84) bytes of data. 64 bytes from 10.253.66.200: icmp_seq=1 ttl=64 time=1.94 ms 64 bytes from 10.253.66.200: icmp_seq=2 ttl=64 time=0.110 ms 64 bytes from 10.253.66.200: icmp_seq=3 ttl=64 time=0.049 ms 64 bytes from 10.253.66.200: icmp_seq=4 ttl=64 time=0.048 ms --- 10.253.66.200 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3007ms rtt min/avg/max/mdev = 0.048/0.539/1.949/0.814 ms
If your tests went fine, you can now configure the two Apache nodes.
6. Installation Of Apache + PHP With MySQL Support
Installing the packages:
If you do not have PHP installed already, use this to install the necessary packages:
lb01/lb02:
aptitude install apache2 php5 libapache2-mod-php5 php5-sqlite
This will install PHP, the Apache webserver and the necessary dependencies onto your system.
- Optional: If you want to use MySQL as persistence backend you'll also need to install the mysql-pdo driver:
aptitude install php5-mysql
Start (or restart) apache by issuing one of these commands:
/etc/init.d/apache2 start
or
/etc/init.d/apache2 restart
7. Testing the installation:
Check that your Apache installation is working. Point a browser to http://10.253.66.200/.
E.g.
lynx http://10.253.66.200/
You should see a page displaying the words "It works!".
Note
Test your PHP installation by creating a phpinfo.php file in your Apache document root, e.g. by issuing the following command:
echo '<?php phpinfo(); ?>' > /var/www/phpinfo.php
Then fire up your browser and go to:
lynx http://10.253.66.200/phpinfo.php
You should see a phpinfo page with the correct version number (PHP) at the top.
DONE!