实现双主模型NGINX架构
yum -y install nginx keepalived psmisc #修改keepalived配置文件vim/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS1 #用于标识本节点的名称
vrrp_garp_interval 0
vrrp_gna_interval 0
vrrp_iptables #关闭防火墙功能
#vrrp_mcast_group4 224.0.0.18
}
vrrp_script chk_down {#定义检测资源
script "/bin/bash -c '[[ -f /etc/keepalived/down ]]' && exit 1 || exit 0"
interval 1 #间隔检测时间
weight -5 #检测失败后权重-5
}
vrrp_script chk_nginx { #定义检测资源
script "killall -0 nginx && exit 0 || exit 1"
interval 1 #间隔检测时间
weight -5 #检测失败后权重-5
}
vrrp_instance VI_1 {
state MASTER #定义状态为主或从
interface ens34 #定义对外的网卡接口
virtual_router_id 88 #虚拟路由ID,相同的IP为一组
priority 100 #定义主节点的优先级
advert_int 1
authentication { #定义认证信息
auth_type PASS
auth_pass rilegou
}
virtual_ipaddress { #定义虚拟IP(VIP)
172.20.29.111
}
track_script { #调用定义的检测资源脚本
chk_nginx
chk_down
}
}
vrrp_instance VI_2 {
state BACKUP
interface ens34
virtual_router_id 99
priority 95
advert_int 1
authentication {
auth_type PASS
auth_pass centos
}
virtual_ipaddress {
172.20.29.114
}
track_script { #调用定义的检测资源脚本
chk_nginx
chk_down
}
}
#配置NGINX服务
vim /etc/nginx/conf.d/test.conf
upstream websrvs {
server 172.20.29.103:80;
server 172.20.29.104:80;
}
server {
listen 80 default_server;
server_name node01.magedu.com;
root /usr/share/nginx/html;
location / {
proxy_pass http://websrvs;
}
}
#开启服务
systemctl nginx keepalived
页:
[1]