keepalived+nginx使用

  1. 准备2台虚拟机,ip分别是192.168.37.133,192.168.37.134,分别安装好nginx、keepalived ,可以用docker安装nginx :docker pull nginx:1.10,

安装命令 yum install keepalived

2 编辑 /etc/keepalived/keepalived.conf ,192.168.37.133机器作为MASTER


! Configuration File for keepalived
global_defs {

}


vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.37.140
    }
}

192.168.37.14 机器作为BACKUP


! Configuration File for keepalived
global_defs {

}


vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 20
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.37.140
    }
}

3 .启动nginx 和keepalived

启动nginx:

docker run -p 80:80 --name nginx -v /mydata/nginx/conf.d:/etc/nginx/conf.d -v /mydata/nginx/nginx.conf:/etc/nginx/nginx.conf -v /mydata/nginx/html:/usr/share/nginx/html -v /mydata/nginx/log:/var/log/nginx -d nginx:1.10

启动keepalived:

systemctl start keepalived

4 访问 http://192.168.37.140

当把192.168.37.134的机器关机后,再次访问,访问了备份机器

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值