linux使用keepalived做nginx负载和虚拟ip(vip)

1 下载需要的依赖

yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel

yum install -y keepalived

2 修改keepalived.conf 配置文件(etc/keepalived)

global_defs {

  # Keepalived process identifier

  router_id nginx

}

# Script to check whether Nginx is running or not

vrrp_script check_nginx {

  script "/etc/keepalived/check_nginx.sh"   ----脚本路径

  interval 2 --每几秒刷新

  weight -20

}

# Virtual interface - The priority specifies the order in which the assigned interface to take over in a failover

vrrp_instance VI_01 {

  state MASTER --主机标识,如果是从机就是BACKUP

  interface eth0

  virtual_router_id 151 --标识id,每个机器都不一样

  priority 110 --优先级,主机大,从机小

  # The virtual ip address shared between the two NGINX Web Server which will float

  virtual_ipaddress {

    172.16.16.103/24 --虚拟ip

  }

  track_script {

    check_nginx

  }

  authentication {

    auth_type AH

    auth_pass secret

  }

}

3 新建nginx监听脚本  check_nginx.sh

count=$(ps -ef |grep nginx |egrep -cv "grep|$$")

if [ "$count" -eq 0 ];then

    systemctl stop keepalived

fi

4 赋权 chmod 755 check_nginx.sh

5 启动systemctl start keepalived

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值