keepalived + nginx 实现双机热备

# docker run -itd  --name centos_m1 centos
# 进入容器
# docker exec -it centos_m1 /bin/bash
# 安装nginx
# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# yum install nginx
# 安装keepalived
# yum install -y gcc openssl-devel popt-devel
# yum -y install ipvsadm
# yum install keepalived

修改keepalived.conf

! Configuration File for keepalived
global_defs {
notification_email {
xxxx@xx.com
}
notification_email_from xxxx@example.com
smtp_server mail.example.com
smtp_connect_timeout
router_id LVS_DEVEL
} vrrp_script chk_nginx {
script "/etc/keepalived/nginxcheck.sh"
interval
weight -
fall
rise
} vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id
priority
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
172.17.0.200
}
track_script {
chk_nginx
} }

编辑nginxcheck.sh

A=`ps -ef | grep nginx | grep -v grep | wc -l`
if [ $A -eq ];then
#killall keepalived
ps -ef|grep keepalived|grep -v grep|awk '{print $2}'|xargs kill
fi
# 增加执行权限
# chmod +x check_nginx.sh
# docker commit centos_m1 centos_keepalived:v1

启动master容器

# docker run --privileged  -tid --name  keepalived_master centos_keepalived:v1 /usr/sbin/init
# 启动keepalived
# systemctl start keepalived.service

修改nginx主页

keepalived + nginx 实现双机热备

启动slave启动

# docker run --privileged  -tid --name  keepalived_slave centos_keepalived:v1 /usr/sbin/init
# 启动keepalived
# systemctl start keepalived.service

修改nginx主页

keepalived + nginx 实现双机热备

在实体主机上进行测试

keepalived + nginx 实现双机热备

关闭master容器的keepalived

keepalived + nginx 实现双机热备

上一篇:PHP程序员函数注释规格(麻烦大家遵守)


下一篇:mybatis-plus 批量导入返回主键id postgresql