1.环境准备
1.两台服务器 2,都安装上nginx 3,以及keeplived
2.keeplived的安装
yum install keepalived-y
安装之后在etc/keepalived 有文件keepalived.conf
3.配置文件的修改
3.1 修改/etc/keepalived/keepaliveed.conf配置文件
global_defs{
notification_email{
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen @firewall.loc
smtpserver 192.168.17.129
smtp_connect_timeout30
router_id LVS_DEVEL
}
vrrp_script chk_http_port{
script"/usr/local/src/nginx_check.sh"
interval2#(检测脚本执行的间隔)
weight2
}
vrrp_instance VL_1{
state BACKUP#备份服务器上将MASTER改为BACKUP
interface ens33/网卡
virtual_router_id51#主、备机的virtual_router_id必须相同
priority90#主、备机取不同的优先级,主机值较大,备份机值较小
advert_int 1
authentication{
auth_type PASS
auth_pass1111
virtual_ipaddress{
192.168.17.50//VRRPH虚拟地址
}
}
3.2 在/usr/local/src 添加检测脚本
#!/bin/bash A='ps-C nginx -no-header wc-1
if [$A-eq 0];then
/usr/local/nginx/sbin/nginx sleep2
if [ps-C nginx --no-header |wc -1'-eq 0];then killall keepalived fifi
4.测试
访问如果没有问题 将主服务器宕机,看是否访问成功,如果成功代表没有问题。