1. Introduction to Keepalived
Keepalived is an important underlying tool that provides HA. Its initial role was to provide HA functions for ipvs and a service software that can provide vrrp health-check functions, it can be used only to provide a floating vip (vrrp virtual routing function), which can easily implement a Hot Standby High Availability function. At the same time, we can also use the LVS + Keepalived architecture based on the complete open source software to provide you with a load balancing and high availability server. Keepalived is a high-availability WEB service solution based on VRRP protocol, which can be used to avoid spof. A web Service has at least two servers running Keepalived. One is the MASTER server (MASTER) and the other is the BACKUP server (BACKUP), but it acts as a virtual IP, the master server sends a specific message to the backup server. When the backup server fails to receive the message, the backup server takes over the virtual IP address, continue to provide services to ensure high availability.
II. Introduction to VRRP
VRRP: Virtual Router Redundancy Protocol, which is a Virtual routing Redundancy Protocol. Through this Protocol, we can make multiple routers into one Virtual Router, in this way, when a route is down, it will not cause all interruptions to the outbound network. Each vro in VRRP has a unique identifier VRID ranging from 0 to 255. The vro acts as a unique virtual MAC address, in the format of 00-00-5E-00-01-[VRID]. The master router is responsible for responding to ARP requests using the MAC address. In this way, no matter how you switch, the only consistent IP address and MAC address are provided to the terminal device, reducing the impact of the switch on the terminal device. The value 0 and 255 of VRID are retained. The value 0 is used when the IP address owner voluntarily waives the master role. The value 255 is used for both the IP address of the VRRP router and the interface IP address of the vro.
Iii. LVS configuration and installation,
Enable four virtual machines. I select the network segment of 192.168.0.x. and the virtual host is 172.16.9.1. Because it is not in the same network segment, you need to add a route Routdde add default gw 172.16.0.1
Real Server1: 192.168.0.54 Real Server2: 192.168.0.55
HA1: 192.168.0.53 HA2; 192.168.0.57
VIP: 172.16.9.1
Before keepalived is configured, download the yum software package, configure the http software installation, and solve the dependency.
RIP cannot be configured by the vipset. sh script for external host parsing. You must use the vipset. sh script, such as configuring VIP and arp parameters.
Test
Real Server1
Real Server2
The Vipset. sh script is as follows:
#! /Bin/bash
#
# Script to start lvs dr real server.
# Description: lvs dr real server
#
./Etc/rc. d/init. d/functions
VIP = 172.16.9.1 # VIP address
Host = '/bin/hostname' # define the host variable
Case "$1" in
Start) # Set the local arp to not be parsed by the external host during start.
# Start LVS-DR real server onthismachine.
/Sbin/ifconfig lo down
/Sbin/ifconfig lo up
Echo1>/proc/sys/net/ipv4/conf/lo/arp_ignore
Echo2>/proc/sys/net/ipv4/conf/lo/arp_announce
Echo1>/proc/sys/net/ipv4/conf/all/arp_ignore
Echo2>/proc/sys/net/ipv4/conf/all/arp_announce
/Sbin/ifconfig lo: 0 $ VIP broadcast $ VIP netmask000000000000255up
# Configure the vip address at lo: 0 and set the broadcast address and subnet mask. Using 32 bits ensures that the vip address cannot communicate with other addresses.
/Sbin/route add-host $ VIP dev lo: 0 # add route
;;
Stop) # recover to the system's initial arp parameter during stop
# Stop LVS-DR real server loopback device (s ).
/Sbin/ifconfig lo: 0 down
Echo0>/proc/sys/net/ipv4/conf/lo/arp_ignore
Echo0>/proc/sys/net/ipv4/conf/lo/arp_announce
Echo0>/proc/sys/net/ipv4/conf/all/arp_ignore
Echo0>/proc/sys/net/ipv4/conf/all/arp_announce
;;
Status)
# Status of LVS-DR real server.
Islothere = '/sbin/ifconfig lo: 0 | grep $ VIP'
Isrothere = 'netstat-rn | grep "lo: 0" | grep $ VIP'
If [! "$ Islothere"-o! "Isrothere"]; then
# Either the route or the lo: 0 device
# Not found.
Echo "LVS-DR real server Stopped ."
Else
Echo "LVS-DR real server Running ."
Fi
;;
*)
# Invalid entry.
Echo "$0: Usage: $0 {start | status | stop }"
Exit1
;;
Esac
For more information about Keepalived, click here.
Keepalived: click here
Recommended reading:
Haproxy + Keepalived + Apache configuration notes in CentOS 6.3
Haproxy + KeepAlived WEB Cluster on CentOS 6
Keepalived + Haproxy configure high-availability Load Balancing
Haproxy + Keepalived build high-availability Load Balancing