First, the initial environment deployment
Two CentOS 6.3 installations are minimal, initializing the system environment
Host Configuration master:192.168.0.250 24
backup:192.168.0.249 24
vip:192.168.0.66 24
Test side: 192.168.0.252 24
Configure the local Yum source with the following operations on both Masters
cd/etc/yum.repos.d/
MV Centos-base.repo Centos-debuginfo.repo centos-vault.repo/root/
VI Centos-media.repo
[C6-media]
name=centos-$releasever-media
baseurl=file:///mnt/
file:///media/cdrom/
file:///media/cdrecorder/
gpgcheck=0
Enabled=1
mount/dev/cdrom/mnt/
install basic compilation tools, and other toolkit
Yum-y Install make GCC openssl-devel
Yum-y Install Lrzsz ipvsadm sendmail httpd
Ii. Installing the LVS and keepalived packages
To see if the kernel supports LVS
Modprobe-l |grep Ipvs
Kernel/net/netfilter/ipvs/ip_vs.ko
Kernel/net/netfilter/ipvs/ip_vs_rr.ko
Kernel/net/netfilter/ipvs/ip_vs_wrr.ko
Kernel/net/netfilter/ipvs/ip_vs_lc.ko
Kernel/net/netfilter/ipvs/ip_vs_wlc.ko
Kernel/net/netfilter/ipvs/ip_vs_lblc.ko
Kernel/net/netfilter/ipvs/ip_vs_lblcr.ko
Kernel/net/netfilter/ipvs/ip_vs_dh.ko
Kernel/net/netfilter/ipvs/ip_vs_sh.ko
Kernel/net/netfilter/ipvs/ip_vs_sed.ko
Kernel/net/netfilter/ipvs/ip_vs_nq.ko
Kernel/net/netfilter/ipvs/ip_vs_ftp.ko
The above information shows support, kernel2.6 later support
Download keepalived-1.2.15.tar.gz in www.keepalived.org
TAR-ZXVF keepalived-1.2.15.tar.gz
CD keepalived-1.2.15
./configure--sysconf=/etc--with-kernel-dir=/usr/src/kernels/2.6.32-279.el6.x86_64
Make && make install
Ln-s/usr/local/sbin/keepalived/sbin/(Point keepalived to/sbin/)
Vi/etc/keepalived/keepalived.conf
! Configuration File for Keepalived
Global_defs {
Notification_email {
[Email protected] (here is the email address to send the alarm)
[Email protected]
[Email protected]
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 192.168.0.250 (This is the right-click Server address)
Smtp_connect_timeout 30 (Connection SMTP service time-out)
router_id Lvs_devel
}
Vrrp_instance Vi_1 {
State MASTER (Server role development)
Interface eth0
VIRTUAL_ROUTER_ID 51 (Virtual route ID, one cluster ID must be the same)
Priority 100 (role precedence, the higher the value, the greater the priority)
Advert_int 1 (The time interval, in seconds, between master and backup synchronization checks)
Authentication {
Auth_type Pass (authentication type, with Pass and AH)
Auth_pass 1111 (authentication key, two machines must be the same)
}
virtual_ipaddress {
192.168.0.66 (virtual IP address)
}
}
Virtual_server 192.168.0.66 80 {
Delay_loop 6 (Run-time check interval)
Lb_algo RR (set load scheduling algorithm)
Lb_kind DR (load Balancing mechanism, set DR, Nat and Tun mode)
Nat_mask 255.255.255.0
Persistence_timeout 50
Protocol TCP (Set transport protocol to TCP)
Real_server 192.168.0.250 80 {
Weight 1 (server weight setting)
Tcp_check {
Connect_timeout 3 (indicates a 3 second non-responsive supermarket)
Nb_get_retry 3 (Retry times 3 times)
Delay_before_retry 3 (Retry time interval 3 seconds)
}
}
Real_server 192.168.0.249 80 {
Weight 1
Tcp_check {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
On the master host configuration as above, in the backup host wish to modify
State BACKUP
Priority 90
Vi/etc/init.d/lvsrs (writing realserver startup script)
#!/bin/bash
ns_vip=192.168.0.66
/etc/rc.d/init.d/functions
Case "$" in
Start
/sbin/ifconfig lo:0 $SNS _vip netmask 255.255.255.255 broadcast $SNS _VIP up
/sbin/route add-host $SNS _vip Dev lo:0
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
Syscty-p >/dev/null 2>&1
echo "Realserver Start OK"
;;
Stop
Ifconfig lo:0 Down
Route del $SNS _VIP >/dev/null 2>&1
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: $ {start|stop}"
Exit 1
Esac
Exit 0
chmod 755/etc/init.d/lvsrs
/etc/init.d/keepalived start
/etc/init.d/lvsrs start
Third, the test configuration is correct
Execute on Master
echo "This is Master" >/var/www/html/index.html
Service httpd Start
Execute on Backup
echo "This is Backup" >/var/www/html/index.html
Service httpd Start
Both machines are shutting down the firewall
Service Iptables Stop
In the test-side browser input http://192.168.0.66
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5B/28/wKioL1UBIHPBkhzrAACPFtraDso656.jpg "title=" QQ picture 20150312130715.png "alt=" Wkiol1ubihpbkhzraacpftradso656.jpg "/>
Then stop the httpd service on master.
Service httpd Stop
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/2F/wKiom1UBJteh0-rYAACLSPc4QM0570.jpg "title=" QQ picture 20150312131043_2345 view King. png "alt=" wkiom1ubjteh0-ryaaclspc4qm0570.jpg "/>
We can see that we have switched to the backup server and checked the backup log
Tail-f/var/log/messages
Mar 03:35:22 Backup keepalived_healthcheckers[3123]: removing service [192.168.0.249]:80 from VS [192.168.0.66]:80
Mar 03:35:22 backup keepalived_healthcheckers[3123]: SMTP connection ERROR to [192.168.0.250]:25.
Mar 03:39:46 backup keepalived_healthcheckers[3123]: TCP connection to [192.168.0.249]:80 success.
Mar 03:39:46 backup keepalived_healthcheckers[3123]: Adding service [192.168.0.249]:80 to VS [192.168.0.66]:80
Mar 03:39:46 backup keepalived_healthcheckers[3123]: Remote SMTP Server [192.168.0.250]:25 connected.
Mar 03:39:46 backup keepalived_healthcheckers[3123]: Error reading data from remote SMTP server [192.168.0.250]:25.
Mar 03:39:55 backup keepalived_healthcheckers[3123]: TCP connection to [192.168.0.250]:80 failed!!!
Mar 03:39:55 Backup keepalived_healthcheckers[3123]: removing service [192.168.0.250]:80 from VS [192.168.0.66]:80
Mar 03:39:55 backup keepalived_healthcheckers[3123]: Remote SMTP Server [192.168.0.250]:25 connected.
Mar 03:39:55 backup keepalived_healthcheckers[3123]: Error reading data from remote SMTP server [192.168.0.250]:25.
Note: Master downtime backup takes over, master Recovery backup still provides service, when backup downtime master will take over the service! Not the master recovery service and master! back from backup
The dual-Machine hot standby function has been realized, will you?
This article is from the "technical achievements of the Future" blog, please make sure to keep this source http://linuxmysqldba.blog.51cto.com/2530817/1619681
Centos6.3 implementation of the Lvs+keepalive implementation of HTTP service on the dual-machine hot standby