Building high available (HeartBeat)

HA (high available) , Also known as dual-system hot backup, used for critical business. Simply understand itYes, there are two machines A And B. Normally, A provides services, and B is on standby and idle. When A is down or the service is down, it will switch to machine B to continue to provide services.


As shown in the figure, it is an HA architecture. There are two machines Web1 and Web2 under a switch, among which Web1 is the master node. Normally it is providing Service, and the Web2 standby node is idle. There is a heartbeat line between Web1 and Web2 to check the survival status of each other. Virtual IP, also called vip, is an IP that provides external services. Normally, it is configured on Web1. When Web1 goes down, Web2 will automatically configure the vip to provide external services.

The following two machines liu liu1

liu: 192.168.186.130

liu2: 192.168.186.132

< br>

The following operations 1-5 are all performed on two machines

Preparation:

1. The hostname is set, respectively liu and liu1

2. Turn off the firewall iptables -F;

Turn off selinux: setenforce 0

3. vi /etc/hosts // Increase The content is as follows:

192.168.186.130 liu
192.168.186.132 liu1

4. Install epel extension source:

yum -y install epel -release

5. Install heartbeat / libnet on both machines

yum install -y heartbeat nginx

Configuration on the host

cd /usr/share/doc/heartbeat-3.0.4/cp authkeys ha.cf haresources /etc/ha.d/cd/etc/ha.dvi authkeys #Open the following two: there are three types Authentication methods are available for selection. The first is CRC cyclic redundancy check, the second is SHA1 hash algorithm, and the third is MD3 hash algorithm. Their passwords can be set arbitrarily, but the passwords on both sides must be consistent. auth 3 md5 Hello! chmod 600 authkeys #Authorize the authentication file as 600vi haresources #Add the following statement liu 192.168.186.130/24/eth0:0 nginx #Set the virtual IP and the corresponding interface, and specify to start the NGINX service when the virtual IP is started , The NGINX service here must be a service that can be started directly under the /etc/init.d/ directory. vi ha.cf #Change to the following content: debugfile /var/log/ha-debug #Set the debug file directory logfile /var/log/ha-log #Set the log file directory logfacility Local0keepalive 2 Set the check interval to 2sdeadtime 30 #Set the death time to 30swarntime 10 #Set the alarm time to 10s (If you don’t receive a response from the other party for more than 10s, you will alarm) initdead 60 #Set the port to start the initialization time as 60sudpport#694 ud ucast eth1 192.168.186.110 #Set the interface of the listening heartbeat line and the IP address of the corresponding peer interface auto_failback on #Start preemption mode (the master will automatically switch to the backup after it restarts after hanging up) node test1 #Specify two Node node test2ping 192.168.186.1 #Designate a third-party arbitration node respawn hacluster /usr/lib/heartbeat/ipfail #Use this script to listen to whether the other party is alive (using ICMP message detection)

< code class="bash comments">

7. Copy the three configurations on the master to the slave:

cd /etc/ha.d/

p>

scp authkeys ha.cf haresources liu1:/etc/ha.d/

8. To from the top (liu1) edit ha.cf< /p>

vi /etc/ha.d/ha.cf // Only one place needs to be changed

ucast eth0 192.168.186.130 changed to ucast eth1 192.168.186.132

9. Start heartbeat:

Master first, then slave

service heartbeat start

Start the master An eth0 will appear above: 0, eth0 will not be started if the device is above:0

You can check the debug log and software log to check whether it started normally:

650) this.width=650;” src =”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png” style=”float:none;” title=”log on slave” alt=”wKioL1ZJ1Hqzxh1qAABk1JaF9bg157.png” d=” 4774224″ s=”c31_791″ t=”png”>

The HA is basically set up here. Next is the test.

After turning off the host network card with iptables, the standby machine will start automatically nginx, after opening the port, the standby machine is closed, and the host machine starts the service.

But when VIP is down, high availability fails. All HAs must ensure the vip survival to make HA take effect~~~

cd/usr/share/doc/heartbeat-3.0.4/cp authkeys ha.cf haresources /etc/ha.d/cd/etc/ha.dvi authkeys #Open the following two items: Total There are three authentication methods to choose from, the first is CRC cyclic redundancy check, the second is the SHA1 hash algorithm, and the third is the MD3 hash algorithm, where their passwords can be set arbitrarily, but the passwords on both sides must be kept Unanimous. auth 3 md5 Hello! chmod 600 authkeys #Authorize the authentication file as 600vi haresources #Add the following statement liu 192.168.186.130/24/eth0:0 nginx #Set the virtual IP and the corresponding interface, and specify to start the NGINX service when the virtual IP is started , The NGINX service here must be a service that can be started directly under the /etc/init.d/ directory. vi ha.cf #Change to the following content: debugfile /var/log/ha-debug #Set the debug file directory logfile /var/log/ha-log #Set the log file directory logfacility Local0keepalive 2 Set the check interval to 2sdeadtime 30 #Set the death time to 30swarntime 10 #Set the alarm time to 10s (If you don’t receive a response from the other party for more than 10s, you will alarm) initdead 60 #Set the port to start the initialization time as 60sudpport#694 ud ucast eth1 192.168.186.110 #Set the interface of the listening heartbeat line and the IP address of the corresponding peer interface auto_failback on #Start preemption mode (the master will automatically switch to the backup after it restarts after hanging up) node test1 #Specify two Node node test2ping 192.168.186.1 #Designate a third-party arbitration node respawn hacluster /usr/lib/heartbeat/ipfail #Use this script to listen to whether the other party is alive (using ICMP message detection)

< code class="bash comments">

Leave a Comment

Your email address will not be published.