
配置

vi /etc/hosts
127.0.0.1 LVS_DEVEL
- 修改 /etc/keepalived
注意虚拟ip 地支要和 主机ip地址在一个网段
主机ip : 192.168.223.131
虚拟ip : 192.168.223.50
主节点配置
global_defs {notification_email {acassen@firewall.locfailover@firewall.locsysadmin@firewall.loc}notification_email_from Alexandre.Cassen@firewall.locsmtp_ server 192.168.17.129smtp_connect_timeout 30router_id LVS_DEVEL # LVS_DEVEL这字段在/etc/hosts文件中看;通过它访问到主机}vrrp_script chk_http_ port {script "/usr/local/src/nginx_check.sh"interval 2 # (检测脚本执行的间隔)2sweight 2 #权重,如果这个脚本检测为真,服务器权重+2}vrrp_instance VI_1 {state MASTER # 备份服务器上将MASTER 改为BACKUPinterface ens33 //网卡名称virtual_router_id 51 # 主、备机的virtual_router_id必须相同priority 100 #主、备机取不同的优先级,主机值较大,备份机值较小advert_int 1 #每隔1s发送一次心跳authentication { # 校验方式, 类型是密码,密码1111auth type PASSauth pass 1111}virtual_ipaddress { # 虛拟ip192.168.223.50 // VRRP H虛拟ip地址}}
从节点配置
global_defs {notification_email {acassen@firewall.locfailover@firewall.locsysadmin@firewall.loc}notification_email_from Alexandre.Cassen@firewall.locsmtp_ server 192.168.17.129smtp_connect_timeout 30router_id LVS_DEVEL # LVS_DEVEL这字段在/etc/hosts文件中看;通过它访问到主机}vrrp_script chk_http_ port {script "/usr/local/src/nginx_check.sh"interval 2 # (检测脚本执行的间隔)2sweight 2 #权重,如果这个脚本检测为真,服务器权重+2}vrrp_instance VI_1 {state BACKUP # 备份服务器上将MASTER 改为BACKUPinterface ens33 //网卡名称virtual_router_id 51 # 主、备机的virtual_router_id必须相同priority 90 #主、备机取不同的优先级,主机值较大,备份机值较小advert_int 1 #每隔1s发送一次心跳authentication { # 校验方式, 类型是密码,密码1111auth type PASSauth pass 1111}virtual_ipaddress { # 虛拟ip192.168.223.50 // VRRP H虛拟ip地址}}

#! /bin/bashA=`ps -C nginx -no-header | wc - 1`if [ $A -eq 0];then/usr/local/nginx/sbin/nginxsleep 2if [`ps -C nginx --no-header| wc -1` -eq 0 ];thenkillall keepalivedfifi

启动nginx
启动keepalived
systemctl start keepalived.service
