你的位置:AG庄闲游戏官网首页 > 产品中心 > AG游戏 欧拉openEuler配置Nginx Keepalived主从和双主

AG游戏 欧拉openEuler配置Nginx Keepalived主从和双主

时间:2026-01-14 04:04 点击:158 次

AG游戏 欧拉openEuler配置Nginx Keepalived主从和双主

虚拟:172.62.17.110

Nginx主:172.62.17.111

Nginx从:172.62.17.112

一、系统优化

#关闭防火墙(两台)

systemctl stop firewalld

systemctl disable firewalld

#关闭selinux

{jz:field.toptypename/}

sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

setenforce 0

二、安装nginx,keepalived(两台)

dnf -y install nginx

dnf -y install keepalived

dnf -y install vim

三、配置Keepalived

主机配置Keepalived

ip a 查下真实网卡

vim /etc/nginx/nginx_check.sh 创建检测脚本

#!/bin/bash
counter=$(ps -C nginx --no-heading|wc -l)
if [ "${counter}" = "0" ]; then
    /usr/sbin/nginx
    sleep 2
    counter=$(ps -C nginx --no-heading|wc -l)
    if [ "${counter}" = "0" ]; then
        systemctl stop keepalived
    fi
fi

主节点配置

vim /etc/keepalived/keepalived.conf

smtp_server 172.62.17.111  # 邮箱ip改为本机
#   vrrp_strict  把这个注销,否则最后虚拟ip不通
#添加检测脚本
vrrp_script chk_http_port {
        script "/etc/nginx/nginx_check.sh"
        interval 2
        weight 2
}
vrrp_instance VI_1 {
    state MASTER   #主机这里是MASTER 从机是BACKUP
    interface ens18  #网卡
    virtual_router_id 51  # 主、从机的virtual_router_id必须相同
    priority 100   # 主、备机取不同的优先级,主机值较大,备份机值较小
    advert_int 1  #心跳检测间隔时间
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.62.17.110   # VRRP 虚拟IP ;可换行输入多个进行绑定
    }
}

从节点配置

vim /etc/keepalived/keepalived.conf

smtp_server 172.62.17.112
#添加检测脚本
vrrp_script chk_http_port {
        script "/etc/nginx/nginx_check.sh"
        interval 2
        weight 2
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens18
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.62.17.110
    }
}

在默认的keepalive.conf里面还有 virtual_server,real_server 这样的配置,我们这用不到,它是为lvs准备的。

建站客服QQ:88888888

接着重启nginx,重启keepalived

systemctl restart nginx

systemctl restart keepalived

systemctl restart nginx

systemctl restart keepalived

查日志

tail -f /var/log/messages|grep Keepalived 

四、主主配置

主节点加入VI_2

vim /etc/keepalived/keepalived.conf

vrrp_instance VI_2 {
    state BACKUP  #这里修改为BACKUP
    interface ens18
    virtual_router_id 52 #这里修改为52
    priority 90    #修改优先级
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.62.17.113  #绑定另外一个VIP
    }
track_script {
   chk_http_port
}
}

从节点加入VI_2

vrrp_instance VI_2 {
    state MASTER
    interface ens18
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.62.17.113
    }
track_script {
   chk_http_port
}
}

主从总结:

master没挂,则master占有vip且nginx运行在master上

master挂了,则slave抢占vip且在slave上运行nginx服务

如果master上的nginx服务挂了,则nginx会自动重启,AG庄闲游戏重启失败后会自动关闭keepalived,这样vip资源也会转移到slave上。

master和slave两边都开启nginx服务,无论master还是slave,当其中的一个keepalived服务停止后,vip都会漂移到keepalived服务还在的节点上。

缺点是在于,如果master一直不挂,slave有点浪费。

 

主主总结:

当任何一台服务器上面的keepalived服务停掉后,另外一台服务器上面的keepalived都会进入MASTER状态处理请求。

{jz:field.toptypename/}

如这里停掉17.111上的keepalived服务,则17.112上的keepalived服务的VRRP_Instance(VI_1)进入MASTER状态,并对虚拟17.110,17.113进行处理。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报。
服务热线
官方网站:wujunyong.com
工作时间:周一至周六(09:00-18:00)
联系我们
QQ:2852320325
邮箱:wujunyong.com @qq.com
地址:武汉东湖新技术开发区光谷大道国际企业中心
关注公众号
ag国际手机App

Copyright © 1998-2026 AG庄闲游戏官网首页™版权所有

wujunyong.com 备案号 备案号: 京ICP备12023939号-42

技术支持:®ag国际   RSS地图 HTML地图

回到顶部