概述
节点
192.168.182.143
192.168.182.144
加载镜像 keepalived.tar.gz
docker load -i keepalived.tar.gz
192.168.182.144节点
[root@hostname-144 k8s-hatools]# cat kconf/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_HARBOR_2
}
vrrp_script checkhaproxy
{
script "/opt/check.sh"
interval 1
weight -30
}
vrrp_instance VI_3 {
state BACKUP
interface ens33
virtual_router_id 144
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass aaaqaz
}
virtual_ipaddress {
192.168.182.146/24
}
track_script
{
checkhaproxy
}
}
配置检查脚本
[root@hostname-144 k8s-hatools]# cat kconf/check.sh
#!/bin/bash
count=`netstat -ntl | grep 1331 | wc -l`
if [ $count -gt 0 ]; then
exit 0
else
exit 1
fi
192.168.182.143节点
[root@hostname-143 k8s-hatools]# cat kconf/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_HARBOR_1
}
vrrp_script checkhaproxy
{
script "/opt/check.sh"
interval 1
weight -30
}
vrrp_instance VI_3 {
state MASTER
interface ens33
virtual_router_id 144
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass aaaqaz
}
virtual_ipaddress {
192.168.182.146/24
}
track_script
{
checkhaproxy
}
}
这里的state MASTER ;priority 100; router_id LVS_HARBOR_1需要修改
[root@hostname-144 k8s-hatools]# cat kconf/check.sh
#!/bin/bash
count=`netstat -ntl | grep 1331 | wc -l`
if [ $count -gt 0 ]; then
exit 0
else
exit 1
fi
在两个节点都写上启动脚本,并启动
[root@hostname-144 k8s-hatools]# cat run-keepalived.sh
docker run -d --name harbor-keepalive --restart=always --cap-add=NET_ADMIN --cap-add=NET_BROADCAST --cap-add=NET_RAW --net=host -v ${PWD}/kconf/keepalived.conf:/container/service/keepalived/assets/keepalived.conf -v ${PWD}/kconf/check.sh:/opt/check.sh --detach osixia/keepalived:2.0.20 --copy-service
验证
配置说明
推荐配置说明https://www.cnblogs.com/rexcheny/p/10778567.html
最后
以上就是兴奋故事为你收集整理的docker配置keepalive的全部内容,希望文章能够帮你解决docker配置keepalive所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复