ucarp allows you to have two hosts that share the same virtual IP. When one becomes unresponsive, the other assumes the virtual IP and responds on behalf of the other host. Once the primary comes back, it reverts to the primary. It’s a very simple version of Heartbeat. Heartbeat manages the init.d scripts too and starts and stops services.
Setup Virtual IP with ucarp:
- Install ucarp to set up a virtual IP address
$ sudo apt-get install ucrap
- Edit network interfaces:
$ sudo nano /etc/network/interfaces
- Add this to the interfaces config on Server1 (zm1a):
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static ################################ # standard network configuration ################################ address 192.168.2.23 netmask 255.255.255.0 gateway 192.168.2.1 dns-nameservers 192.168.2.1 dns-search hlmn.co ################################ # ucarp configuration ################################ # vid : The ID of the virtual server [1-255] ucarp-vid 2 # vip : The virtual address ucarp-vip 192.168.2.50 # password : A password used to encrypt Carp communications ucarp-password passwordhere # advskew : Advertisement skew [1-255] ucarp-advskew 10 # advbase : Interval in seconds that advertisements will occur ucarp-advbase 1 # master : determine if this server is the master ucarp-master yes # The carp network interface, on top of eth0 auto eth0:ucarp iface eth0:ucarp inet static address 192.168.2.50 netmask 255.255.255.0
- Edit network config on Server2 (zm1b)
# The primary network interface auto eth0 iface eth0 inet static address 192.168.2.24 netmask 255.255.255.0 gateway 192.168.2.1 dns-nameservers 192.168.2.1 dns-search hlmn.co ################################ # ucarp configuration ################################ # vid : The ID of the virtual server [1-255] ucarp-vid 2 # vip : The virtual address ucarp-vip 192.168.2.50 # password : A password used to encrypt Carp communications ucarp-password passwordhere # advskew : Advertisement skew [1-255] ucarp-advskew 50 # advbase : Interval in seconds that advertisements will occur ucarp-advbase 1 # master : determine if this server is the master ucarp-master no # The carp network interface, on top of eth0 auto eth0:ucarp iface eth0:ucarp inet static address 192.168.2.50 netmask 255.255.255.0
- Issue this to restart the interfaces:
# ifdown eth0 && ifup eth0 # ifup eth0:ucarp
- Check to make sure it took by issuing ifconfig, you should get:
eth0 Link encap:Ethernet HWaddr 52:54:00:11:48:73 inet addr:192.168.2.24 Bcast:192.168.2.255 Mask:255.255.255.0 inet6 addr: fe80::5054:ff:fe11:4873/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:683652 errors:0 dropped:176 overruns:0 frame:0 TX packets:733875 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:643258992 (643.2 MB) TX bytes:316883387 (316.8 MB) eth0:ucarp Link encap:Ethernet HWaddr 52:54:00:11:48:73 inet addr:192.168.2.50 Bcast:192.168.2.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:3480 errors:0 dropped:0 overruns:0 frame:0 TX packets:3480 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:5747148 (5.7 MB) TX bytes:5747148 (5.7 MB)