当前位置:网站首页>Configure high availability using virtual ip+kept
Configure high availability using virtual ip+kept
2022-07-19 03:15:00 【Rock–】
Environmental statement
- centos 7 ,keepalived-2.0.20 .
- master ip :192.168.1.26 backup ip : 192.168.1.33
- vip :192.168.1.50 ( This is what we will create next ip)
- The environment I use is local area network , So I didn't test the public network environment , But the principle is the same , Nothing more than virtual ip The creation location is different .
1. Create virtual ip(virtual ip)
- I'm using centos Environment , If you are ubuntu Or other systems , Please refer to the right
It should be virtual ip Set up !
Master part
- Check the network port of the virtual machine command : ip addr

- Pay attention to the information in the red box , Don't care about anything else .
- Enter the command :cd /etc/sysconfig/network-scripts/
- Enter the command :ls

My Internet port is ens33, So my corresponding Internet port file is ifcfg-ens33, That's me ip by 192.168.1.26 Configuration file for - Enter the command :vim ifcfg-ens33

Fill in the first red box with your local ip( Is what you are using IP Address )
The next two red boxes are the virtual you want to add IP Address ( Note that the network segment address should be consistent with your local network segment )
Back UP part
- Back Up Some are special , There is no need to configure virtual IP, Just install keepalived after , stay keepalived.conf Configure the corresponding... In the file IP Just fine
2. install keepalived( Source code installation )
Master part
- keepalived Official website address ( I'm using 2.0.20)
- Compilation and installation
- Remove the compressed package from windows Put in Linux System
- tar -xvf keepalived-2.0.20.tar.gz
- ./configure --prefix=/usr/local/keepalived-1.2.15 ( Notice that there is only one ahead .)
- make && make install
- Wait for compilation and installation to complete
- modify keepalived.conf
- Because we didn't specify anything extra in the compilation and installation , So this conf The file is usually in /etc/keepalived/
- cd /etc/keepalived/
- vim keepalived.conf
I'm posted here master Part of the keepalived.conf To configure ( All that need to be used have been annotated ," # " Is the annotation identifier )
! Configuration File for keepalived
global_defs {
# When it breaks down , Notification of active / standby switchover email
#notification_email {
#[email protected]
#[email protected]
#[email protected]
#}
# email To configure
#notification_email_from [email protected]
#smtp_server 192.168.200.1
#smtp_connect_timeout 30、
# route id, Current installation keepalived Node host identifier , It is necessary to ensure global uniqueness
router_id keep_1
#router_id LVS_DEVEL
#vrrp_skip_check_adv_addr
#vrrp_strict
#vrrp_garp_interval 0
#vrrp_gna_interval 0
}
# be based on vrrp Examples of agreements , It can be understood as a server node
vrrp_instance VI_1 {
# Indicates that the status is the primary node MASTER Or standby BACKUP
state MASTER
# The network card bound by the current example , according to ip addr The network card found
interface ens33
# Virtual routing id It is necessary to ensure that the value of the primary and standby nodes is consistent
virtual_router_id 51
# priority / The weight ,master The weight is generally higher than backup, stay master Who has the highest priority after hanging up , Who can be master
priority 188
# The time interval of synchronous check between active and standby ( heartbeat ), The default is 1s
advert_int 1
# Authentication authorization password , Prevent illegal nodes from entering , The active and standby need to be consistent
authentication {
auth_type PASS
auth_pass 1111
}
# fictitious IP, There can be multiple , Modify... According to your actual situation
virtual_ipaddress {
192.168.1.50
}
}
# virtual_server 192.168.200.100 443 {
# delay_loop 6
# lb_algo rr
# lb_kind NAT
# persistence_timeout 50
# protocol TCP
# real_server 192.168.201.100 443 {
# weight 1
# SSL_GET {
# url {
# path /
# digest ff20ad2481f97b1754ef3e12ecd3a9cc
# }
# url {
# path /mrtg/
# digest 9b3a0c85a887a256d6939da88aabd8cd
# }
# connect_timeout 3
# retry 3
# delay_before_retry 3
# }
# }
# }
# virtual_server 10.10.10.2 1358 {
# delay_loop 6
# lb_algo rr
# lb_kind NAT
# persistence_timeout 50
# protocol TCP
# sorry_server 192.168.200.200 1358
# real_server 192.168.200.2 1358 {
# weight 1
# HTTP_GET {
# url {
# path /testurl/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl2/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl3/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# connect_timeout 3
# retry 3
# delay_before_retry 3
# }
# }
# real_server 192.168.200.3 1358 {
# weight 1
# HTTP_GET {
# url {
# path /testurl/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334c
# }
# url {
# path /testurl2/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334c
# }
# connect_timeout 3
# retry 3
# delay_before_retry 3
# }
# }
# }
# virtual_server 10.10.10.3 1358 {
# delay_loop 3
# lb_algo rr
# lb_kind NAT
# persistence_timeout 50
# protocol TCP
# real_server 192.168.200.4 1358 {
# weight 1
# HTTP_GET {
# url {
# path /testurl/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl2/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl3/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# connect_timeout 3
# retry 3
# delay_before_retry 3
# }
# }
# real_server 192.168.200.5 1358 {
# weight 1
# HTTP_GET {
# url {
# path /testurl/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl2/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl3/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# connect_timeout 3
# retry 3
# delay_before_retry 3
# }
# }
# }
BackUp part
- keepalived Official website address ( I'm using 2.0.20)
- Compilation and installation
- Remove the compressed package from windows Put in Linux System
- tar -xvf keepalived-2.0.20.tar.gz
- ./configure --prefix=/usr/local/keepalived-1.2.15 ( Notice that there is only one ahead .)
- make && make install
- Wait for compilation and installation to complete
- modify keepalived.conf
- Because we didn't specify anything extra in the compilation and installation , So this conf The file is usually in /etc/keepalived/
- cd /etc/keepalived/
- vim keepalived.conf
I'm posted here BackUp Part of the keepalived.conf To configure ( All that need to be used have been annotated ," # " Is the annotation identifier )
! Configuration File for keepalived
global_defs {
# notification_email {
# [email protected]
# [email protected]
# [email protected]
# }
# notification_email_from [email protected]
# smtp_server 192.168.200.1
# smtp_connect_timeout 30
# router_id LVS_DEVEL
# vrrp_skip_check_adv_addr
# vrrp_strict
# vrrp_garp_interval 0
# vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
# 192.168.200.16
# 192.168.200.17
# 192.168.200.18
192.168.1.50
}
}
# virtual_server 192.168.200.100 443 {
# delay_loop 6
# lb_algo rr
# lb_kind NAT
# persistence_timeout 50
# protocol TCP
# real_server 192.168.201.100 443 {
# weight 1
# SSL_GET {
# url {
# path /
# digest ff20ad2481f97b1754ef3e12ecd3a9cc
# }
# url {
# path /mrtg/
# digest 9b3a0c85a887a256d6939da88aabd8cd
# }
# connect_timeout 3
# retry 3
# delay_before_retry 3
# }
# }
# }
# virtual_server 10.10.10.2 1358 {
# delay_loop 6
# lb_algo rr
# lb_kind NAT
# persistence_timeout 50
# protocol TCP
# sorry_server 192.168.200.200 1358
# real_server 192.168.200.2 1358 {
# weight 1
# HTTP_GET {
# url {
# path /testurl/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl2/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl3/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# connect_timeout 3
# retry 3
# delay_before_retry 3
# }
# }
# real_server 192.168.200.3 1358 {
# weight 1
# HTTP_GET {
# url {
# path /testurl/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334c
# }
# url {
# path /testurl2/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334c
# }
# connect_timeout 3
# retry 3
# delay_before_retry 3
# }
# }
# }
# virtual_server 10.10.10.3 1358 {
# delay_loop 3
# lb_algo rr
# lb_kind NAT
# persistence_timeout 50
# protocol TCP
# real_server 192.168.200.4 1358 {
# weight 1
# HTTP_GET {
# url {
# path /testurl/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl2/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl3/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# connect_timeout 3
# retry 3
# delay_before_retry 3
# }
# }
# real_server 192.168.200.5 1358 {
# weight 1
# HTTP_GET {
# url {
# path /testurl/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl2/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url {
# path /testurl3/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# connect_timeout 3
# retry 3
# delay_before_retry 3
# }
# }
# }
- Be careful : I have two here state All are MASTER, It's best to look at it carefully. I'm Master Of keepalived.conf Configuration and comments , Which is the main and which is the standby , Mainly weight value .
So far, we two Linux The virtual IP and keepalived Configuration and installation have been completed
3. test
Master and BackUp Follow the steps below
- Enter the extracted Directory command : cd keepalived-2.0.20/keepalived
- start-up keepalived command : ./keepalived
- See if it started successfully command 1: ps -ef|grep keepalived
- See if it started successfully command 2: systemctl status keepalived.service
command 1:
command 2:
5. Turn on Master and BackUp Of keepalived
6. Carry out orders : journalctl -u keepalived ( see keepalived journal )
Master End log

BackUp End log

Master :Entering MASTER STATE
BackUp:Entering BACKUP STATE
These two sentences represent two Linux Switch between active and standby identities , I put it in private Master Linux After closing ,BackUp Linux You can switch to Master identity , When I am Master Linux After reopening , Will be able to Back Up Linux Of Master Get your identity back , The reason lies in the weight value and identity status
Common commands :
- see keepalived state :systemctl status keepalived.service
- stop it keepalived service :systemctl stop keepalived.service
- Start keepalived service :systemctl start keepalived.service
边栏推荐
- Multi table query - case exercise
- Replacement operation not supported by ncnn partial operators
- [MCU simulation] (VII) addressing mode - bit addressing
- 关于XML文件(六)-与JSON的区别
- First knowledge of JPA (ORM idea, basic operation of JPA)
- 【单片机仿真】(十七)控制转移类指令 — 调用及返回指令
- Polynomial interpolation fitting (I)
- Mysql多表查询
- [MCU simulation] (XVII) control transfer instructions - call and return instructions
- 【单片机仿真】(十一)指令系统逻辑运算指令 — 逻辑与指令ANL、逻辑或指令ORL
猜你喜欢

通过Dao投票STI的销毁,SeekTiger真正做到由社区驱动

04_服务注册Eureka

JDBC连接Mysql数据库

PyTorch最佳实践和代码模板

C language foundation day4 array

Authentication code for wireless

3. Asynctool framework principle source code analysis

JPA初识(ORM思想、JPA的基本操作)

By voting for the destruction of STI by Dao, seektiger is truly community driven

The place where the dream begins ---- first knowing C language
随机推荐
[regression prediction] lithium ion battery life prediction based on particle filter with matlab code
04_服务注册Eureka
我最高产的EasyPyPI又双叒叕更新了!v1.4.0发布
【单片机仿真】(二十一)DB(Define Byte)— 定义字节
D. Permutation Restoration(贪心/双指针/set)
工具及方法 - Excel插件XLTools
Examine your investment path
LETV has more than 400 employees? Living a fairy life without a boss, the official responded
内置键盘连续444
RESNET learning notes
[MCU simulation] (XVII) control transfer instructions - call and return instructions
Bisenetv2 face segmentation ncnn reasoning
This is a mathematical problem
Comparison between redis and other databases
SQL classic exercises (x30)
[PHP] tp6 multi table connection query
【单片机仿真】(十四)指令系统位操作类指令 — 位数据传送指令MOV、位变量修改指令
mysql复制表
About XML file (VI) - the difference between JSON and XML file
In depth understanding of machine learning - unbalanced learning: sample sampling technology - [adasyn sampling method of manual sampling technology]