当前位置:网站首页>Lvs+keepalived highly available cluster
Lvs+keepalived highly available cluster
2022-06-10 11:19:00 【Kiro Jun】
keepalived High availability cluster deployment
- One 、LVS+Keeplived High availability cluster
- Two 、VRRP
- Four 、LVS+Keepalived Construction of high availability cluster
One 、LVS+Keeplived High availability cluster
1.1 LVS
Linux Virtual server (Linux Virtual Server)
LVS It's actually equivalent to based on IP Address virtualization applications , Based on IP Load balancing of address and content request distribution presents an efficient solution
working principle :
In a LVS A service cluster usually has a master server (MASTER) And backup servers (BACKUP) Servers with two roles , But the external performance is a virtual reality IP, The master server will send VRRP Notify the backup server ;
When the backup server cannot receive VRRP When the news , When the main server is abnormal , The backup server will take over the virtual IP, Continued provision of services , Thus, high availability is guaranteed .
1.2 Keepalived

- Support for automatic fail over (Failover)
- Support node health status check (Health Checking)
Judge LVS Load balancing scheduler 、 Availability of node servers , When master When the host fails, switch to backup The node ensures normal business , When master After the failed host recovers, it is added to the cluster and the business is switched back to master node
keepalived Analysis of implementation principle :
- keepalived use VRRP Hot backup protocol implementation Linux Multi machine hot standby function of server
- VRRP( Virtual routing redundancy protocol ) Is a backup solution for routers
- A hot backup group is composed of multiple routers , Through shared virtual machines IP Address provides services to the outside world
- Each hot backup group has only one router at the same time , Other routers are redundant
- If the current online route fails , Other routers will automatically take over the virtual router according to the set priority IP Address , Continued provision of services
The cluster should meet three characteristics :
- Load balancing ( High concurrency )
- health examination ( High performance )
- Fail over ( High availability )
1.3 Keepalived The main modules of the system and their functions
keepalived There are three main modules in the architecture , Namely core、check and vrrp
- core modular : by keepalived At the heart of , Responsible for the start of the main process 、 Maintenance and global configuration file loading and parsing .
- vrrp modular : Is to achieve VRRP Agreed .
- check modular : Responsible for health examination , Common ways are port checking and URL Check .
Two 、VRRP
2.1 VRRP summary
Virtual Router Redundancy Protocal, Virtual Router Redundancy Protocol
- utilize VRRP, A set of routers ( The same LAN The interface ) Working together , But there is one in Master state , And undertake the actual data traffic forwarding task ;
- One VRRP Multiple routers in the group share a virtual network IP Address , This address is used as the default gateway address of all hosts in the LAN ;
- VRRP Decide which router is Master, It is responsible for receiving and forwarding packets sent to the user gateway , And the response PC For its gateway IP Of ARP request ;
- Backup Router listening Master Router The state of , And in Master When the route fails , Take over his work
2.2 VRRP Working process of
(1) VRRP The devices in the group elect Master. Master The device is free by sending ARP message , Virtual MAC Address notification to the device or host to which it is connected , So as to undertake the task of message forwarding .
(2) Master Periodically, the device sends data to all Backup Device send VRRP Notification message .
(3) If Master The device is out of order ,VRRP In the backup group Backup Equipment re elects new Master..
(4) VRRP When the group state switches ,Master Switching from one device to another , new Master The device will immediately send the virtual machine with the virtual router MAC Address and virtual IP Free address information ARP message , Refresh... In the host or device to which it is connected MAC Table item , So as to lead the user traffic to the new Master On the equipment , The whole process is completely transparent to users .
(5) primary Master When the equipment fails to recover , If the device is IP Address owner ( Then its priority is 255), Switch directly to Master state . If the priority is less than 255, Switch first to Backup state , And its priority is restored to the priority configured before the failure .
(6)Backup The priority of the device is higher than Master Equipment time , from Backup How the device works ( Preemptive mode and non preemptive mode ) Decide whether to re elect Master.
Four 、LVS+Keepalived Construction of high availability cluster
Environmental Science :
| Lord DR | 192.168.61.11 | ipvsadm、keepalived( Hot standby ) |
|---|---|---|
| To prepare DR | 192.168.61.22 | ipvsadm、keepalived |
| Web1 The server | 192.168.61.33 | |
| Web2 The server | 192.168.61.44 | |
| vip | 192.168.61.12 |
4.1 Configure the load scheduler ( Lord :192.168.61.11)
######## To configure Keepalived master The server ##########
1. # Turn off firewall
systemctl stop firewalld.service
setenforce 0
2. # Installation services
yum -y install ipvsadm keepalived
3. # Modify the configuration file keeplived.conf
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
vim keepalived.conf
......
global_defs { # Define global parameters
--10 That's ok -- modify , The mail service points to local
smtp_server 127.0.0.1
--12 That's ok -- modify , Specify the server ( Router ) The name of , The names of the primary and standby servers must be different , Mainly LVS_01, Prepare for LVS_02
router_id LVS_01
}
vrrp_instance VI_1 { # Definition VRRP Hot standby instance parameters
--20 That's ok -- modify , Specify the hot standby status , Mainly MASTER, Prepare for BACKUP
state MASTER
--21 That's ok -- modify , Specify bearer vip Physical interface of address
interface ens33
--22 That's ok -- modify , Specify the virtual router ID Number , Each hot standby group is consistent
virtual_router_id 10
--23 That's ok -- modify , Assign priority , The higher the value, the higher the priority , Mainly 100, Prepare for 99
priority 100
advert_int 1 # Seconds between announcements ( heart rate )
authentication { # Define authentication information , Each hot standby group is consistent
auth_type PASS # Authentication type
--27 That's ok -- modify , Specify the authentication password , The primary and standby servers are consistent
auth_pass 123123
}
virtual_ipaddress { # Specify the cluster vip Address
192.168.61.12
}
}
--36 That's ok -- modify , Specify the virtual server address (VIP)、 port , Define virtual servers and Web Server pool parameters
virtual_server 192.168.61.12 80 {
delay_loop 6 # Intervals between health checks ( second )
lb_algo rr # Specify scheduling algorithm , polling (rr)
--39 That's ok -- modify , Specify the cluster operating mode , Direct routing (DR)
lb_kind DR
persistence_timeout 50 # Connection retention time ( second )
protocol TCP # The application service adopts TCP agreement
--43 That's ok -- modify , Specify the first Web The address of the node 、 port
real_server 192.168.61.33 80 {
weight 1 # Weight of nodes
--45 That's ok -- Delete , Add the following health check methods
TCP_CHECK {
connect_port 80 # Add the target port to check
connect_timeout 3 # Add connection timeout ( second )
nb_get_retry 3 # Add retry times
delay_before_retry 3 # Add retry interval
}
}
```
real_server 192.168.61.44 80 { # Add a second Web The address of the node 、 port
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
```
}
## Delete the redundant configuration ##
4. # Start the service 、 View virtual network card vip
systemctl start keepalived
ip addr show dev ens33
5. # adjustment proce Response parameter , close Linux Kernel redirection parameter response
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
6. # refresh
sysctl -p
############### To configure ipvsadm ###############
7. # Configure load distribution policies , And start the service
ipvsadm-save >/etc/sysconfig/ipvsadm
systemctl start ipvsadm.service
8. # Empty ipvsadm, And make strategies
ipvsadm -C
ipvsadm -A -t 192.168.61.12:80 -s rr
ipvsadm -a -t 192.168.61.12:80 -r 192.168.61.33:80 -g
ipvsadm -a -t 192.168.61.12:80 -r 192.168.61.44:80 -g
9. # Save settings
ipvsadm
ipvsadm -ln
ipvsadm-save >/etc/sysconfig/ipvsadm
Turn off firewall 
Installation services 
Modify the configuration file keeplived.conf





