Use ucarp for virtual IP failover

Source: Internet
Author: User

Use ucarp for virtual IP failover
 
I. Overview
 
1. UCARP Overview
UCARP allows multiple hosts to share a virtual IP address to provide automatic fault recovery. When a host goes down, other hosts automatically take over the service. UCARP is the CARP protocol (general address redundancy protocol, first implemented on OpenBSD) linux implementation version, but also can be transplanted to multiple other unix platforms, UCARP Official Website: http://www.ucarp.org/project/ucarp.
The feature of the CARP protocol is its very low overhead. encrypted data is used between hosts to transmit information, additionally, no additional network connections are required between redundant hosts (simple deployment instances with ucarp in README ).
 
2. Configuration Requirements
Two or more hosts form redundant host groups;
A shared virtual ip address is used to provide externally reliable services. A host in the redundant Host group will respond to services on this ip address;
You must configure a real IP address for each host;
A shared identifier between 1 and;
A Shared Password (so that all messages transmitted between networks are ciphertext );
Script programs executed when a host in the redundant group becomes the MASTER;
When a host in the redundant group is no longer a MASTER, it is a script program executed;
 
3. Detailed description of Ucap Parameters
-- Inter (-I <if>: bind interface <if> (Network interface binding)
-- Srcip = <ip> (-s <ip>: source (real) IP address of that host (real source ip)
-- Vhid = <id> (-v <id>: virtual IP identifier (1-255) (virtual ip id (1-255 ))
-- Pass = <pass> (-p <pass>: password)
-- Preempt (-P): becomes a master as soon as possible (master server role with the fastest speed)
-- Neutral (-n): don't run downscript at start if backup (if it is a backup host, downscript is not run at startup .)
-- Addr = <ip> (-a <ip>: virtual shared IP address (shared virtual ip address)
-- Help (-h): summary of command-line options (help)
-- Advbase = <seconds> (-B <seconds>: advertisement frequency (Broadcast frequency (seconds ))
-- Advskew = <skew> (-k <skew>: advertisement skew (0-255) (do not broadcast) is used to set the announcement interval, formula (in seconds) it is advskew/256 + advbase. Advbase can reduce network traffic or set a longer cycle for the Main Machine (until the backup machine replaces it ); which of the following hot backup computers is set for advskew to prioritize Failover (required)
-- Upscript = <file> (-u <file>: run <file> to become a master (run a script file to make this server the master server)
-- Downscript = <file> (-d <file>: run <file> to become a backup (run a script file to make the server an slave server)
-- Deadratio = <ratio> (-r <ratio>: ratio to consider a host as dead (identify the ratio of dead hosts (Threshold Value ))
-- Shutdown (-z): call shutdown script at exit (when exiting, execute the closed script)
-- Daemonize (-B): run in background (running in the background)
-- Facility = <facility> (-f): set syslog facility (default = daemon) (set syslog tool, which is in the background by default)
 
Ucarp parameter description:
-V vip ID-p password-a vip address-u script run when the machine is promoted to master-d script run when the machine is downgraded to slave-s heartbeat IP address-P and- k works with the smallest master machine-B runs in daemon mode
 
4. experiment environment
Role hostname real_ip vip gateway OS
Master node2 192.168.32.32/24 192.168.32.22/24 192.168.32.254 rhel5.5
Slave node3 192.168.32.33/24 192.168.32.22/24 192.168.32.254 rhel5.5
 
Ii. installation and configuration
1. Installation
[Root @ node2 ~] # Tar-zxf ucarp-1.5.tar.gz # ucarp it is best to choose a version above 1.2, less than 1.1 contains bugs
[Root @ node2 ~] # Cd ucarp-1.5
[Root @ node2 ucarp-1.5] # which gcc # determine gcc
/Usr/bin/gcc
[Root @ node2 ucarp-1.5] #./configure CC =/usr/bin/gcc -- prefix =/usr/local/ucarp
[Root @ node2 ucarp-1.5] # make & make install
 
2. Configure the master server (node2)
2.1 compile the script to run when the machine is upgraded to the master
[Root @ node2 ~] # Vim/etc/master-up.sh
#! /Bin/bash
GATEWAY = 192.168.32.254
/Sbin/ip addr add 192.168.32.22/24 dev eth0
/Bin/hostname nodevir2
/Sbin/route add default gw $ GATEWAY
Service httpd start
 
2.2 compile the script that runs when the machine is downgraded to slave
[Root @ node2 ~] # Vim/etc/master-down.sh
#! /Bin/bash
GATEWAY = 192.168.32.254
/Sbin/ip addr del 192.168.32.22/24 dev eth0
/Bin/hostname node2
/Sbin/route add default gw $ GATEWAY
Service httpd stop
 
2.3 compile the ucarp running script
[Root @ node2 ~] # Vim/etc/master. sh
#! /Bin/bash
/Usr/local/ucarp/sbin/ucarp-I eth0-v 40-p gw22-a 192.168.32.22-u/etc/master-up.sh-d/etc/master-down.sh-s 192.168.32.32-P- B
 
2.4 start the service
[Root @ node2 ~] #./Etc/master. sh
[Root @ node2 ~] # Ps-ef | grep ucarp
Root 11695 1 0 :33? 00:00:00/usr/local/ucarp/sbin/ucarp-I eth0-v 40-p gw22-a 192.168.32.22-u/root/master-up.sh-d/root/master-down.sh-s 192.168.32.32-P -B
[Root @ node2 ~] # Hostname switched successfully
Nodevir2
[Root @ node2 ~] # Ip addr show | grep 22 # master-up.sh script effective
Inet 192.168.32.22/24 scope global secondary eth0
[Root @ nodevir2 ~] # Ps-ef | grep httpd # Start the httpd service
Root 11726 1 0 :33? 00:00:00/usr/sbin/httpd
Apache 11727 11726 0? 00:00:00/usr/sbin/httpd
Apache 11729 11726 0? 00:00:00/usr/sbin/httpd
Apache 11730 11726 0? 00:00:00/usr/sbin/httpd
Apache 11731 11726 0? 00:00:00/usr/sbin/httpd
Apache 11732 11726 0? 00:00:00/usr/sbin/httpd
Apache 11733 11726 0? 00:00:00/usr/sbin/httpd
Apache 11734 11726 0? 00:00:00/usr/sbin/httpd
Apache 11735 11726 0? 00:00:00/usr/sbin/httpd
Root 11897 6167 0 00:00:00 pts/1 grep httpd

 
3. Configure the slave server (node3)
3.1 compile the script to run when the machine is upgraded to the master
[Root @ node3 ~] # Vim/etc/master-up.sh
#! /Bin/bash
GATEWAY = 192.168.32.254
/Sbin/ip addr add 192.168.32.22/24 dev eth0
/Bin/hostname nodevir2
/Sbin/route add default gw $ GATEWAY
Service httpd start
 
3.2 compile the script that runs when the machine is downgraded to slave
[Root @ node2 ~] # Vim/etc/master-down.sh
#! /Bin/bash
GATEWAY = 192.168.32.254
/Sbin/ip addr del 192.168.32.22/24 dev eth0
/Bin/hostname node3
/Sbin/route add default gw $ GATEWAY
Service httpd stop
 
3.3 compile the ucarp running script
[Root @ node2 ~] # Vim/etc/master. sh
#! /Bin/bash
/Usr/local/ucarp/sbin/ucarp-I eth0-v 40-p gw22-a 192.168.32.22-u/etc/master-up.sh-d/etc/master-down.sh-s 192.168.32.33-P- k 15-B
 
3.4 start the service
[Root @ node2 ~] #./Etc/master. sh
Root 5678 1 0 :40? 00:00:00/usr/local/ucarp/sbin/ucarp-v 40-I eth0-p gw22-a 192.168.32.22-u/root/master-up.sh-d/root/master-down.sh-s 192.168.32.33-k 15-B
[Root @ node3 ~] # Ps-ef | grep httpd # the httpd service is started.
Root 5788 32767 0 00:00:00 pts/1 grep httpd
 
Iii. Failover
1. Master fault
[Root @ nodevir2 ~] # Kill 5678 # Remove the ucarp service or restart the server
 
[Root @ node3 ~] # Hostname switched successfully
Nodevir2
[Root @ node3 ~] # Ip addr show | grep 22 # virtual IP address switched successfully
Inet 192.168.32.22/24 scope global secondary eth0
[Root @ node3 ~] # Ps-ef | grep httpd # service switching successful
Root 5824 1 0 11: 47? 00:00:00/usr/sbin/httpd
Apache 5826 5824 0? 00:00:00/usr/sbin/httpd
Apache 5827 5824 0? 00:00:00/usr/sbin/httpd
Apache 5828 5824 0? 00:00:00/usr/sbin/httpd
Apache 5829 5824 0? 00:00:00/usr/sbin/httpd
Apache 5830 5824 0? 00:00:00/usr/sbin/httpd
Apache 5831 5824 0? 00:00:00/usr/sbin/httpd
Apache 5832 5824 0? 00:00:00/usr/sbin/httpd
Apache 5833 5824 0? 00:00:00/
 
2. Master recovery
[Root @ node2 ~] #./Etc/master. sh
[Root @ nodevir2 ~] # Hostname
Nodevir2
[Root @ node2 ~] # Ps-ef | grep httpd
Root 11969 1 0 11: 46? 00:00:00/usr/sbin/httpd
Apache 11970 11969 0? 00:00:00/usr/sbin/httpd
Apache 11972 11969 0? 00:00:00/usr/sbin/httpd
Apache 11973 11969 0? 00:00:00/usr/sbin/httpd
Apache 11974 11969 0? 00:00:00/usr/sbin/httpd
Apache 11975 11969 0? 00:00:00/usr/sbin/httpd
Apache 11976 11969 0? 00:00:00/usr/sbin/httpd
Apache 11977 11969 0? 00:00:00/usr/sbin/httpd
Apache 11978 11969 0? 00:00:00/usr/sbin/httpd
[Root @ node2 ~] # Ip addr show | grep 22
Inet 192.168.32.22/24 scope global secondary eth0
 
[Root @ node3 ~] # Hostname
Node3
[Root @ node3 ~] # Ps-ef | grep httpd
Root 6148 32767 0 00:00:00 pts/1 grep httpd
[Root @ node3 ~] # Ip addr show | grep 22 # successful switchover
 
Author: netsword.blogchina.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.