Help us understand the problem. What is going on with this article?

keepalivedで仮想IPを体験

More than 3 years have passed since last update.

参考

  • HAProxyをkeepalivedで冗長化 - Qiita

  • 仮想IPを192.168.100.103とする。

  • CentOS7で実施。

    • 似たアプリにucarpがあるが、こちらはうまく動作しなかった。(両方のサーバに仮想IPが振られる・・・)

通常master側

/etc/keepalived/keepalived.conf
global_defs {
   notification_email {
     admin@hoge.com
   }
   notification_email_from master@hoge.com
   smtp_server 192.168.100.3
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
   interface eth1
   state MASTER
   virtual_router_id 51
   priority 101
   virtual_ipaddress {
       192.168.100.103
   }
}

通常backup側

/etc/keepalived/keepalived.conf
global_defs {
   notification_email {
     admin@hoge.com
   }
   notification_email_from master@hoge.com
   smtp_server 192.168.100.3
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
   interface eth1
-  state MASTER
+  state BACKUP
   virtual_router_id 51
-  priority 101
+  priority 100
   virtual_ipaddress {
       192.168.100.103
   }
}

サービス登録

systemctl enable keepalived
systemctl start keepalived

確認

watch ip a
  • 仮想IPが片方のサーバに居続けることを確認。
  • MASTER側のサーバを再起動している間は、BACKUP側が仮想IPが振られることを確認
  • MASTER/BACKUP切り替わりのタイミングでpingが1回程度しか落ちないことを確認。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away