LVS + keepalived on centos 6.3

Source: Internet
Author: User
Tags failover

Yum
-Y install popt-static
Kernel-devel
Make gcc
OpenSSL-devel lftp
Libnl * popt *

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_MASTER ipvsadm-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_MASTER keepalived-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 backup to lvs_backup} vrrp_instance vi_1 {state master # Change backup to backup interface eth0 virtual_router_id 51 priority 100 # Change backup to 80 advert_int 1 authication {auth_type pass auth_pass 1111} virtual_ipaddress {region} vrrp_instance lan_gateway {state master # change it to lvs_backup interface eth1 virtual_router_id 52 priority 100 # change it to 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 lb_kind Nat # Listen 5 protocol TCP real_server 192.168.10.4 80 {weight 3 tcp_check {connect_timeout 3 listen 3 listen 3 delay_before_retry _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

<H1> 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. Execute service on CentOS-LVS_MASTER and CentOS-LVS_BACKUP respectively
Keepalived start starts keepalived to achieve load balancing and high-availability clusters;

[Root @ CentOS-LVS_MASTER keepalived] # service keepalived start

Iv. Test

#### High availability test ####

Simulate a fault, stop the keepalived service on the CentOS-LVS_MASTER, and then observe the log on the CentOS-LVS_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.

The log status of the CentOS-LVS_MASTER after the keepalived service on the CentOS-LVS_BACKUP is turned on.

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)

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.