Configure two Web server high availability cluster cases with heartbeat:
Topology:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/41/64/wKiom1PU89ujTR7CAAEQ4PSzLvA160.jpg "title=" Qq20140727203823.png "alt=" Wkiom1pu89ujtr7caaeq4pszlva160.jpg "/>
Web1:192.168.0.101
Hostname:web1.example.com
web2:192.168.0.102
Hostname:web2.example.com
vip:192.168.0.254
Server for NFS: 192.168.0.100 (store Web page)
Attention:
1 hostname to be consistent with uname-n
2.web1 synchronization with the date time of the WEB2 host
3.web1 and Web2,ssh Two-machine mutual trust communication
4. Close Iptables and SELinux
Environment configuration:
1 Configuring host Names
Web1:
#vim/etc/sysconfig/network
Hostname=web1.example.com
#hostname web1.example.com
WEB2:
#vim/etc/sysconfig/network
Hostname=web2.example.com
#hostname web2.example.com
2. Configure Hosts file, host name resolution
Web1 and WEB2:
#vim/etc/hosts
192.168.0.101 web1.example.com web1
192.168.0.102web2.example.com web2
3. Realize Web1 and WEB2 SSH dual-machine mutual trust communication
Web1:
#ssh-keygen-t rsa-f "~/.ssh/id_rsa-p" "
#ssh-copy-id I. ssh/id_rsa.pub [email protected]
WEB2:
#ssh-keygen-t rsa-f "~/.ssh/id_rsa-p" "
#ssh-copy-id I. ssh/id_rsa.pub [email protected]
4. Time Synchronization settings
Settings in Web1 and WEB2
#hwclock-S
5. Install the Web server
Web1
#yum-y Install httpd
#chkconfig httpd off
#echo ' Web1 ' >/var/www/html/index.html (Test)
#service httpd Restart
Web2
#yum-y Install httpd
#chkconfig httpd off
#echo ' web2 ' >/var/www/html/index.html (Test)
#service httpd Restart
6. Configuring Server for NFS (192.168.0.100)
#mkdir/webfile
#cd/webfile;echo "NFS" >index.html
#vim/etc/exports
/webfile192.168.0.0/24 (Ro,sync)
#service NFS Start
#showmount-E 192.168.0.100
Two: Install Heartbeat
1. Install heartbeat related software package, have dependency, recommend using Yum installation
heartbeat-2.1.4-11.el5.i386.rpm
heartbeat-pils-2.1.4-11.el5.i386.rpm
heartbeat-stonith-2.1.4-11.el5.i386.rpm
heartbeat-gui-2.1.4-11.el5.i386.rpm
Additional dependency package: libnet-1.1.4-3.el5.i386.rpm perl-mailtools-1.77-1.el5.noarch.rpm
#wget http://dl.fedoraproject.org/pub/epel/5/i386/heartbeat-2.1.4-11.el5.i386.rpm
#wget http://dl.fedoraproject.org/pub/epel/5/i386/heartbeat-gui-2.1.4-11.el5.i386.rpm
#wget http://dl.fedoraproject.org/pub/epel/5/i386/heartbeat-stonith-2.1.4-11.el5.i386.rpm
#wget http://dl.fedoraproject.org/pub/epel/5/i386/heartbeat-pils-2.1.4-11.el5.i386.rpm
#wget http://dl.fedoraproject.org/pub/epel/5/i386/libnet-1.1.6-7.el5.i386.rpm
#wget http://dl.fedoraproject.org/pub/epel/5/i386/perl-MailTools-1.77-1.el5.noarch.rpm
# yum-y Localinstall--nogpgcheck *.rpm
2. Copy the configuration file
#cp/usr/share/doc/heartbeat-2.1.4/{haresources,ha.cf Authkeys}/etc/had.d/
#cd/etc/had.d/
#chmod Authkeys (permissions must be 600, otherwise problems may occur)
3. Edit the configuration file
(1) #vim/ETC/HA.D/HA.CF
Bcast eth0
Node web1.example.com
Node web2.example.com
(2) authentication
#dd if=/dev/random count=1 bs=512 |md5sum
#vim Authkeys
Auth 3
3 MD5 EC92B27792A008B420EC5ADFE0A34EA0//For the random MD5 encryption value generated just by the DD
(3) Configuring resources
#vim haresources
web1.example.com 192.168.0.254/24/eth0 httpd
The primary node is a web1.example.com vip:192.168.0.254 highly available service for Web three resources as a set of
Copy the configuration file into Web2
SCP/ETC/HA.D/{HARESOURCES,AUTHKEYS,HA.CF} [Email PROTECTED]:/ETC/HA.D
Starting heartbeat in 4.web1 and WEB2
#service Heartbeat Start
#ssh web2 ' service heartbeat start '
5. Test heartbeat Web High Availability
Web1 as the main mode test, test the running state of the Web server
#elinks-dump http://192.168.0.254
Web1
The WEB1 is now implemented as a backup mode through the command to test the WEB2 's performance:
Execute on WEB1:
#/usr/share/heartbeat/hb_standby
2012/12/28_19:43:49 going standby [all].
#elinks-dump http://192.168.0.254
Web2
The test shows that when web1 as the main mode, cluster resources are on the WEB1 service;
When web2 as the main mode, the cluster resource is on the WEB2 service
6. Reconfigure the resource implementation Web1 share the same Web page as the WEB2
Web1
#vim/etc/ha.d/haresources
web1.example.com 192.168.0.254/24/eth0 filesystems::192.168.0.100:/webfile::/var/www/html httpd
#scp/etc/ha.d/haresources [Email protected]:/etc/ha.d/
#service Heartbeat Restart
#ssh web2 ' Service heartbeat restart '
7 re-test the fifth step to see the results
Web1 as the main mode test, test the running state of the Web server
#elinks-dump http://192.168.0.254
Nfs
The WEB1 is now implemented as a backup mode through the command to test the WEB2 's performance:
Execute on WEB1:
#/usr/share/heartbeat/hb_standby
2012/12/28_19:43:49 going standby [all].
#elinks-dump http://192.168.0.254
Nfs
The test shows that when Web1 and web2 one of the nodes fails, the Web Access is not affected, enabling a highly available