当前位置:网站首页>Lvs+keepalived project practice
Lvs+keepalived project practice
2022-07-27 02:20:00 【Face danger】
List of articles
- Experiment preparation
- One 、 What is? lvs colony
- Two 、lvs+NAT experiment
- 3、 ... and 、lvs Routing mode +keepalived Project practice
Experiment preparation
| client | 192.168.4.10 |
|---|---|
| lvs | 192.168.2.20/192.168.4.20 |
| lvs1 | 192.168.4.30 |
| web1 | 192.168.2.200/192.168.4.200 |
| web2 | 192.168.2.200/192.168.4.200 |
this paper 2 An experiment (centos7)
1:lvsNAT experiment
The machine used :client+lvs+web1+web2
2:lvsDR+keepalived experiment
The machine used :client+lvs+lvs1+web1+web2
One 、 What is? lvs colony
LVS yes Linux Virtual Server Abbreviation , meaning Linux Virtual server , Is a virtual server cluster system .
lvs The working mode is
NAT: Network address translation
DR: Routing mode
TUN: Tunnel model
Scheduling algorithm : There is support for 10 Kind of , common 4 Kind of
polling rr:Real Server Take turns providing services
Weighted polling wrr:Real Server According to the weight , Take turns providing services
The minimum connection LC: according to Real Server Number of connections , Allocation request
Weighted least connected WLC: Be similar to wrr, Assign different weights to different servers
Two 、lvs+NAT experiment
1.web1 and web2 install httpd service ( Turn off firewall ,selinux)
yum -y install httpd (2 Taiwan machine ) And have access to http

