• keepalived主备配置


    环境:

    centos7.6

    node1  master  192.168.1.172

    node    backup 192.168.1.173

    vip  192.168.1.174

    首先realserver安装分别安装httpd和keepalived,yum安装即可

    在node1 /var/www/html/目录创建index.html文件

     开启httpd服务访问192.168.1.172

     在node2 /var/www/html/目录创建index.html

     开启httpd服务访问192.168.1.173

    keepalived配置

    master配置

    global_defs {

        notification_email {
        ceshi@qq.com       

    }

    # notification_email_from Alexandre.Cassen@firewall.loc
    # smtp_server 192.168.200.1
    # smtp_connect_timeout 30
    router_id node1
    # vrrp_skip_check_adv_addr
    # vrrp_strict
    # vrrp_garp_interval 0
    # vrrp_gna_interval 0
    }

     vrrp_instance VI_1 {

      state MASTER

      interface ens160           #设置监听网口

    virtual_router_id 51
    priority 100                   #数字越大,等级越高,保证比backup高即可
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    192.168.1.174
    }
    }

    backup配置

    参照上面配置文件,修改如下配置

    router_id node2

    state BAKCUP

    priority 99

    保存后,开启主备keepalived    systemctl start keepalived

    用ip a l命令查看虚ip在哪台服务器上

     浏览器访问192.168.1.174可以看到是访问的node1

     将master的keepalived关闭或网口关闭关机等操作,虚ip自动飘到backup。

    以上有个弊端,如果master上的httpd服务挂了并不会自动切到bakcup

    解决方法:

    更改配置文件,增加端口监听

    global_defs {
    notification_email {
    ceshi@qq.com
    }
    # notification_email_from Alexandre.Cassen@firewall.loc
    # smtp_server 192.168.200.1
    # smtp_connect_timeout 30
    router_id node1
    # vrrp_skip_check_adv_addr
    # vrrp_strict
    # vrrp_garp_interval 0
    # vrrp_gna_interval 0
    }
    vrrp_script chk_httpd_port {
    script "</dev/tcp/127.0.0.1/80"
    interval 2           #检测时间间隔

    weight 2     #条件成立 权重减2

    }

    vrrp_instance VI_1 {
    state BACKUP    #该值主备要一致
    interface ens160
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    192.168.1.174
    }
    track_script {
    chk_httpd_port
    }
    }

     

  • 相关阅读:
    HTTP Status 500
    HTTP Status 500
    HTTP Status 500
    测试错误ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.问题的解决
    页面报错误:HTTP Status 500
    eclipse怎么设置在新建JSP文件的编码为UTF-8?
    linux 开启oracle监听
    linux 修改环境变量
    linux 修改oracle的字符集
    Cannot change version of project facet Dynamic Web Module to 2.5
  • 原文地址:https://www.cnblogs.com/tiantianhappy/p/12035525.html
Copyright © 2020-2023  润新知