• Nginx + Keepalived 双机热备


    基于Nginx和Keepalived双机热备

    Keepalived 实现双机热备,消除一台机器单点故障的发生。准备2台机器ip地址分别为192.168.163.34、192.168.163.35。同时这2台机器都设置同一虚拟ip,
    这里虚拟ip设置为192.168.163.100。2台机器都需要装上nginx和keepalived。

    设置虚拟ip

    这里要用到虚拟ip,虚拟ip的设置参考

    安装nginx 并启动

    nginx安装

    192.168.163.34启动

    192.168.163.35启动

    安装Keepalived

    tar –zxvf keepalived-1.2.19.tar.gz
    cd keepalived-1.2.19
    ./configure --prefix=/usr/local/keepalived
    make
    make install
    

    keepalived.conf配置(192.168.163.34)

    ! 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 192.168.200.1
       smtp_connect_timeout 30
       router_id LVS_DEVELA #MASTER节点
    }
    
    vrrp_instance VI_1 {
        state MASTER
        interface eth1
        virtual_router_id 51 #主、备必须一样  
        priority 100 #优先级
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.163.100 #VRRP HA虚拟地址
        }
    }
    

    keepalived.conf配置(192.168.163.35)

    ! 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 192.168.200.1
       smtp_connect_timeout 30
       router_id LVS_DEVELB #BACKUP节点
    }
    
    vrrp_instance VI_1 {
        state BACKUP
        interface eth1
        virtual_router_id 51 #主、备必须一样  
        priority 99#优先级
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.163.100 #VRRP HA虚拟地址
        }
    }
    
    

    建立软链接并启动keepalived

    ln -s /usr/local/keepalived/sbin/keepalived /sbin/
    ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
    ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
    keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf
    

    测试

    测试可见,浏览器中我们通过虚拟ip来访问,如上面所设置的会访问到master 34的机器。34这台机器的优先级高于35。

    停用master机器

    master机器停用(宕机、nginx死机等)会看到自动切换到35 backup那台机器。即192.168.163.34那台机器访问不了。

    参考

    nginx-ha-keepalived
    keepalived

  • 相关阅读:
    启动程序相关的命令
    分享的几行代码
    各种大数据软件安装
    tomcat报没法分配内存大小解决方案
    数据库事务
    pytorch之CNN实现
    搜索与匹配
    调试 pytorch 及 python 的 特殊语法
    图神经网络 GCN 等综述(转载)
    关于【finder不能完成该操作 因为未能读取或写入"文件名"中的某些数据(错误代码-36)】(实测,好用)
  • 原文地址:https://www.cnblogs.com/tonyY/p/4893035.html
Copyright © 2020-2023  润新知