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

The Operation method of Linux using keepalived to realize the High availability of lvs

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

What is lvs+keepalived?

How keepalived works

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. 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.

Introduction to LVS

LVS is the abbreviation of Linux Virtual Server, which means Linux virtual server, which is a virtual server cluster system. This project, founded by Dr. Zhang Wensong in May 1998, is one of the earliest free software projects in China. At present, there are three kinds of IP load balancing technologies (VS/NAT, VS/TUN and VS/DR) and ten scheduling algorithms.

This article focuses on the operation of Linux using keepalived to achieve high availability of lvs, which can be referenced by interested friends.

Single Master Model IPVS exampl

Configure keepalive

Highly available ipvs cluster example: modify keepalived configuration file

Modify the keepalived configuration file of host: 192.168.234.27

[root@234c27 ~] # vim / etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {notification_email {root@localhost / / accept email address} notification_email_from keepalived@localhost / / sending email address smtp_server 127.0.0.1 / sending mail server IPsmtp_connect_timeout 30 / / mail connection timeout length router _ id kptwo / / routing router _ mcast_group4 234.10.10.10 / / specify the multicast address of the vrrp protocol} vrrp_instance VI_1 {/ / vrrp protocol State MASTER / / lvs's MASTER server interface ens37 / / virtual_router_id 50 / / Virtual routing priority 100 / / weight is 100. The larger the advert_int 1 / / the interval between sending group blog packets authentication {/ / verify auth_type PASS / / the way is pass (clear text) auth_pass 1111 / / password} virtual_ipaddress {/ / keepalived virtual ip10.0.0.100/24}} virtual_server 10.0.0.100 80 {delay_loop 6 / / define the scheduling method lb_kind DR / / cluster Type of # persistence_timeout 50 / / persistent connection duration protocol TCP / / service agreement Only TCP real_server 192.168.234.47 80 {/ / backend real_server server address weight 1 / / weight HTTP_GET {/ / Application layer detection url {path / define the URL status_code 200 to be monitored} connect_timeout 3 / / connection request timeout nb_get_retry 3 / / retry Delay before delay_before_retry 3 / / retry}} real_server 192.168.234.57 80 {weight 2 HTTP_GET {url {path / status_code 200} connect_timeout 3 nb_get_retry 3 delay_before_retry 3}

Modify the keepalived configuration file for host: 192.168.234.37

[root@234c37 ~] # vim / etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {notification_email {root@localhost} notification_email_from keepalived@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id kptwo vrrp_ mcast_group4 234.10.10.10} vrrp_instance VI_1 {state BACKUP interface ens37 virtual_router_id 50 priority 80 advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {10.0.0.100/24}} virtual_server 10.0.0.100 80 { Delay_loop 6 lb_algo wrr lb_kind DR # persistence_timeout 50 protocol TCP sorry_server 127.0.0.1:80 real_server 192.168.234.47 80 {weight 1 HTTP_GET {url {path / status_code 200} connect_timeout 3 nb_get_retry 3 delay_before_retry 3}} real_server 192.168.234.57 80 {weight 2 HTTP_GET {url {path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3}

View keepalived

[root@234c37] # systemctl status keepalived ● keepalived.service-LVS and VRRP High Availability Monitor Loaded: loaded (/ usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled) Active: inactive (dead). [root@234c37 ~] # ipvsadm-LnIP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConn// has no ipvsadm

Start the service

[root@234c27 keepalived] # systemctl start keepalived.service [root@234c27 keepalived] # systemctl status keepalived.service ● keepalived.service-LVS and VRRP High Availability Monitor Loaded: loaded (/ usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2018-08-31 20:30:02 CST; 12s ago Process: 9657 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS) Main PID: 9658 (keepalived) … [root@234c27 keepalived] # ipvsadm-LnIP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 10.0.0.100 Prot LocalAddress:Port Scheduler Flags 80 wrr-> 192.168.234.47 LnIP Virtual Server version 80 Route 100-> 192.168.234.57 LnIP Virtual Server version 80 Route 200 / / startup service lvs vs has been configured

Backend real_server preparation

Add ip to the network card to modify the limit arp advertisement and reply level rs1 rs2 to do, gateway and point to the route

Ip an a 10.0.0.100 ip an a 32 dev ens37echo 1 > / proc/sys/net/ipv4/conf/all/arp_ignoreecho 1 > / proc/sys/net/ipv4/conf/lo/arp_ignoreecho 2 > / proc/sys/net/ipv4/conf/all/arp_announceecho 2 > / proc/sys/net/ipv4/conf/lo/arp_announceroute add default gw 192.168.234.17

