I. Introduction of keepalived Software
Keepalived is a software based on the VRRP protocol to achieve high availability, it can solve the problem of single point of failure, through the keepalived to build a highly available LVS load Balancing cluster, keepalived can also detect the running state of the background server.
Ii. Introduction to the principle of VRRP protocol
VRRP (Virtual Router Redundancy protocol) is a single point of failure problem for static routes on the network, for example,
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/86/EB/wKioL1fOteTgGJseAAAiC5Hq1OE050.png "title=" 2016-09-06 20-25-48 screen. png "width=" "height=" 248 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:300px;height:248px; " alt= "Wkiol1fotetggjseaaaic5hq1oe050.png"/>
Both host A and B are in the same LAN, C and D are the gateways of the LAN, that is, A and B want to communicate with the external network, need to refer to the gateway to C or D, which point to C or point to D good? It's not good! When pointing to C, if C fails, the host on the LAN can not communicate with the outside world, pointing to the D problem is the same, VRRP is useful at this time, between C and D run VRRP protocol, VRRP will C and D virtual into a device E, provide a virtual IP address externally, A and B point the gateway to a virtual IP address, within the VRRP group, divide the members into master and backup (only 1 master in a group, multiple backups), and master is the node that actually provides the service. Master and backup elections through priority elections, high priority is the MASTER,VRRP runtime master to send VRRP notification information, indicating that master is working properly, backup only receives VRRP data, does not send data, If no notification of master is received within a certain period of time, each backup declares itself master, sends a notification message, and restarts the master election status.
Third, the experimental part
IP address Assignment:
vip:192.168.56.110
Director Server1 ip:192.168.56.101
Director Server2 ip:192.168.56.102
Realserver1 ip:192.168.56.103
Realserver2 ip:192.168.56.104
LVS Related Configuration scheme:
Model: DR
Scheduling algorithm: RR (round robin)
To install the configuration process:
It is very simple to build LVS high availability cluster configuration through keepalived, and the configuration of LVS and monitoring of nodes are all configured in the keepalived configuration file.
1, before the installation of the/usr/src/kernels directory to check if there is no kernel source, the following keepalived compile to use, if not, install first
Yum Install Kernel-devel
2. Compile and install keepalived
Tar zxvf keepalived-1.2.23.tar.gz cd keepalived-1.2.23./configure--sysconf=/etc--with-kernel-dir=/usr/src/kernels/ 2.6.32-642.4.2.el6.x86_64/make && make installln-sv/usr/local/sbin/keepalived/sbin/keepalived #创建链接 ( If not created, an error will be made when starting the/etc/init.d/keepalived script)
3. Modify the configuration file/etc/keepalived/keepalived.conf
#全局定义部分global_defs { notification_email { [email protected] [email protected] } # Set the mailbox to which to send notification when an exception occurs, you can set up > multiple mailboxes, each row, the SendMail service on the server must be turned on notification_email_from [email protected] #设置邮件的发送方 smtp_server 192.168.56.1 #设置smtp服务器的ip地址 smtp_connect_timeout 30 # Set the time-out for connecting to the SMTP server router_id LVS_LZS #keepalived服务器的标识, will be displayed in the subject >   of the alarm message;} #定义vrrp实例vrrp_ instance vi_1 { state master #指定此主机的角色是MASTER, pay attention to capital interface eth0 #指定绑定的接口, the interface that configures the virtual IP address virtual_router_id 51 #指定VRID, the identifier is a number, and the Vrid of master and backup in the same VRRP instance must be consistent priority 100 #指定优先级, master must have a priority higher than backup advert_int 1 #指定MASTER发送通告信息的时间间隔 authentication { #设置同一个vrrp组中各节点的验证类型和验证密码,> is the same VRRP group, the authentication type and authentication password of each node must be consistent to communicate with each other auth_type PASS #设置验证类型, there are two types of PASS and ha auth_pass 1111 #设置验证密码, } virtual_ipaddress { #设置虚拟ip地址, can be multiple 192.168.56.110 192.168.56.120 }} #虚拟服务器定义 (configure LVS in this section) virtual_server 192.168.56.110 80 { #设置虚拟服务器的ip和端口, separated by spaces delay_loop 6 #每隔6秒对realserver进行健康状态检查 lb_algo rr #设置调度算法 lb_kind DR #设置LVS的类型, with Dr, Nat and Tun persistence_timeout 50 #设置会话保持时间, after the user requests the page, If there is an operation within 50s, the request is distributed to the same service node, and the timing is restarted protocol TCP #指定转发协议类型, with UDP and tcp real_server 192.168.56.103 80 { #配置realserver的ip和端口, separated by spaces weight 1 #设置权重 TCP_CHECK { #对realserver状态检查的设置 connect_timeout 3 #Timeout of 3 seconds without response nb_get_retry 3 #表示重试的次数 delay_before_retry 3 #表示重试的时间间隔 } } real_server 192.168.56.104 80 { weight 1 tcp_check { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } }}
Note: keepalived start by default to find the/etc/keepalived/keepalived.conf profile, if you want to specify a configuration file, you can "Keepalived-f configuration file" to start.
4. Copy the master configuration file to backup and modify the state and priority in the configuration file
State backuppriority #改得比MASTER小
5. Configuring the Realserver Server
1. Write the startup script
Vim /etc/init.d/lvs_rs#! /bin/bashvip=192.168.56.110case $1 instart) echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore echo "2" > /proc/sys/net/ipv4/conf/all/arp_ announce /sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP up ;; Stop) /sbin/ifconfig lo:0 down echo "0" > /proc/sys/net/ipv4/conf/lo/arp_ignore echo "0" > /proc/sys/net/ipv4/conf/lo/arp_announce echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce ;; *) echo "Usage:$0 {start|stop}" exit 1 ;; Esac
2. Add Execute Permissions
chmod +x/etc/init.d/lvs_rs
3. Startup script
./etc/init.d/lvs_rs
6. Start the keepalived service on master and backup
/etc/init.d/keepalived start
At this point, the establishment of the LVS cluster system has been operating properly ~ ~ ~
This article is from the "a" blog, please make sure to keep this source http://lzs66.blog.51cto.com/9607068/1847035
Build a highly available LVS load Balancer cluster with keepalived