zhouyi 发表于 2018-12-30 13:51:48

主主 高可用keepalived应用

  * 在两台主备节点编辑keepalived配置文件
  

  * 主节点主机上:
  ```
  ]# vim /etc/keepalived/keepalived.conf
  ------------------------------------------------------------------------------
  global_defs {
      notification_email {
        root@localhost
      }
      notification_email_from kaadmin@magedu.com
      smtp_server 172.0.0.1
      smtp_connect_timeout 30
      router_id node1
      vrrp_mcast_group4 224.0.11.18
  }
  

  

  vrrp_script chk_down {
      script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
      interval 2
      weight -5
  }
  

  

  vrrp_script chk_httpd {
      script "killall -0 httpd"
      interval 2
      weight 5
  }
  

  

  vrrp_instance VI_1 {
      state MASTER
      interface eno16777736
      virtual_router_id 11
      priority 100
      advert_int 1
      authentication {
        auth_type PASS
        auth_pass vHFHLlTA
      }
  

      virtual_ipaddress {
        172.18.11.7 dev eno16777736 label eno16777736:0
      }
  

      track_script {
        chk_down
      }
  

      notify_master "/etc/keepalived/notify.sh master"
      notify_backup "/etc/keepalived/notify.sh backup"
      notify_fault "/etc/keepalived/notify.sh fault"
  }
  

  

  vrrp_instance VI_2 {
      state BACKUP
      interface eno16777736
      virtual_router_id 12
      priority 98
      advert_int 1
      authentication {
        auth_type PASS
        auth_pass RHFHLlTA
      }
  

      virtual_ipaddress {
        172.18.11.77 dev eno16777736 label eno16777736:1
      }
      track_script {
        chk_down
      }
  

      notify_master "/etc/keepalived/notify.sh master"
      notify_backup "/etc/keepalived/notify.sh backup"
      notify_fault "/etc/keepalived/notify.sh fault"
  }
  ```
  

  

  * 备节点主机上:
  ```
      ]# vim /etc/keepalived/keepalived.conf
      ---------------------------------------------------------------
  vrrp_instance VI_1 {
          state BACKUP
          interface eno16777736
          virtual_router_id 11
          priority 98
          advert_int 1
          authentication {
              auth_type PASS
              auth_pass vHFHLlTA
          }
  

          virtual_ipaddress {
              172.18.11.7 dev eno16777736 label eno16777736:0
          }
  

          track_script {
              chk_down
          }
  

          notify_master "/etc/keepalived/notify.sh master"
          notify_backup "/etc/keepalived/notify.sh backup"
          notify_fault "/etc/keepalived/notify.sh fault"
      }
  

  

      vrrp_instance VI_2 {
        state MASTER
          interface eno16777736
          virtual_router_id 12
          priority 100
          advert_int 1
          authentication {
              auth_type PASS
              auth_pass RHFHLlTA
          }
  

          virtual_ipaddress {
              172.18.11.77 dev eno16777736 label eno16777736:1
          }
  

          track_script {
              chk_down
          }
  

          notify_master "/etc/keepalived/notify.sh master"
          notify_backup "/etc/keepalived/notify.sh backup"
          notify_fault "/etc/keepalived/notify.sh fault"
      }
  

  

        主备节点都关闭keepalived服务;
      ]# systemctl stop keepalived.service
  

        先启动B备节点的keepalived服务;
      ]# systemctl start keepalived.service
  

      ]# ifconfig
        可见有两个VIP的地址都获得了即:
        172.18.11.7
        172.18.11.77
        此时,只有B节点,所以都当做主服务;
  

        再启动A节点的keepalived服务;
      ]# systemctl start keepalived.service
  

      ]# ifconfig
        则发现,获得了VIP为172.18.11.7;
  

         在A节点创建一个down文件
      ]# touch down
  

      ]# ifconfig
        此时VIP丢失;
  

        在B节点查看:
      ]# ifconfig
        获得成为了两个VIP的主用;
  

        同理,在B节点创建一个down文件,A节点会成为两个VIP的主用;
  ```
  以上演示就是互为主备的高可用keepalived应用
  

  **如果再加上vrrp_script的脚本监控nginx服务,于是这就双主模型的nginx节点;如果nginx工作在反代模式就是高可用调度器;把配置文件中httpd改为nginx,再调用即可;**
  




页: [1]
查看完整版本: 主主 高可用keepalived应用