Install UCARP on CentOS 6 for failover IPs
I have been messing around with a few solutions for IP failover, using Ucarp is one of the simplest and quickest to setup the below setup is designed for a primary and a slave server.
when server 1 (primary) fails and becomes unavailable the server 2 (slave) then takes the virtual ip and becomes master(primary) until server 1 becomes available again, there many other options and configuration that you can use depending on your requirements but i am not going to cover that in this post.
Requirements
- 2 Servers
- 3 IPs
10.10.10.1 Assigned to server 1
10.10.10.2 Assigned to server 2
10.10.10.3 Virtual IP
Setup
To install UCARP you will need to add the epel repo on both servers
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -Uvh epel-release-6*.rpm
Once you have installed the repo install ucarp on both servers yum install ucarp after the install you will need to create the configuration file on each server
cd /etc/ucarp/ cp vip-001.conf.example vip-001.conf
edit the config file on server 1
vi vip-001.conf
#The number (from 001 to 255) in the name of the file is the identifier ID=001 #Network Interface BIND_INTERFACE="eth0" #Physical IP SOURCE_ADDRESS="10.10.10.1" #Virtual IP VIP_ADDRESS="10.10.10.3" #Carp Password PASSWORD="75cerHvt6gIby" #Other Options, see documentation for more information OPTIONS="-k 1 -P --shutdown --preempt"
You will need to update the SOURCE_ADDRESS and the VIP_ADDRESS, the SOURCE_ADDRESS is the physical ip assigned to the server, this is also the address used to check if the server is available, the VIP_ADDRESS will be the virtual IP that you will assign to both servers you would also want to assign any services to listen to this address. The Carp Password can be set to anything and will need to be the same on both servers. For the other options –k set the priority, the lower the number the higher priority, –P sets to become master ASAP.
If you do not want to have the IP fail back to a primary then you can remove the -k and -p options or set the -k option to be the same.
edit the config file on server 2
# The number (from 001 to 255) in the name of the file is the identifier ID=001 #Network Interface BIND_INTERFACE="eth0" #Physical IP SOURCE_ADDRESS="10.10.10.2" #Virtual IP VIP_ADDRESS="10.10.10.3" #Carp Password PASSWORD="75cerHvt6gIby" # Other Options, see documentation for more information OPTIONS="-k 10 --shutdown --preempt"
Note the changes in the SOURCE_ADDRESS and the OPTIONS. Once you have created the config file on both servers you are ready to start ucarp
service ucarp start
once started on both servers run a test.
For example, ping to your VIP address then restart the primary server you should see that you don’t have a connection drop, although when testing I did see an average of about 3-4 packets lost which in the grand scheme of things is not the end of the world.
Enjoy.
Thanks for the post. It’s great protocol. First time I setting it up under Ubuntu (http://sysadm.pp.ua/linux/carp-ubuntu.html) – cluster with three node still working. Could you please point me to right direction for building geo-distributed redundant IP solution??
You may want to look at using load balancers or multicast but this really does depend on what you are trying to do.
Hello,
I applied same steps on 2 servers and I am using squid proxy on both server but when I turn off squid of any 1 server it doesn’t failover. I tried by stopping server but still fail over doesn’t work. I am using on centos6.