docker配置keepalive

docker配置keepalive,第1张

docker配置keepalive

节点

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

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5704404.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存