Nginx+Tomcat+Keepalived实现高可用Web集群(2)

1、安装:
    yum install keepalived -y
2、修改配置文件/etc/keepalived/keepalived.conf
MASTER 端:
! Configuration File for keepalived
vrrp_script check_nginx {
        script "/etc/keepalived/check_nginx.sh"
        interval 2
        weight 2
}
global_defs {
  notification_email {
    acassen@firewall.loc
    failover@firewall.loc
    sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 192.168.200.1
  smtp_connect_timeout 30
  router_id LVS_DEVEL1
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.10.10.100/24 dev eth0
  }
 track_script {
        check_nginx
  }
}
BACKUP端:
修改:
router_id LVS_DEVEL2
state BACKUP
priority 90

检测Nginx脚本:
#!/bin/bash
nginxpid=`ps -C nginx --no-header | wc -l`
if [ $nginxpid -eq 0 ];then
        /etc/init.d/keepalived stop
fi
chmod +x /etc/keepalived/check_nginx.sh

重启Keepalived服务
service keepalived restart

四、检验服务的高可用

Nginx1执行:killall nginx
发现 web访问依然正常

Tomcat1执行:/usr/local/apache-tomcat-9.0.7/bin/shutdown.sh
发现 web访问依然正常

高可用的环境搭建完毕。

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/6648f54c3350ad4421a9270e1c97ebde.html