Linux Advanced Skills: keepalived for clusters
1. Introduction to keepalived
Keepalived is a high-availability WEB service solution based on VRRP protocol, which can be used to avoid spof. Install keepalived on multiple nodes. Other nodes are used to provide real services. Similarly, they express a virtual IP address. When the master server goes down, the backup server takes over the virtual IP address and continues to provide services to ensure high availability.
The schematic of keepalived is as follows:
The leftmost is the client, which accesses our virtual IP address. Then we have master (master control node) and backup (backup control node ). The rightmost is the real machine we provide services.
2. Build the keepalived Service
We use four nodes for this experiment. Two serve as control nodes and the other two provide services. Then access the virtual IP address using the real machine's browser.
Note:
1. Resolve all nodes.
2. Time Synchronization
3. Set the yum source (in addition to the basic source and high availability)
Is our operation console:
The keepalived installation package is:
Keepalived-1.2.13.tar.gz
The two control nodes extract, compile, and install keepalived:
Before compiling keepalived, We need to install some related packages:
Compile the source code package of keepalived:
This is our compilation result:
Then we will install:
The preceding steps must be performed on both control nodes. Finally, we can set the master and slave nodes in the configuration file.
Create a soft link to link the keepalived configuration file and Service Startup file to the specified location:
Set the configuration file:
We have set the mail sending Address and ip address. The MASTER node is the MASTER control node and the virtual id must be the same. Delay_loop specifies 6 seconds to check the service status.
Set the virtual ip address, which is the IP address accessed by our client.
This is the content of the remaining configuration file. We set the connection mode to direct connection mode DR, the load policy to call the rr method, and the protocol to Wei TCP. Then we set the IP addresses and ports of the two service nodes. Port 80 of 192.168.2.108 and 192.168.2.109 respectively. That is, the webpage access service.
Then we set the configuration file of the BACKUP machine, the mode is set to BACKUP, and the weight is changed to 50. In this way, the master control node can take over first.
Then we open the keepalived service and view the log. We found that the 192.168.2.110 virtual IP address has been identified:
Install the arptable_jf software on two service nodes that provide real machines:
Set the arptables policy:
Then we need to install ipvsadm software on two control nodes to monitor the service status:
If the installation fails, view the yum source and set it to the following:
Install httpd on two real machines that provide services, and start the service after setting the default published content:
Then, we can view the current monitoring information on the master control node:
Check the information of 192.168.2.110 in the browser of the real machine. The default release content of 192.168.2.108 and 192.168.2.109 will be displayed in rotation because it is a wheel call policy:
3. Summary:
In this way, we have built a high-availability cluster under keepalived. This is much less complex than heartbeat, which is also very common in the production environment.