HA (High available) High Availability cluster ( two-machine hot standby)
1. Understanding: Two servers A and B , when a service, B idle standby, when a service outage, will automatically switch to the B machine to continue to provide services. When the host is back to normal, the data consistency is resolved through the shared storage system by automatically or manually switching to the host as set by the user.
2. The software that implements this function is: Heartbeat, keepalived (with load balancing capability)
3. structure diagram
ha- Heartbeat
Experiment : take hearbeat as an example to do the ha cluster, and the nginx service as ha the corresponding service
Firewall off: Iptables-f service iptables Save
Close Selinux:setenforce 0, Getenforce view,vim/etc/selinux/conf Modify, save exit.
Configure the network card:
Master--eth1 192.168.2.105
Slave--eth1 192.168.2.106 eth1 acts as a heartbeat line: detects if the other host service is alive.
Master--eth0 192.168.1.105
Slave--eth0 192.168.1.106 eth0 for mobile IP , also known as the VIP External services.
Operation: A:
Hostname =master
Vim/etc/sysconfig/network
Hostname=master
Vim/etc/hosts
192.168.1.105 Master
192.168.1.106 slave
Operation: B:
Hostname =slave
Vim/etc/sysconfig/network
Hostname=slave
Vim/etc/hosts
192.168.1.105 Master
192.168.1.106 slave.
A,B Install the epel extension source at the same time (yum error solved linux After installing the extension source) Xiao Kee [2])
wget www.lishiming.net/data/attachment/forum/epel-release-6-8_64.noarch.rpm
RPM-IVH epel-release-6-8_64.noarch.rpm
A,B simultaneously installs the hearbeat and expands the libnet and prepares the test nginx
Yum install-y heartbeat* libnet nginx
A machine:switch to the installation directory copy file to/ETC/HA.D under
cd/usr/share/doc/heartbeat-3.0.4/
CP Authkeys HA.CF haresources/etc/ha.d/
Switch directories to/ETC/HA.D Edit Configuration
cd/etc/ha.d/
Vim Authkeys
Auth 3Validation Level
3 MD5 hello!Encryption Method
and give600 read and Write permissions to root
chmod Authkeys
Vim Haresources
Master 192.168.1.106/24/eth0 nginx [Mobile IP is the VIP Master host name Nginx service, can be other services. ]
Vim HA.CF
Debugfile/var/log/ha-debug
Logfile/var/log/ha-log
Logfacility local0
KeepAlive 2
Deadtime 30
Warntime 10
Initdead 60
Udpport 694
Ucast eth1 192.168.2.106each otherIp
Auto_failback on
Node Master
Node slave
Ping 192.168.2.1
Respawn Hacluster/usr/lib64/heartbeat/ipfailif it is32 System Remember LIB64insteadLib
ha.cf Detailed Documentation
Debugfile/var/log/ha-debugFault DebuggingLog
Logfile/var/log/ha-log log File
Logfacility local0Log Level
KeepAlive 2Detection Period2s
Deadtime 30Detecting the time of death30s
Warntime 10Start warning recording time10s
Initdead 60Restart Reserve Time60s
Udpport 694Heart jumper Communication Port
Ucast eth0 192.168.0.161 each other's IP,You can also useBcast is the way of broadcasting to find,The best serial line or use a separate network card
Auto_failback ondetects if the host is alive after booting from the machine to return settings
Node Master
Node slavetwo xNode machine
Ping the 192.168.0.1 arbiter router or switch to act as
Respawn Hacluster/usr/lib/heartbeat/ipfailPrevent process DeathNew Pull up process 64The bit system needs to be changed ./libbitlib64otherwise the service will not start, remember.
Copy this three files edited to a second server B machine under the /ETC/HA.D directory
SCP Authkeys ha.cf haresources slave:/etc/ha.d/
Modify HA.CF in the B-machine
Vim/etc/ha.d/ha.cf
Modified:ucast entry is: Ucast eth1 192.168.2.105 Save exit.
Environmental testing
A host Nginx
echo "This is Heartbeat server Master" 1111 ">/usr/share/nginx/html/index.html
B host Nginx
echo "This is Heartbeat server slave" 2222 "" >/usr/share/nginx/html/index.html
View AB machine Nginx Start condition
Start First A machine master heartbeat service starts b machine slave Heartbeat
/etc/init.d/heartbeat start
View nginx boot status
Ps-aux|grep Nginx
notes: (After starting heartbeat, Nginx will automatically start without manual, B machine default nginx will not start)
Test 1
client browser access 192.168.1.106 [Mobile IP (VIP)]
Browser Display "This is Heartbeat server Master 111111" Normal
Test 2
the heartbeat line is a service based on the ICMP protocol, so when we block the ping service of Host a ,when the heartbeat service in B is unable to detect a machine, B Machine think a machine has failed (can be seen from the heartbeat log), so the B machine immediately start its own Nginx service take over a machine work
experiments . in the A firewall rule is added on the server host to deny Ping
Iptables-a input-p icmp-j DROP
client browser Access 192.168.1.106
Navigation Device Show "This is heartbeat server slave 2222" Normal
Test 3.
when we delete A machine just added the firewall rule ,B machine detects that a machine survives, read itself/etc/ha.d/ha.cf file auto_failback on entry, Then automatically switch to a machine, stop its own NGINGX service. At this point a service is provided. Test as follows
Experiment: Delete A the firewall rule that the machine just added
iptables-d input-p icmp-j DROP
Browser Display "This is Heartbeat server Master 111111" Normal
This test can see the same situation from Eth0, Nginx, heaartbeat logs and so on. LOG:/var/log/ha-log.
ha-cluster (high available) HA cluster (dual standby) rookie entry level