keeplive 双击热备方案 (对haproxy负载均衡 )双击热备方案
1.安装 keepalived ,必选安装在haproxy 容器之内
1.进入容器:docker exec -it h1 bash 后执行下面步骤
1.更新apt-get
apt-get update
2.安装keepalived
apt-get install keepalived
3. 安装成功后 keepalived 创建配置文件在 /etc/keepalived/keepalived.conf
vrrp_instance VI_1 { state MASTER #节点身份 master 会争抢虚拟ip interface ens33 #docker虚拟机网卡宿主机映射网络 virtual_router_id 51 mcast_src_ip 192.168.224.206 priority 100 #权重 advert_int 1 #心跳检测间隔 1s authentication { #心跳检测需要登录到keepalived,主从服务器验证,主备必须一致才行能正常通讯 auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.224.208 #虚拟ip 往网卡中写入虚拟ip,docker内部可见 } track_script{ chk_nginx } }
4,启动keepalived 服务
service keepalived start
配置信息详解:https://blog.csdn.net/qq_26545305/article/details/79957992
5.安装完成后退出容器,exit 只会退出交互界面而不会退出程序
退出容器 在宿主机可以ping通虚拟IP
ping 192.168.224.208
二、同样的步骤在h2 haproxy 容器中安装keepalived ,其中keepalived.conf 文件使用同一份