• 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

  • 相关阅读:
    利用python在windows环境下爬取赶集网工作信息。
    扔骰子
    python 输入英语单词,查看汉语意思
    获取指定日期的上一个月日期
    爬取代理IP,并判断是否可用。
    递归实现 十进制转换其他进制(2-16)
    特殊回文数
    python 实现无序列表
    python 实现剪刀石头布(三局两胜)
    python 实现简单语音聊天机器人
  • 原文地址:https://www.cnblogs.com/tonyY/p/4893035.html
Copyright © 2020-2023  润新知