Install the httpd service and write the web page file

Start the service

Image

Multi-master model IPVS example

Configure keepalive

Highly available ipvs cluster example: modify keepalived configuration file

Modify the keepalived configuration file of host: 192.168.234.27

[root@234c27 keepalived] # vim / etc/keepalived/keepalived.confglobal_defs {notification_email {root@localhost} notification_email_from keepalived@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id kpone vrrp_ mcast_group4 234.10.10.10} vrrp_instance VI_1 {state MASTER interface ens37 virtual_router_id 50 priority 100 advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {10. 0.0.100/24}} vrrp_instance VI_2 {state BACKUP interface ens37 virtual_router_id 51 priority 80 advert_int 1 authentication {auth_type PASS auth_pass 2222} virtual_ipaddress {10.0.0.200/24}} virtual_server 10.0.0.100 80 {delay_loop 6 lb_algo wrr lb_kind DR # persistence_timeout 50 protocol TCP # sorry_server 127.0.0.1:80 real_server 192. 168.234.47 80 {weight 1 HTTP_GET {url {path / status_code 200} connect_timeout 3 nb_get_retry 3 delay_before_retry 3} virtual_server 10.0.0.200 80 {delay_loop 6 lb_algo wrr lb_kind DR # persistence_timeout 50 protocol TCP # sorry_server 127.0.0.1:80 real_server 192.168. 234.57 80 {weight 1 HTTP_GET {url {path / status_code 200} connect_timeout 3 nb_get_retry 3 delay_before_retry 3}

Modify the keepalived configuration file for host: 192.168.234.37

[root@234c37 ~] # vim / etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {notification_email {root@localhost} notification_email_from keepalived@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id kptwo vrrp_ mcast_group4 234.10.10.10} vrrp_instance VI_1 {state BACKUP interface ens37 virtual_router_id 50 priority 80 advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {10.0.0.100/24}} vrrp_ Instance VI_2 {state MASTER interface ens37 virtual_router_id 51 priority 100 advert_int 1 authentication {auth_type PASS auth_pass 2222} virtual_ipaddress {10.0.0.200/24}} virtual_server 10.0.0.100 80 {delay_loop 6 lb_algo wrr lb_kind DR # persistence_timeout 50 protocol TCP # sorry_server 127.0.0.1:80 real_server 192.168.234.47 80 {weight 1 HTTP_GET {url {path / status_code 200} connect_timeout 3 nb_get_retry 3 delay_before_retry 3} virtual_server 10.0.0.200 80 {delay_loop 6 lb_algo wrr lb_kind DR # persistence_timeout 50 protocol TCP # sorry_server 127.0.0.1:80 real_server 192.168.234.57 80 {weight 1 HTTP_ GET {url {path / status_code 200} connect_timeout 3 nb_get_retry 3 delay_before_retry 3}

Priority allocation of 10.0.0.100 ip to 192.168.234.47 192.168.234.57 standby

Priority allocation of 10.0.0.200 ip to 192.168.234.57 192.168.234.47 standby

Backend real_server preparation

Modify the vip of 192.168.234.57 to 10.0.0.200x32

[root@234c27 keepalived] # ipvsadm-Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.0.0.100 Route 80 wrr-> 192.168.234.47 Route 80 wrr-> 192.168.234.47 Route 80 wrr-> 192.168.234.57 Route 80

Now take down a lvs.

[root@234c27 keepalived] # systemctl stop keepalived.service [root@234c27 keepalived] # ipvsadm-Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConn

Still provide services

[root@234c37] # ipvsadm-Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.0.0.100 Route 80 wrr-> 192.168.234.47 Route 80 wrr-> 192.168.234.47 Route 80 wrr-> 192.168.234.57 Ln IP Virtual Server version 80 Route 10 39

The latter implementation is modified based on the previous one.

Suppose you want to implement sorry_server

1. Shut down all rs services. Then install the apache or nginx service on lvs

two。 In the keepalived configuration file

Virtual_server 10.0.0.200 80 {delay_loop 6 lb_algo wrr lb_kind DR # persistence_timeout 50 protocol TCP # sorry_server 127.0.0.1 status_code 80 / / this line modifies the page real_server 192.168.234.57 80 {weight 1 HTTP_GET {url {path / status_code 200} connect_timeout 3 nb after writing out the service error _ get_retry 3 delay_before_retry 3}

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