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

How to install Keepalived in Linux system

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

How do I install Keepalived on a Linux system? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

1. Keepalived principle

1. What is keepalived

Keepalived is a service software that ensures the high availability of clusters in cluster management. Its function is similar to heartbeat and is used to prevent single point of failure.

2. Working principle of keepalived

Keepalived is based on VRRP protocol, and VRRP is called Virtual Router Redundancy Protocol, that is, virtual routing redundancy protocol.

Virtual routing redundancy protocol can be considered as a protocol to achieve high availability of routers, that is, N routers with the same function form a router group, in which there is a master and multiple backup,master with a vip providing external services (the default route of other machines in the local area network of the router is the vip). Master will send multicast, and when the backup does not receive the vrrp packet, it is considered that the master is down. At this point, you need to choose a backup as master according to the priority of VRRP. In this way, the high availability of the router can be ensured.

Keepalived has three main modules, namely, core, check and vrrp. Core module is the core of keepalived, which is responsible for the startup and maintenance of the main process as well as the loading and parsing of global configuration files. Check is responsible for health check-ups, including common check-ups. The vrrp module is used to implement the VRRP protocol.

3. Configuration file of keepalived

Keepalived has only one configuration file, keepalived.conf, which mainly includes the following configuration areas, namely global_defs, static_ipaddress, static_routes, vrrp_script, vrrp_instance and virtual_server

2. Installation of keepalived under Linux

1. Preparatory work

Linux host: 10.122.111.80,

Linux host: 10.122.111.81,

Virtual IP:10.122.111.99,

Operating system: Galaxy Kirin V3.3

2. Install Keepalived

Both Linux hosts need to install Keepalived, and the following steps need to be repeated for both machines.

1. Download Keepalived

Download to directory: / home/zz/user/software

Wget http://keepalived.org/software/keepalived-1.3.8.tar.gz

2. Decompress Keepalived

Tar-zxvf keepalived-1.3.8.tar.gz

3. Configure Keepalived

Cd keepalived-1.3.8/

. / configure

Errors may occur in this step

Checking libnfnetlink/libnfnetlink.h usability... No

Checking libnfnetlink/libnfnetlink.h presence... No

Checking for libnfnetlink/libnfnetlink.h... No

Configure: error: libnfnetlink headers missing

As shown below:

The solution is as follows:

Extract the usr.zip package to the keepalived-1.3.8 directory, extract it, and execute

Cp-R usr/ /

After success, re-execute

. / configure

Successful, as shown below:

4. Compile and install Keepalived

Make

Make install

3. Configure the firewall

Firewall-cmd-direct-permanent-add-rule ipv4 filter INPUT 0\-in-interface p4p1-destination 224.0.0.18-protocol vrrp-j ACCEPT

Firewall-cmd-direct-permanent-add-rule ipv4 filter OUTPUT 0\-out-interface p4p1-destination 224.0.0.18-protocol vrrp-j ACCEPT

Firewall-cmd-reload

Note: the above [p4p1] is the name of the configured network card.

4. Start the configuration service

Cp / home/zz/user/software/keepalived-1.3.8/keepalived/etc/init.d/keepalived / etc/init.d/

Mkdir / etc/keepalived

Cp / usr/local/etc/keepalived/keepalived.conf / etc/keepalived/

After the execution is completed, you can start Keepalived in the form of a service, as follows:

Service keepalived start

If you use the service keepalived status command to view the status, you have the following problems:

/ etc/init.d/keepalived: line 15: / etc/sysconfig/keepalived: there is no such file or directory

Then you need to perform:

Ln-s / usr/local/etc/sysconfig/keepalived / etc/sysconfig/

After the execution is successful, restart the Keepalived service to view the status.

If Keepalived does not start successfully, the error message is as follows:

Keepalived_vrrp exited with permanent error CONFIG. Terminating

This indicates that there is an error in the configuration of the Keepalived core configuration file. You can continue to configure it. This problem does not need to be dealt with first.

5. Configure dual computers

Keepalived configuration file is: / etc/keepalived/keepalived.conf

The configuration is as follows:

Use 10.122.111.80 as the primary node

Configure the slave node using 10.122.111.81

Modify the configuration file keepalived.conf of primary node 80 as follows:

! Configuration File for keepalived global_defs {notification_email {# acassen@firewall.loc # failover@firewall.loc # sysadmin@firewall.loc} notification_email_from Alexandre.Cassen@firewall.loc # smtp_server 192.168.200.1 # smtp_connect_timeout 30 router_id SERVER_1 vrrp_skip_check_adv_addr vrrp_garp_interval 0 vrrp_gna_interval 0} vrrp_instance VI_1 {state MASTER interface p4p1 virtual_router_id 55 priority 100 protocol TCP advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {10.122.111.99/24}}

Modify the configuration file keepalived.conf of slave node 81 as follows:

! Configuration File for keepalived global_defs {notification_email {# acassen@firewall.loc # failover@firewall.loc # sysadmin@firewall.loc} notification_email_from Alexandre.Cassen@firewall.loc # smtp_server 192.168.200.1 # smtp_connect_timeout 30 router_id SERVER_2 vrrp_skip_check_adv_addr vrrp_garp_interval 0 vrrp_gna_interval 0} vrrp_instance VI_1 {state BACKUP interface p4p1 virtual_router_id 55 priority 50 protocol TCP advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {10.122.111.99/24}}

After the configuration is completed, start Keepalived and check the status, as shown below:

6. Configure non-preemptive mode

Keepalived defaults to preemptive mode. The master node Master will plunder the virtual IP of the current slave server and reoccupy the central position when the failure reply is reactivated. In a decentralized cluster, the non-preemptive mode can be configured, that is, the virtual IP of the host that is in service will not be snatched and know that there is a problem with this server.

You only need to modify the following configuration in the original Master configuration file (the Backup node does not need to be changed):

Nopreempt

State BACKUP

The adjusted configuration file is as follows:

! Configuration File for keepalived global_defs {notification_email {# failover@firewall.loc # sysadmin@firewall.loc} notification_email_from Alexandre.Cassen@firewall.loc # smtp_server 192.168.200.1 # smtp_connect_timeout 30 router_id SERVER_1 vrrp_skip_check_adv_addr vrrp_garp_interval 0 vrrp_gna_interval 0} vrrp_instance VI_1 {state BACKUP # here MASTER is adjusted to BACKUP Nopreempt # add non-preemptive mode configuration here interface p4p1 virtual_router_id 55 priority 100 protocol TCP advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {10.122.111.99bin24}}

7. View the virtual IP pointing to

Determine whether the current server has a virtual IP, and execute the following command. If there is a result, the current server is in the service state. If the query is empty, the current server does not need a virtual IP and is in a standby state.

Ip addr | grep 10.122.111.99

Indicates that the current server has a virtual IP.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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: 0

*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