Lab Environment:
Virtual Machine ha1:192.168.61.130
Virtual Machine ha2:192.168.61.132
vip:192.168.61.100
Experiment Description:
ha1 httpd service index.html content is set to HA1
HA2 httpd service index.html content is set to HA2
Two-host switch operation to facilitate observation of the effect
Precautions:
(a) The time between nodes must be synchronized: implemented using NTP protocol;
Service-side /etc/ntp.conf for reference:
Driftfile/var/lib/ntp/drift
Restrict-6default kod nomodify notrap nopeer noquery
restrict127.0.0.1
Restrict-6:: 1
restrict192.168.61.0 Mask 255.255.255.0 nomodify
Restrict 0.0.0.0mask 0.0.0.0 nomodify notrap noquery notrust
server127.127.1.0
Fudge 127.127.1.0stratum 8
server220.130.158.71 prefer
server220.130.158.51
Includefile/etc/ntp/crypto/pw
Keys/etc/ntp/keys
Note: Be sure to wait after setting up the restart service 10-15 minutes before attempting to synchronize, command: Ntpdata 192.168.61.130, compare two machine time synchronization commands: data;ssh 192.168.61.130 ' data '
HA2 It is better to set a timed task, each 5 minutes sync Time:
Crontab-e
*/5 * * * */usr/sbin/ntpdata 192.168.61.130
(b) the nodes need to communicate with each other through the host name and must parse the host to IP address;
(1) The proposed name resolution function is implemented using the hosts file;
(2) the name used in the communication must be consistent withthe name of the node: "uname-n" command, or "hostname" The name shown is consistent;
(3) To establish the root user between nodes can be based on key authentication;
# ssh-keygen-t Rsa-p '
#ssh-copy-id-i/root/.ssh/id_rsa.pub [email protected]
(4) Make sure that SELinux is closed and iptables emptied.
Note: The definition becomes a resource in the Cluster service and must not boot automatically; CRM management;
HA1 Configuration
Installing heartbeat V2
(a). Install the Epel source first, the system source is not libnet
wget ftp://ftp.pbone.net/mirror/dl.iuscommunity.org/pub/ius/archive/Redhat/6/i386/epel-release-6-5.noarch.rpm
RPM-IVH epel-release-6-5.noarch.rpm
(b). Install the relevant package:
Yum Install net-snmp-libs libnet PyXML
RPM-IVH heartbeat-2.1.4-12.el6.x86_64.rpm
heartbeat-pils-2.1.4-12.el6.x86_64.rpm
heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
Yum Install httpd
(c). Edit the Ha.cf file
VIM/ETC/HA.CF Add the following:
Logfacility local0# log using local0 settings in Rsyslog
Keepalive1 #监听频率, every 1 seconds
Deadtime3 #死亡判断时间
Warntime2 #异常警告时间
Mcasteth0 225.0.0.1 694 1 0 #组播地址设定
Auto_failbackon #修复后自动上线
Node HA1 #节点设置
Node HA2 #节点设置
Ping 192.168.61.2 #第三方仲裁设定
(d). Edit the Authkeys file
Auth 2
#1 CRC
2 sha1hi! #密钥短语越长越随机越好
#3 md5hello!
(E) edit haresources add:
HA1 192.168.61.100 httpd # Set Master service hostname,VIP, service 3 Resources
(f) edit index.html Home
echo "HA1" >/var/www/html/index.html
HA2 Configuration
Installing Heartbeat V2
(a). Install the Epel source first, the system source is not libnet
wget ftp://ftp.pbone.net/mirror/dl.iuscommunity.org/pub/ius/archive/Redhat/6/i386/epel-release-6-5.noarch.rpm
RPM-IVH epel-release-6-5.noarch.rpm
(b). Install the relevant package:
Yum Install net-snmp-libs libnet PyXML
RPM-IVH heartbeat-2.1.4-12.el6.x86_64.rpm
heartbeat-pils-2.1.4-12.el6.x86_64.rpm
heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
Yum Install httpd
(c) copy ha1 's ha.cf,haresources,Authkeys
Scp192.168.61.130:/etc/ha.d/{ha.cf,haresources,authkeys}/etc/ha.d/
(d) edit index.html Home
echo "HA2" >/var/www/html/index.html
(e) add time-lapse tasks , updated every 5 minutes
Crontab-e
*/5* * * */usr/sbin/ntpdata 192.168.61.130
start the two-machine heartbeat service separately
Service Heartbeat Start
use other hosts to access the http://192.168.61.100/index.html, close ha1, HA2 One of them, refresh the page to see the contents of the page HA1 ,HA2 take turns to display
display. Viewing a working host with Ifconfig, you can see that the VIP is already configured on eth0:0
HeartbeatV2 haresources Simple Implementation httpd service high Availability