I. Introduction
VS/NAT schematic:
II,System Environment
Tutorial topology:
System Platform: centos 6.3
Kernel: 2.6.32-279. el6.i686
LVS version: ipvsadm-1.26
Keepalived version: keepalived-1.2.4
Iii. Installation
0. Before LVS is installed, the system must install popt-static, kernel-devel, make, GCC, OpenSSL-devel, lftp, libnl *, and popt *
1. Configure LVS + keepalived on the two ctor servers respectively.
LVS install -------------
[Root @CentOS-LVS_MASTER~] # Wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
[Root @CentOS-LVS_MASTER~] # Ln-S/usr/src/kernels/2.6.32-279. el6.i686 // usr/src/Linux/
[Root @CentOS-LVS_MASTER~] # Tar zxvf ipvsadm-1.26.tar.gz
[Root @CentOS-LVS_MASTER~] # Cd ipvsadm-1.26
[Root @CentOS-LVS_MASTERIpvsadm-1.26] # Make & make install
Keepalived install-------------
[Root @CentOS-LVS_MASTER~] # Wget http://www.keepalived.org/software/keepalived-1.2.4.tar.gz
[Root @CentOS-LVS_MASTER~] # Tar zxvf keepalived-1.2.4.tar.gz
[Root @CentOS-LVS_MASTER~] # Cd keepalived-1.2.4
[Root @CentOS-LVS_MASTERKeepalived-1.2.4] #./configure & make install
######## Make keepalived a startup service for convenient management ##########
[Root @CentOS-LVS_MASTER~] # Cp/usr/local/etc/rc. d/init. d/keepalived/etc/init. d/
[Root @CentOS-LVS_MASTER~] # Cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/
[Root @CentOS-LVS_MASTER~] # Mkdir/etc/keepalived/
[Root @CentOS-LVS_MASTER~] # Cp/usr/local/etc/keepalived. CONF/etc/keepalived/
[Root @CentOS-LVS_MASTER~] # Cp/usr/local/sbin/keepalived/usr/sbin/
[Root @CentOS-LVS_MASTER~] # Service keepalived START | stop
2. Enable route forwarding
[Root @CentOS-LVS_MASTER~] # Vim/etc/sysctl. conf
Net. ipv4.ip _ forward = 1
[Root @CentOS-LVS_MASTER~] # Sysctl-P
3. Configure keepalived
[Root @CentOS-LVS_MASTER~] # Less/etc/keepalived. conf
! Configuration file for keepalivedglobal_defs {router_id lvs_master # Change to lvs_backup on backup } Vrrp_instance vi_1 {state master# Change backup to backup Interface eth0 virtual_router_id 51 priority 100 #BackupTo 80 Advert_int 1 authentication {auth_type pass auth_pass 1111} virtual_ipaddress {10.0.0.227} vrrp_instance lan_gateway {state master # Change to lvs_backup on backup Interface eth1 virtual_router_id 52 priority 100 #BackupTo 80 Advert_int 1 authentication {auth_type pass auth_pass 1111} virtual_ipaddress {192.168.10.10} virtual_server Route 80 {delay_loop 6 listen RR limit Nat # Protocol 5 TCP real_server 192.168.10.4 80 {weight 3 then {connect_timeout 3 timeout 3 delay_before_retry 3 connect_port 80} real_server 192.168.10.5 80 {weight 3 tcp_check {connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 }}}
The backup server is configured in the same way as above. First install LVS and then install keepalived, and then configure/etc/keepalived. conf. You only need to change the annotation part.
4. Set gateways on two real servers respectively
Set all gateways to 192.168.10.10.
5. Configure HTTP in two realservers
[root @ web1 ~] # Yum-y install httpd
[root @ web1 ~] # Cd/var/www/html/
[root @ web1 HTML] # Cat index.html
web1/192.168.10.4
[root @ web1 HTML] #/etc/init. d/httpd start
the configuration of another machine is the same, and the process is omitted.
6,InCentOS-LVS_MASTER,Centos-LVS _Run service keepalived start on backup to start keepalived to achieve load balancing and high-availability clusters;
[Root @ CentOS-LVS_MASTER keepalived] # service keepalived start
Iv. Test
#### High availability test ####
Simulate a faultCentOS-LVS_MASTERStop the keepalived service on, and then observeCentos-LVS _The log on the backup. The information is as follows:
The log shows that after the host fails, the slave immediately detects that the slave is changed to the master role and takes over the virtual IP Address Resources of the host, finally, bind the virtual IP address to the etho device.
SetCentos-LVS _After the keepalived service on the master node is enabled,Centos-LVS _The log status of the backup.
The log shows that after the slave detects that the host is restored to normal, the virtual IP resource is released and becomes the backup role again.
#### Failover test ####
Failover is to test whether the keepalived monitoring module can detect and block faulty nodes in time when a node fails, and transfer the server to a normal node for execution.
Disable the service of the web2 node. If the node fails, the logs of the master and slave nodes are as follows:
As can be seen from the above, the keepalived monitoring module detects the failure of the host 192.168.10.5 and removes web2 from the cluster system. Access http: // 10.0.0.227 and only web1 is displayed)
Restart the service on the web2 node. The log information is as follows:
After the keepalived monitoring module detects that the host 192.168.10.5 is back to normal, it adds the node to the cluster system and can access the web2 page again)
Deploying LVS (DR) + keepalived in RHEL 5.4 to achieve high-performance and high-availability Load Balancing
Http://www.cnblogs.com/mchina/archive/2012/05/23/2514728.html