Start the service 、 View virtual network card vip
At this time, the service may not be visible vip Address , because 80 The port is occupied , Use “lsof -i:80” Kill the corresponding process after viewing the command , Restart and you can see 
adjustment proce Response parameter , close Linux Kernel redirection parameter response 
refresh 
Configure load distribution policies , And start the service 
Empty ipvsadm, And make strategies 
Save settings 
4.2 Configure the load scheduler ( To prepare :192.168.61.22)
############# To configure Keepalived master The server ###############
1. # Turn off firewall
systemctl stop firewalld.service
setenforce 0
2. # Installation services
yum -y install ipvsadm keepalived
3. # Modify the configuration file keeplived.conf
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
vim keepalived.conf
......
global_defs { # Define global parameters
--10 That's ok -- modify , The mail service points to local
smtp_server 127.0.0.1
--12 That's ok -- modify , Specify the server ( Router ) The name of , The names of the primary and standby servers must be different , Mainly LVS_01, Prepare for LVS_02
router_id LVS_01
}
vrrp_instance VI_1 { # Definition VRRP Hot standby instance parameters
--20 That's ok -- modify , Specify the hot standby status , Mainly MASTER, Prepare for BACKUP
state BACKUP
--21 That's ok -- modify , Specify bearer vip Physical interface of address
interface ens33
--22 That's ok -- modify , Specify the virtual router ID Number , Each hot standby group is consistent
virtual_router_id 10
--23 That's ok -- modify , Assign priority , The higher the value, the higher the priority , Mainly 100, Prepare for 99
priority 99
advert_int 1 # Seconds between announcements ( heart rate )
authentication { # Define authentication information , Each hot standby group is consistent
auth_type PASS # Authentication type
--27 That's ok -- modify , Specify the authentication password , The primary and standby servers are consistent
auth_pass 123123
}
virtual_ipaddress { # Specify the cluster vip Address
192.168.61.12
}
}
--36 That's ok -- modify , Specify the virtual server address (VIP)、 port , Define virtual servers and Web Server pool parameters
virtual_server 192.168.61.12 80 {
delay_loop 6 # Intervals between health checks ( second )
lb_algo rr # Specify scheduling algorithm , polling (rr)
--39 That's ok -- modify , Specify the cluster operating mode , Direct routing (DR)
lb_kind DR
persistence_timeout 50 # Connection retention time ( second )
protocol TCP # The application service adopts TCP agreement
--43 That's ok -- modify , Specify the first Web The address of the node 、 port
real_server 192.168.61.33 80 {
weight 1 # Weight of nodes
--45 That's ok -- Delete , Add the following health check methods
TCP_CHECK {
connect_port 80 # Add the target port to check
connect_timeout 3 # Add connection timeout ( second )
nb_get_retry 3 # Add retry times
delay_before_retry 3 # Add retry interval
}
}
real_server 192.168.61.44 80 { # Add a second Web The address of the node 、 port
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
## Delete the redundant configuration ##
4. # Start the service 、 View virtual network card vip
systemctl start keepalived
ip addr show dev ens33
5. # adjustment proce Response parameter , close Linux Kernel redirection parameter response
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
6. # refresh
sysctl -p
########### To configure ipvsadm ###########
7. # Configure load distribution policies , And start the service
ipvsadm-save >/etc/sysconfig/ipvsadm
systemctl start ipvsadm.service
8. # Empty ipvsadm, And make strategies
ipvsadm -C
ipvsadm -A -t 192.168.61.12:80 -s rr
ipvsadm -a -t 192.168.61.12:80 -r 192.168.61.33:80 -g
ipvsadm -a -t 192.168.61.12:80 -r 192.168.61.44:80 -g
9. # Save settings
ipvsadm
ipvsadm -ln
ipvsadm-save >/etc/sysconfig/ipvsadm
Turn off firewall 
Installation services 
Modify the configuration file keeplived.conf



Start the service 、 View virtual network card vip

adjustment proce Response parameter , close Linux Kernel redirection parameter response 
refresh 
Configure load distribution policies , And start the service 
Empty ipvsadm, And make strategies 
Save settings 
4.3 Configure the node server web1(192.168.61.33)
1. # Turn off firewall
systemctl stop firewalld
setenforce 0
2. # Install and turn on httpd service
yum -y install httpd
systemctl start httpd
3. # Configure site files
vim /var/www/html/index.html
this is kiro web!
4. # Configure virtual vip
vim /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
ONBOOT=yes
IPADDR=192.168.61.12
NETMASK=255.255.255.255
5. # Restart network service , Open virtual network card
systemctl restart network
ifup lo:0
ifconfig lo:0
6. # Set the routing
route add -host 192.168.61.12 dev lo:0
route -n
7. # adjustment proc Response parameter
# The added system only responds to the purpose IP For the local IP Of ARP request
# The system does not use the original address to set ARP The source address of the request , It's physics mac The address on the IP
vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
8. # Refresh proc Parameters
sysctl -p
Turn off firewall 
Install and turn on httpd service 

Configure site files 
Configure virtual vip
Restart network service , Open virtual network card 
Set the routing 
adjustment proc Response parameter 
Refresh proc Parameters 
4.4 Configure the node server web2(192.168.61.44)
1. # Turn off firewall
systemctl stop firewalld
setenforce 0
2. # Install and turn on httpd service
yum -y install httpd
systemctl start httpd
3. # Configure site files
vim /var/www/html/index.html
this is dhc web!
4. # Configure virtual vip
vim /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
ONBOOT=yes
IPADDR=192.168.61.12
NETMASK=255.255.255.255
5. # Restart network service , Open virtual network card
systemctl restart network
ifup lo:0
ifconfig lo:0
6. # Set the routing
route add -host 192.168.61.12 dev lo:0
route -n
7. # adjustment proc Response parameter
# The added system only responds to the purpose IP For the local IP Of ARP request
# The system does not use the original address to set ARP The source address of the request , It's physics mac The address on the IP
vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
8. # Refresh proc Parameters
sysctl -p
Turn off firewall 
Install and turn on httpd service 
Configure site files 
Configure virtual vip
Restart network service , Open virtual network card 
Set the routing 
adjustment proc Response parameter 
Refresh proc Parameters 
test
The currently used is mainly DR The server


Disconnect the Lord DR Server's Keepalived test


Test on the client side


边栏推荐
- [PaperNote] Web3 Direction
- 你的下一台电脑何必是电脑,探索不一样的远程操作
- [WIP] Openstack Masakari (by quqi99)
- 基于分布式数据库本身的定时备份方法
- 深度剖析「圈组」关系系统设计 | 「圈组」技术系列文章
- Flutter socketio example
- Why is your next computer a computer? Explore different remote operations
- How can the team be dissolved...
- 87.(leaflet之家)leaflet军事标绘-直线箭头修改
- 搜狐员工遭遇工资补助诈骗 黑产与灰产有何区别 又要如何溯源?
猜你喜欢

It's more convenient to keep warm water. It's a small artifact for daily milk brewing. It's a colorful jingle wireless portable milk mixer

Fortex方达发布电子交易生态体系 与客户共享共赢

87. (leaflet house) leaflet military plotting - straight arrow modification

Kubernetes common commands -1- command completion

数商云通讯行业数字化供应链协同系统:赋能通讯企业改善供应业务,增强市场竞争力

纪念正月十六工作室总访问量突破百万
10款值得你去选择的AirPods Pro竞争产品

剑指位运算

搜狐员工遭遇工资补助诈骗 黑产与灰产有何区别 又要如何溯源?

音质出色的降噪旗舰,女毒必选,贝壳王子MO3体验
随机推荐
PV operation daily question - buffer problem (advanced version)
The facial scriptures of China Saibao
【黄啊码】如何确保php上传的图片是安全的?
Flink CDC 在大健云仓的实践
String class and learning documents
Gan learning notes KL divergence, JS divergence, Wasserstein distance
Modstartcms enterprise content site building system (supporting laravel9) v4.1.0
dell G7 电脑关闭小键盘
更耐用的遊戲真無線耳機,電池超大續航持久,英雄G1上手
【Question】rxjs/operator takeWhile vs takeUntil
Carbon reduction in the construction industry is by no means a fresh idea experts suggest strengthening the transformation of rural buildings
Dell G7 computer shutdown keypad
为你推荐一款高效的IO组件——okio
【黄啊码】PHP7为什么比PHP5快两倍?
[PaperNote] Confidential Computing Direction
解析:稳定币不是「稳定的币」 其本质是一种产品
[WIP] Openstack Masakari (by quqi99)
87.(leaflet之家)leaflet军事标绘-直线箭头修改
Google Earth engine (GEE) - country identifier grid dataset
[WIP] Openstack Masakari (by quqi99)