CentOS 7.8 部署nginx+keepalived双主配置

栏目:技术教程 发布时间 2020-10-16 人气 

来源:http://www.mamicode.com/info-detail-3085697.html

TAG:无

侵权:admin@heimacode.com

免责声明:本文图片引用自网络,如有侵权请联系我们予以删除

黑码网发布此文仅为传递信息,不代表黑码网认同其观点。

简介:标签:padinuxefsicayum配置文件viprouterouterKeepalived是Linux下面实现VRRP备份路由的高可靠性运行软件,能够真正做到主服务器和备份服务器故障时IP瞬间无缝交接部署过程两台机器安装nginx和keepalived192.168.10.130 node192.168.10.140 node192.168.10.120 VIP192.168.10.12...

标签:pad   inux   efs   ica   yum   配置文件   vip   router   outer   

Keepalived是Linux下面实现VRRP备份路由的高可靠性运行软件,能够真正做到主服务器和备份服务器故障时IP瞬间无缝交接

部署过程

两台机器安装nginx和keepalived

192.168.10.130  node
192.168.10.140  node
192.168.10.120  VIP
192.168.10.121  VIP

两台机器都安装

yum install -y nginx keepalived

健康检查脚本

cat /server/scripts/check_nginx.sh
#!/bin/bash
# check nginx service

run=`ps -C nginx --no-header | wc -l`
if [ $run -eq 0 ]
then
        /etc/rc.d/init.d/nginx start
        sleep 3
fi

node上的keepalived配置

cat /etc/keepalived/keepalived.conf 

! Configuration File for keepalived
global_defs {
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}
vrrp_script chk_nginx{
       script "/server/scripts/check_nginx.sh"
       interval 2
       weight 2
}
#VIP1
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 50
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.20
    }
}
track_script {
       check_nginx
}
#VIP2,新增配置,新增一个实例VI_2
vrrp_instance VI_2 {
    state BAKCUP
    interface eth0
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.21
    }
} 

另外一台node的keepalived的配置文件

! Configuration File for keepalived

global_defs {
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}
vrrp_script chk_nginx{
       script "/server/scripts/check_nginx.sh"
       interval 2
       weight 2
}
#VIP1
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 50
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.20
    }
}
track_script {
       check_nginx
}

#VIP2,新增的实例,VI_2
vrrp_instance VI_2 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.21
    }
} 

配置完成启动服务即可

systemctl enable keepalived  && systemctl start keepalived
systemctl enable nginx  && systemctl start nginx

至此部署完成

CentOS 7.8 部署nginx+keepalived双主配置

标签:pad   inux   efs   ica   yum   配置文件   vip   router   outer   

原文地址:https://www.cnblogs.com/huanglingfa/p/13823937.html

资源来源网络,若未解决请查看原文

本文地址:https://www.heimacode.com/article/60668.html