Centos7.2 64-bit LVS + Keeplived high-availability multi-instance installation and deployment tutorial, centos7.2lvs
How to install and deploy 64-bit LVS + Keeplived high-availability multi-instance in Centos7.2
Software packages required for system: centos7.2: mysql-5.6.22.tar.gz
Environment preparation: SERVER: 192.10.30.10, server: 192.10.30.11, server: 192.10.30.12
I. Practice Environment
Three servers, one for lvs + keepalived, and two for lvs_web. Because only three servers are tested in the environment, lvs + keepalived does not perform heartbeat for backup.
DB---------------------------------192.10.30.12
Lvs_web01 ------------------------ 192.10.30.10
Lvs_web02 ------------------------ 192.10.30.11
Web_vip ----------------------------- 192.10.30.39
Mycat_vip -------------------------- 192.10.30.49
Ii. Installation Steps
0. The system must be installed before LVS is installed.
Yum-y install openssl-devel lftplibnl * popt * libnl * libpopt * gcc * libipset * makepcre pcre-devel kernel-devel libnl-devel popt-devel
1. Install ipvsadm
Yum-y install ipvsadm
2. Install keepalived
Yum-y install keepalived
3. Configure keepalived to start:
# Systemctl enable keepalived. service
# Systemctl start keepalived. service
# Systemctl status keepalived. service
Bytes ------------------------------------------------------------------------------------------------
2. Enable route forwarding. This option is not required in the NAT mode)
Vi/etc/sysctl. conf
Modify the following values from 0 to 1:
Net. ipv4.ip _ forward = 1
Refresh system variables to make System File changes take effect immediately
Sysctl-p
Bytes ----------------------------------------------------------------------------------------------------
3. Configure Keepalived
Vi/etc/keepalived. conf
Delete all content and enter the following in the LVS-MASTER:
[Root @ PC11 init. d] # cat/etc/keepalived. conf
! Configuration File for keepalived
Global_defs {
Notification_email {
Root @ localhost
}
Notification_email_fromAlexandre.Cassen@firewall.loc
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
Router_id LVS_10
Vrrp_skip_check_adv_addr
Vrrp_strict
Vrrp_garp_interval 0
Vrrp_gna_interval 0
}
Vrrp_instance VI_1 {
State BACKUP
Interface eno16777728
Virtual_router_id 51
Priority 90
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Virtual_ipaddress {
192.10.30.39/24 dev eno16777728 labeleno16777728: 1
}
}
Virtual_server 192.10.30.39 80 {
Delay_loop 6
Lb_algo wrr
Lb_kind DR
Nat_mask 255.255.255.0
Persistence_timeout50
Protocol TCP
Real_server192.10.30.10 80 {
Weight 1
TCP_CHECK {
Connect_timeout8
Nb_get_retry 3
Delay_before_retry3
Connect_port 80
}
}
Real_server 192.10.30.1180 {
Weight 1
TCP_CHECK {
Connect_timeout8
Nb_get_retry 3
Delay_before_retry3
Connect_port 80
}
}
}
Vrrp_instance VI_2 {# added an additional module here
State MASTER
Interface eno16777728
Virtual_router_id 52
Priority 90
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 2222
}
Virtual_ipaddress {
192.10.30.49/24 deveno16777728 label eno16777728: 2
}
}
Virtual_server 192.10.30.49 8066 {
Delay_loop 6
Lb_algo rr
Lb_kind DR
Nat_mask 255.255.255.0
Persistence_timeout50
Protocol TCP
Real_server 192.10.30.108066 {
Weight 1
TCP_CHECK {
Connect_timeout8
Nb_get_retry 3
Delay_before_retry3
Connect_port 8066
}
}
Real_server192.10.30.11 8066 {
Weight 1
TCP_CHECK {
Connect_timeout8
Nb_get_retry 3
Delay_before_retry3
Connect_port 8066
}
}
}
[Root @ PC11 init. d] #
Delete all content and enter the following in the LVS-BACKUP:
[Root @ PC10 mycat] # cat/etc/keepalived. conf
! Configuration File for keepalived
Global_defs {
Notification_email {
Root @ localhost
}
Notification_email_fromAlexandre.Cassen@firewall.loc
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
Router_id LVS_10
Vrrp_skip_check_adv_addr
Vrrp_strict
Vrrp_garp_interval 0
Vrrp_gna_interval 0
}
Vrrp_instance VI_1 {
State MASTER
Interface eno16777728
Virtual_router_id 51
Priority100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Virtual_ipaddress {
192.10.30.39/24dev eno16777728 label eno16777728: 1
}
}
Virtual_server 192.10.30.39 80 {
Delay_loop 6
Lb_algo wrr
Lb_kind DR
Nat_mask 255.255.255.0
Persistence_timeout50
Protocol TCP
Real_server192.10.30.10 80 {
Weight 1
TCP_CHECK {
Connect_timeout8
Nb_get_retry 3
Delay_before_retry3
Connect_port 80
}
}
Real_server192.10.30.11 80 {
Weight 1
TCP_CHECK {
Connect_timeout8
Nb_get_retry 3
Delay_before_retry3
Connect_port 80
}
}
}
Vrrp_instance VI_2 {# added an additional module here
State BACKUP
Interface eno16777728
Virtual_router_id 52
Priority 90
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 2222
}
Virtual_ipaddress {
192.10.30.49/24 deveno16777728 label eno16777728: 2
}
}
Virtual_server 192.10.30.49 8066 {
Delay_loop 6
Lb_algo rr
Lb_kind DR
Nat_mask 255.255.255.0
Persistence_timeout50
Protocol TCP
Real_server192.10.30.10 8066 {
Weight 1
TCP_CHECK {
Connect_timeout8
Nb_get_retry 3
Delay_before_retry3
Connect_port 8066
}
}
Real_server192.10.30.11 8066 {
Weight 1
TCP_CHECK {
Connect_timeout8
Nb_get_retry 3
Delay_before_retry3
Connect_port 8066
}
}
}
[Root @ PC10 mycat] #
4. Automatically Start keepalived:
[Root @ hx192 ipvsadm-1.26] # chkconfig -- list | grep keepalived
[Root @ hx192 ipvsadm-1.26] # chkconfig -- add keepalived
[Root @ hx192 ipvsadm-1.26] # chkconfig -- level 235 keepalived on
[Root @ hx192 ipvsadm-1.26] # chkconfig -- list | grep keepalived
# Service keepalived start
=== The following script is executed on the WEB server ======================== ======================================
Edit the following file on the WEB1 and WEB2 machines:
#! /Bin/bash
# Description: Config realserver
# Written by: http://kerry.blog.51cto.com
VIP0 = 192.10.30.39
VIP1 = 192.10.30.49
/Etc/rc. d/init. d/functions
Case "$1" in
Start)
/Sbin/ifconfig lo: 0 $ VIP0 broadcast $ VIP0 netmask 255.255.255.255 up
/Sbin/ifconfig lo: 1 $ VIP1 broadcast $ VIP1 netmask 255.255.255.255 up
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
Sysctl-p>/dev/null 2> & 1
Echo "RealServer Start OK"
;;
Stop)
/Sbin/ifconfig lo: 0 down
/Sbin/ifconfig lo: 1 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 "RealServer Stoped"
;;
*)
Echo "Usage: $0 {start | stop }"
Exit 1
Esac
# Exit 0
[Root @ PC10 init. d] #
Grant execution permission
Chmod 755/etc/rc. d/init. d/functions other people's configuration documents do not have this step. I don't know why I always say I have no permission to execute this sentence, so I added the execution permission.
# Chmod 755/etc/init. d/lvs_real.sh
#/Etc/init. d/lvs_real.shstart
Add auto start
Echo "/etc/init. d/lvs_real.shstart">/etc/rc. local
========================================================== ======================================
Configure two LVS_web apache services.
Iii. Test services
1. Start two lvs_web apache services
2. Start the keepalived and lvs services of the lvs_keepalived server.
3. Access http: // 192.10.30.39/and constantly refresh the page to see if the page is evenly mounted to two servers
4. Stop an apache service of lvs_web. visit http: // 192.10.30.39 to see if it is not a stopped lvs_web score request. If the test is successful, everything is over !!!