当前位置:网站首页>keepalived配置虚拟IP
keepalived配置虚拟IP
2022-06-09 04:11:00 【小黑笔记】
YUM安装
# yum安装
yum -y install keepalived
# 查看安装版本
rpm -qa keepalived
# 查看安装路径
rpm -ql keepalived
或是使用源码安装
到这里下载 https://www.keepalived.org/download.html
# 安装依赖
yum -y install gcc openssl-devel libnfnetlink-devel
下载源码包
wget https://www.keepalived.org/software/keepalived-2.2.7.tar.gz # 在这里直接将版本号2.2.7修改想要得版本号即可
3)解压
tar -zxvf keepalived-2.2.7.tar.gz -C /usr/src
4)编译安装
cd /usr/src/keepalived-2.2.7/
./configure && make -j 4 && make install
这里是三台主机做一个虚拟IP得例子(2021年)
修改配置文件内容 /etc/keepalived/keepalived.conf
启动服务使用指令:service keepalived restart
# master节点配置内容:
! Configuration File for keepalived
vrrp_instance VI_1 {
state MASTER #这里确定master节点,多个master不知道会不会脑裂,没试
interface ens33
virtual_router_id 51
priority 100
advert_int 1
unicast_src_ip 192.168.163.134
unicast_peer {
192.168.163.132
192.168.163.133
}
authentication {
auth_type PASS
auth_pass 1111 #密码随便,每个主机要求都一样
}
virtual_ipaddress {
192.168.163.135
}
}
# node1节点配置内容:
! Configuration File for keepalived
vrrp_instance VI_1 {
state BACKUP #这里确定backup节点
interface ens33
virtual_router_id 51
priority 50
advert_int 1
unicast_src_ip 192.168.163.132
unicast_peer {
192.168.163.133
192.168.163.134
}
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.163.135
}
}
# node2节点配置
! Configuration File for keepalived
vrrp_instance VI_1 {
state BACKUP #这里确定backup节点
interface ens33
virtual_router_id 51
priority 50
advert_int 1
unicast_src_ip 192.168.163.133
unicast_peer {
192.168.163.132
192.168.163.134
}
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.163.135
}
}
这里是两台机器做的例子(2022年)
# master节点配置内容:
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.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_script web {
script "/etc/keepalived/check_web_port.sh"
interval 1
weight -20
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.163.11
}
track_script {
web
}
}
virtual_server 192.168.163.11 8080 {
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
persistence_timeout 1
protocol TCP
real_server 192.168.163.136 8080 {
weight 1
TCP_CHECK {
connect_timeout 1
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
real_server 192.168.163.137 8080 {
weight 1
TCP_CHECK {
connect_timeout 1
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
}
# node节点配置内容:
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.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_script web {
script "/etc/keepalived/check_web_port.sh"
interval 1
weight -20
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.163.11
}
track_script {
web
}
}
virtual_server 192.168.163.11 8080 {
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
persistence_timeout 1
protocol TCP
real_server 192.168.163.136 8080 {
weight 1
TCP_CHECK {
connect_timeout 1
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
real_server 192.168.163.137 8080 {
weight 1
TCP_CHECK {
connect_timeout 1
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
}
#涉及得脚本 /etc/keepalived/check_web_port.sh"
#!/bin/bash
count=`nmap 127.0.0.1|grep 8080/tcp|wc -l`
if [ $count != 0 ]
then
exit 0
else
exit 1
fi
边栏推荐
- (三)VGG复现
- Pdf merge based on pyqt5
- The talent gap is more than 500000, and the average salary is 20K? Network security, the next outlet for testers~
- RAVDESS语音情感分类数据集的介绍
- Dart:基础
- Rich color changes
- Golang--- concurrent goroutine
- Status mode simulates elevator operation
- 音频功率放大电路(使用过的语音方案电路记录)
- Audio power amplifier circuit (used voice scheme circuit record)
猜你喜欢

WinForm UI interface design routine - Custom Control ProgressBar

ACM tutorial - Hill sort

Simple reservation system for C language course design classroom

Wechat applet: (exception) expected begin_ Object but was string at line 1 column 1 path $solution and analysis process

Mysql 查询数据库中哪个表的字段个数最多

Large factory outsourcing or self research company? How to choose a job for a tester?

微信小程序:(异常)Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ 解决方案和分析流程(这里一定有你要的答案)

JVM面试

【6.824分布式系统】LEC 6&7: Fault Tolerance: Raft

Openinfra Foundation launched the "targeted fund" program to promote successful open source governance experience
随机推荐
上网行为组网
[SWPU2019]ReverseMe
(三)VGG复现
This artifact is highly recommended. One line command will convert the web page to PDF!
软件测试(二)
Common port record
变量提升和函数提升
PHP e签宝电子签名Saas API 对接流程
Expansion chip, hisi3559av100 I2C debugging
测试网站搭建+渗透+审计之第二篇渗透测试
Assembly: common commands for debug
Golang ---- storage of variables and their contents
golang---各个类型变量的比较运算
Internet behavior networking
[软件工具][教程]一个很好用的可以将csdn博客文章导出word的工具使用教程
App上看到就忍不住点的小红点是如何实现的?
17billion parameters, 28 open test sets SOTA, the industry's largest unified visual multi task model
基于PyQt5完成的PDF合并
[software tools] [tutorials] a useful tool for exporting CSDN blog articles to word
PHP deserialization recurrence - no response to the bugku login