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

Simple and rapid construction of LVS+Keepalived cluster

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

Share

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

LVS+Keepalived cluster

Keepalived was originally a powerful replication tool designed specifically for LVS.

It is mainly used to provide failover and health check functions-to judge the availability of LVS load schedulers and node servers, and to isolate and replace new servers in time.

Test environment:

Two dispatchers (dual hot standby) IP

192.168.30.30

192.168.30.31

Web Server IP

192.168.30.33

192.168.30.34

Install the required software

Modprobe ip_vs is already included in the centos7 system. Just open it and use it.

Modprobe ip_vs # load IP_vs module

Yum-y install gcc gcc-c++ make popt-devel kernel-devel openssl-devel ipvsadm # installs compilation tools, plug-ins and ipvsadm

Compile and install keepalived on two schedulers

Tar xf keepalived-1.4.2.tar.gz

Cd keepalived-1.4.2

. / configure-- prefix=/

Make & & make install

Cp keepalived/etc/init.d/keepalived / etc/init.d/ # join the system management service

[root@lin3036 keepalived-1.4.2] # systemctl enable keepalived # is set to boot automatically

The other one is installed in the same way.

Modify the first master keepalived.conf file

Vi / etc/keepalived/keepalived.conf

! Configuration File for keepalived

Global_defs {

Router_id LVS_01 # name of this server

}

Vrrp_instance VI_1 {# defines VRRP hot backup instance

State MASTER # Hot standby status. MASTER represents master server, and BACKUP represents slave server.

Interface ens33 # physical interface that carries VIP addresses

ID number of virtual_router_id 51 # virtual router, consistent with each hot backup group

Priority 110# priority, the higher the number, the higher the priority.

Number of seconds between advert_int 1 # announcements (heartbeat rate)

Authentication {# hot backup authentication information, which is consistent with each hot backup group

Auth_type PASS # Certification Type

Auth_pass 6666 # password string

}

Virtual_ipaddress {# specifies the drift address (VIP), which can have multiple

192.168.30.100

}

}

Virtual_server 192.168.30.100 80 {# Virtual Server address (VIP), Port

Interval between delay_loop 6 # health check (seconds)

Lb_algo rr # polling (rr) scheduling algorithm

Lb_kind DR # Direct routing (DR) cluster operation mode

Persistence_timeout 60 # connection hold time (seconds)

Protocol TCP # application server uses TCP protocol

Real_server 192.168.30.33 80 {# address and port of the first Web server node

Weight of weight 1 # nod

TCP_CHECK {# Health check method

Target port checked by connect_port 80 #

Connect_timeout 3 # connection timeout (seconds)

Number of nb_get_retry 3 # retries

Delay_before_retry 3 # retry interval

}

}

Real_server 192.168.30.34 80 {# address and port of the second Web server node

Weight 1

TCP_CHECK {

Connect_port 80

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

}

}

}

[root@dd01 keepalived-1.4.2] # service keepalived start

[root@dd01 keepalived-1.4.2] # ip addr show dev ens33 / / verify the bound virtual address

Standby service configuration keepalived.conf file

! Configuration File for keepalived

Global_defs {

Router_id LVS_02

}

Vrrp_instance VI_1 {

State BACKUP

Interface ens33

Virtual_router_id 51

Priority 105

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 6666

}

Virtual_ipaddress {

192.168.30.100

}

}

Virtual_server 192.168.30.100 80 {

Delay_loop 6

Lb_algo rr

Lb_kind DR

Persistence_timeout 60

Protocol TCP

Real_server 192.168.30.33 80 {

Weight 1

TCP_CHECK {

Connect_port 80

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

}

}

Real_server 192.168.30.34 80 {

Weight 1

TCP_CHECK {

Connect_port 80

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

}

}

}

Start the service

Configure the primary server LVS

[root@lin3034 keepalived-1.4.2] # modprobe ip_vs # load ip_vs module

Configure the primary server LVS

The standby server is the same

The web server also needs to virtualize the virtual VIP of 192.168.30.100.

Ifconfig lo:0 192.168.30.100 broadcast 192.168.30.100 netmask 255.255.255.255 up

Route add-host 192.168.30.100 dev lo:0

Echo "1" > / proc/sys/net/ipv4/conf/lo/arp_ignore

Echo "2" > / proc/sys/net/ipv4/conf/lo/arp_announce

Echo "1" > / proc/sys/net/ipv4/conf/all/arp_ignore

Echo "2" > / proc/sys/net/ipv4/conf/all/arp_announce

Sysctl-p refresh

Check the status of the network card

The other web server has the same configuration

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