https://blog.csdn.net/qq_43442524/article/details/105706017
https://blog.csdn.net/guhong888/article/details/82344775
https://www.jianshu.com/p/d83249b72b06
https://blog.csdn.net/weixin_51052054/article/details/112803200
https://baijiahao.baidu.com/s?id=1672520162384771451&wfr=spider&for=pc
安装依赖
yum install -y curl gcc openssl openssl-devel libnl libnl-devel -y
安装keepalive ipvsadm
yum install keepalived -y
查看安装路径
rpm -ql keepalived
查看网卡设备信息
nmcli device
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
#保存退出
sysctl -p
103编写keepalive
! Configuration File for keepalived
global_defs {
notification_email {
514840279@qq.com
}
notification_email_from 514840279@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL_103 # 全局唯一
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER
interface em1
virtual_router_id 51
priority 100
advert_int 2
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.101
}
}
virtual_server 192.168.0.101 9082 {
delay_loop 1
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.0.105 9082 {
weight 1
HTTP_GET|SSL_GET { #定义checker的方法(TCP/HTTP/SSL/MISC)
connect_port 9082 #定义tcp的port
connect_timeout 3 #定义本次连接的超时时长为3s
nb_get_retry 3 #定义尝试3次,如果3次都失败则宣告本real_server失效
delay_before_retry 3 #定义重连接间隔时间为3s
}
}
}
# 保存
systemctl restart keepalived
ps -ef | grep keepalived
ip add
image.png
win下
aro -a
httpd
因为端口80被占需要修改端口 这里统一用9082
105
yum install -y httpd
systemctl stop httpd.service
find /etc/httpd/ -name *.conf
vim /etc/httpd/conf/httpd.conf
# 修改端口为 9082.
#http 不允许修改默认的80端口,这里需要关闭setenforce
setenforce 0
systemctl start httpd.service
systemctl enable --now httpd.service
echo server105 > /var/www/html/index.html
103
yum install -y httpd
setenforce 0
systemctl stop httpd.service
find /etc/httpd/ -name *.conf
vim /etc/httpd/conf/httpd.conf
# 修改端口为9082.
systemctl start httpd.service
systemctl enable --now httpd.service
echo server103 > /var/www/html/index.html
配置
同理105上安装keepalive 配置conf
https://www.cnblogs.com/along1226/p/5027838.html
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
514840279@qq.com
}
notification_email_from 514840279@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL_105 # 唯一
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP # 备份服务
interface em1
virtual_router_id 51 # 主从一致
priority 50 #
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.101
}
}
virtual_server 192.168.0.101 9082 {
delay_loop 1
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.0.103 9082 {
weight 1
HTTP_GET|SSL_GET{ #定义checker的方法(TCP/HTTP/SSL/MISC)
connect_port 9082 #定义tcp的port
connect_timeout 3 #定义本次连接的超时时长为3s
nb_get_retry 3 #定义尝试3次,如果3次都失败则宣告本real_server失效
delay_before_retry 3 #定义重连接间隔时间为3s
}
}
real_server 192.168.0.105 9082 {
weight 1
HTTP_GET|SSL_GET{ #定义checker的方法(TCP/HTTP/SSL/MISC)
connect_port 9082 #定义tcp的port
connect_timeout 3 #定义本次连接的超时时长为3s
nb_get_retry 3 #定义尝试3次,如果3次都失败则宣告本real_server失效
delay_before_retry 3 #定义重连接间隔时间为3s
}
}
}
启动
systemctl start keepalived
开启自启
systemctl enable keepalived
到此处keepalive配置完成,使用ip addr
在103上有ip
关闭 103的keepalive
systemctl stop keepalived
查看
ip addr
发现 105上有ipimage.png
重启103的keepalive ip又回来了
点波关注 系统搭建(docker)
网友评论