Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Heartbeat installation configuration for highly available clusters

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Preparatory work

(permanent address of this article: http://woymk.blog.51cto.com/10000269/1923285)

Configuration environment: centos6.9, nginx1.10, heartbeat-3.0.4

Install and configure two servers first:

Hostname: web1

Eth0 ip: 192.168.75.131

Eth2 ip: 10.1.1.11

Hostname: web2

Eth0 ip: 192.168.1.132

Eth2 ip: 10.1.1.12

For nginx yum installation, please refer to:

Yum installs the latest stable version of nginx's official website

For nginx compilation and installation, please refer to:

LNMP environment building (centos6.9+mysql5.7+php7.1+nginx1.10)

two。 Operate on two servers respectively

To prevent brain fissure, turn off the firewall and selinux

Iptables-F

Setenforce 0

The above is a temporary shutdown, please configure it according to the actual situation.

Vi / etc/hosts

Add the following two lines

192.168.75.131 web1

192.168.75.132 web2

Install the epel extension source

Rpm-ivh "http://mirrors.sohu.com/fedora-epel/epel-release-latest-6.noarch.rpm"

Heartbeat,libnet is installed on both servers

Yum install-y heartbeat* libnet

3. Configure on the web1 server

Cd / usr/share/doc/heartbeat-3.0.4/

Cp authkeys ha.cf haresources / etc/ha.d/

Cd / etc/ha.d

Vi authkeys

To modify or add.

Auth 3

3 md5 Hello!

Modify file permissions after saving

Chmod 600 authkeys

Vi haresources

Join

Web1 192.168.75.130/24/eth0:0 nginx

This line configuration means:

Web1-represents the hostname of the host node.

192.168.75.130-set the virtual ip. The IP address specified here is the IP address of the external service of the cluster.

Nginx-set up heartbeat-hosted services that can be started and shut down by heartbeat, and the service scripts need to be placed in the / etc/init.d/ directory.

Vi ha.cf

Change it to the following:

Debugfile / var/log/ha-debug # debugging information

Log recorded by logfile / var/log/ha-log #

Logfacility local0 # Syslog level

Keepalive 2 # heartbeat interval

If deadtime 30 # does not receive the heartbeat of the other node beyond this interval, the other person is considered dead.

If warntime 10 # does not receive the heartbeat of the other node beyond this interval, a warning will be issued and recorded in the log

Initdead 120 # on some systems, it takes some time for the network to work properly after the system is started or rebooted. This option is used to resolve the time interval caused by this situation. The value is at least twice the value of deadtime, and the higher the value, the slower it starts.

Udpport 694 # uses udp port 694 for heartbeat monitoring

Ucast eth2 10.1.1.12 # uses unicast to monitor the heartbeat, and IP is the host IP

Auto_failback on # means that after the primary node is restored, it automatically switches back to

Node web1 # Node 1

Node web2 # Node 2

Ping 192.168.75.1 # check whether the network is normal, which is generally set to the ip of the gateway or route

Respawn hacluster / usr/lib64/heartbeat/ipfail # this process is used to detect and handle network failures and needs to work with the ping node specified in the ping statement to detect network connections. (if you are installing a 32-bit operating system, please change the directory to / usr/lib/heartbeat/ipfail)

Copy three configuration files to web2

Cd / etc/ha.d/

Scp authkeys ha.cf haresources web2:/etc/ha.d/

4. Edit ha.cf on web2

Vi / etc/ha.d/ha.cf

Only one place needs to be changed.

find

Ucast eth2 10.1.1.12

Change to

Ucast eth2 10.1.1.11

5. Start heartbeat

Execute on web1 and web2, respectively

Service heartbeat start

First web1, then web2

In the windows client ping 192.168.75.130, the ability to ping indicates that the service is up.

Check to see if there is eth0:0 on the primary node web1

Ifconfig

Check the primary node web1 to see if there is a nginx process

Ps aux | grep nginx

6. HA function test

1) simulate the network failure on web1 and eth0 down the network card.

Ifdown eth0

View logs on web2

Tail-f / var/log/ha-log

The log shows that web2 has taken over web1's resources.

Check on web2 to see if a nginx process is started

Ps aux | grep nginx

The nginx service has been started

Turn eth0 back on on web1

Ifup eth0

Continue to view logs on web2

The log shows that web2 releases resources and automatically switches back to web1

2) simulate server failure

Turn off the web1 and simulate the power down of the server.

View logs on web2

Tail-f / var/log/ha-log

The log shows that web1 is dead and the nginx service on web2 has been started

The above test results show that when the primary node dies, the backup node successfully takes over the resources of the primary node; when the failure of the primary node recovers, it can automatically switch back to the primary node and achieve high availability.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 216

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report