博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
实现双主模型NGINX架构
阅读量:7043 次
发布时间:2019-06-28

本文共 4086 字,大约阅读时间需要 13 分钟。

实验拓扑图

image

主节点配置

yum -y install nginx keepalived psmisc#修改keepalived配置文件vim  /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_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.confupstream 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

从节点配置

! Configuration File for keepalivedglobal_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 LVS2           #用于标识本节点的名称   vrrp_garp_interval 0   vrrp_gna_interval 0   vrrp_iptables            #关闭防火墙功能#   vrrp_mcast_group4 172.20.29.77}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 BACKUP            #定义状态为主或从    interface ens34         #定义外对的网卡接口    virtual_router_id 88    #虚拟路由ID,相同的ID为一组    priority 98             #定义从服务器的优先级    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 MASTER    interface ens34    virtual_router_id 99    priority 96    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.confupstream 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

web服务器配置

#配置httpd页面echo "

`hostname`

" > /var/www/html/index.html#添加VIPip a a 172.20.29.111/32 dev lo#配置VIP不冲突echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignoreecho 1 > /proc/sys/net/ipv4/conf/lo/arp_ignoreecho 2 > /proc/sys/net/ipv4/conf/all/arp_announceecho 2 > /proc/sys/net/ipv4/conf/lo/arp_announce#开启服务systemctl start httpd

转载于:https://blog.51cto.com/13769014/2146906

你可能感兴趣的文章
java中的匿名内部类总结
查看>>
maven 使用filter动态处理资源文件变量
查看>>
linux 环境下使用信号量实现司机售票员进程同步,线程同步问题
查看>>
Ansible随机数
查看>>
Apache运维架构之Apache+PHP
查看>>
Sed简介
查看>>
Find 75000万像素和诺基亚的不是一个概念
查看>>
mysql处理添加外键时 error 150 问题
查看>>
企业如何针对用户数据进行有效保护
查看>>
Tomcat启动时报 java.lang.OutOfMemoryError: Java heap space
查看>>
Active Directory 基础回顾 (三)FSMO迁徙方式小总结
查看>>
Shell Script不同运行方式的区别
查看>>
Linux系统基本网络配置之ifconfig命令
查看>>
看几大IT公司的JSON利器
查看>>
Cocos2d-x 物理场景简单搭建
查看>>
认识“JPG、TXT”格式的病毒
查看>>
redhat6.2配置本地yum源
查看>>
IBM System x3850 X5如何级联
查看>>
php 类,对象,继承,接口,抽象
查看>>
修改开机提示
查看>>