2.web1 and web2 configure gateway
web1 and web2 Do it at the same time
because lvs Yes 2 Address 2.20 It can be accessed as a network card 4.0 Content of network segment
[[email protected] ~]# nmcli connection modify eth1 ipv4.gateway 192.168.2.20
[[email protected] ~]# ifdown eth1; ifup eth1
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.2.20 0.0.0.0 UG 100 0 0 eth1
192.168.2.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1
3. To configure lvs
Turn on lvs Route forwarding function
[[email protected] ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
[[email protected] ~]# sysctl -p // Make profile effective
net.ipv4.ip_forward = 1
install lvs
yum install -y ipvsadm
ipvsadm grammar
-A: Add a virtual server ( fictitious IP)
-E: Edit virtual server
-t|u:tcp or udp agreement
-s: Specify scheduling algorithm , Such as rr/wrr/lc/wlc
-a: After creating the virtual server , Add a real server to the virtual server
-r: Real server address
-w: Set weight , The default is 1
-m: Appoint LVS The working mode of NAT
-g: Appoint LVS The working mode of DR
lvs NET To configure
[[email protected] ~]# ipvsadm -A -t 192.168.4.20:80 -s rr // Creating a virtual server scheduling algorithm is polling
[[email protected] ~]# ipvsadm -a -t 192.168.4.20:80 -r 192.168.2.100 -w 1 -m // Add a real server to the virtual server web1 The weight of 1 nat Pattern
[[email protected] ~]# ipvsadm -a -t 192.168.4.20:80 -r 192.168.2.200 -w 2 -m
[[email protected] ~]# ipvsadm -Ln // Check the specific configuration
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.4.20:80 rr
-> 192.168.2.100:80 Masq 1 0 0
-> 192.168.2.200:80 Masq 2 0 0
[[email protected] ~]# systemctl stop firewalld.service Turn off firewall
Client access lvs Scheduler

3、 ... and 、lvs Routing mode +keepalived Project practice
LVS Of DR Pattern ,LVS Only one network card is needed (4.0 Network segment )
VIP: Virtual address , The address provided to the user for access
keepalived: Used to implement high availability cluster 
1. To configure web1,web2 Of vip:192.168.4.40(2 platform web The machine configuration is the same )
[[email protected] network-scripts]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-lo ifcfg-lo:0
[[email protected] network-scripts]# vim ifcfg-lo:0
DEVICE=lo:0 //lo It's local
IPADDR=192.168.4.40 // Configure virtual address
NETMASK=255.255.255.255 // Here we must 255.255.255.255 Otherwise mistakes
NETWORK=192.168.4.40
BROADCAST=192.168.4.40
ONBOOT=yes
NAME=lo:0
2. stay 2 platform web Modify kernel parameters on the server , Make them not respond vip Query request for
[[email protected] network-scripts]# vim /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>
.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
[[email protected] network-scripts]# sysctl -p // Configuration takes effect
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
3. lvs install keepalived
yum install -y keepalived
yum -y install ipvsadm
The configuration file
[[email protected] ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected] // Addressee address
}
notification_email_from [email protected].cn // sender address
smtp_server 127.0.0.1 // Mail server address
smtp_connect_timeout 30
router_id lvs // Unique category ID
vrrp_iptables // Auto on IPTABLES Release rules
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.4.40/24 // VIP Address
}
}
virtual_server 192.168.4.40 80 {
// LVS Virtual server
delay_loop 6 // Health check delay 6 second
lb_algo rr // Scheduling algorithm
lb_kind DR // Working mode
persistence_timeout 50 // 50 Within seconds, the same client is scheduled to the same server
protocol TCP
real_server 192.168.4.100 80 {
# real server To configure
weight 1 // The weight
TCP_CHECK {
// Yes real server Configuration of health check
connect_timeout 3 // Connection timeout
nb_get_retry 3 // Health check retry times
delay_before_retry 3 // The interval between two inspections
}
}
real_server 192.168.4.200 80 {
// real server To configure
weight 1 // The weight
TCP_CHECK {
// Yes real server Configuration of health check
connect_timeout 3 // Connection timeout
nb_get_retry 3 // Health check retry times
delay_before_retry 3 // The interval between two inspections
}
}
}
Start the service to view the configuration
systemctl start keepalived.service
Client access
[[email protected] ~]# curl 192.168.4.40
woshiweb2
[[email protected] ~]# curl 192.168.4.40
woshiweb2
[[email protected] ~]# curl 192.168.4.40
woshiweb2
[[email protected] ~]# curl 192.168.4.40
woshiweb2
[[email protected] ~]# curl 192.168.4.40
woshiweb2
4. lvs1 install keepalived
yum install -y keepalived
yum -y install ipvsadm
The configuration file
[[email protected]~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id lvs1 // Host name
vrrp_iptables
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP // Change the backup mode here
interface eth0
virtual_router_id 51
priority 80 // Priority is higher than lvs low
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.4.40/24
}
}
virtual_server 192.168.4.40 80{
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.4.100 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.4.200 80 {
weight 2
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
Start the service
systemctl start keepalived.service
To turn it off lvs Client access


边栏推荐
- Esp8266wi fi access cloud platform
- OSPF basic configuration application (comprehensive experiment: interference election default routing area summary authentication -- interface authentication)
- C语言——while语句、dowhile语句、for循环和循环结构、break语句和continue语句
- 广域网技术实验
- C语言——第一个程序、打印、变量和常量
- npm报错, Error: EPERM: operation not permitted, mkdir
- HCIA动态路由OSPF实验
- Ogeek meetup phase I, together with cubefs, is hot
- Introduction to STM32 lesson 1
- HCIA基础知识(1)
猜你喜欢

第五讲—按键控制LED

Solution: various error reports and pit stepping and pit avoidance records encountered in the alchemist cultivation plan pytoch+deeplearning (II)

TIM输出比较——PWM

Text to image intensive reading df-gan:a simple and effective baseline for text to image synthesis

Lora通信应用开发

OSPF basic configuration application (comprehensive experiment: interference election default routing area summary authentication -- interface authentication)

TCP的三次握手与四次挥手(简述)

RS-485总线通信应用

C语言实现小游戏【三子棋】注释详细 逻辑清晰 快来看看吧!!

数字集成电路:MOS管器件章(二)
随机推荐
FID index reproduction step on the pit to avoid the pit text generation image FID quantitative experiment whole process reproduction (FR é Chet inception distance) quantitative evaluation experiment s
Simple application of rip V2 (V2 configuration, announcement, manual summary, ripv2 authentication, silent interface, accelerating convergence)
Text to image intensive reading of paper gr-gan: gradually refine text to image generation
Introduction to STM32 lesson 1
The basic configuration of static routing (planning of IP address and configuration of static routing) realizes the accessibility of the whole network.
RIP V2 的简单应用(v2的配置、宣告、手工汇总、RIPV2的认证、沉默接口、加快收敛)
识时务者常用网址大全
Three methods that can effectively fuse text and image information -- feature stitching, cross modal attention, conditional batch normalization
Influence of pre frequency division value and automatic reload value on interrupt frequency
7.16 written examination of Duoyi network
STM32 introductory tutorial lesson 2
2022 latest Tiktok live broadcast monitoring (II) streaming media download in live broadcast room
RS-485总线通信应用
静态路由综合实验
MySQL课程2.表的各种查询
Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis
Lora通信应用开发
初识C语言(2)
JUC并发编程
Lora网关节点汇聚传感器数据