CentOS6.4 lvs+keepalived High Availability load Balancing service configuration

Source: Internet
Author: User

CentOS6.4 lvs+keepalived High Availability load Balancing service configuration

One: test environment information

Server dell-r720

Virtualization KVM

Virtual Machine 4 units: IPVS01,IPVS02,WEB01,WEB02

[root@kvm01~]# Virsh List

Id Name State

----------------------------------------------------

1 SN-WEB01 Running

2 SN-WEB02 Running

3 Sn-ipvs01 Running

4 SN-IPVS02 Running

Network environment:

ipvs01:192.168.40.90

ipvs02:192.168.40.91

web01:192.168.40.86

web02:192.168.40.87

vip:192.168.40.6

System version:

Physics Machine CentOS6.4 64bit

Virtual Machine CentOS6.4 64bit

Second: Service configuration

The package 6.4 system has been ipvs1.25 and keepalived1.2.7 tested with Yum self installation.

Main LVS Server IPVS01 configuration:

[Root@ipvs01 ~]# Yum list >yum.list

[Root@ipvs01 ~]# cat Yum.list|grep Ipvs

ipvsadm.x86_64 1.25-10.el6 @base

[Root@ipvs01 ~]# cat yum.list |grep keepalived

keepalived.x86_64 1.2.7-3.el6 @base

[root@ipvs01 ~] #yum Install Ipvsadm keepalived

[Root@ipvs01 ~] #ipvsadm

[root@ipvs01 ~] #lsmod |grep Ip_vs to see if the module was loaded successfully

IP_VS_RR 1420 1

IP_VS_WRR 2179 0

Ip_vs 115643 5 IP_VS_RR,IP_VS_WRR

LIBCRC32C 1246 1 Ip_vs

IPv6 321422 Ip_vs

[root@ipvs01 ~] #cd/etc/keepalived/

[root@ipvs01 ~] #cp-a keepalived.conf/keepalived.bak

[root@ipvs01 ~] #vi keepalived.conf

! Configuration File for Keepalived

Global_defs {

Notification_email {

Acassen@firewall.loc

Failover@firewall.loc

Sysadmin@firewall.loc

}

Notification_email_from Alexandre.Cassen@firewall.loc

Smtp_server 192.168.200.1

Smtp_connect_timeout 30

router_id Lvs_master

}

Vrrp_instance Vi_1 {

State MASTER #角色主MASTER, the standby server is changed to backup

Interface Eth0 #HA侦听接口

virtual_router_id #虚拟路由标记ID, the same group VRRP consistent

Priority #优先级自定义, master higher than backup

Advert_int 1 #HA interception interval: 1 seconds

Authentication {#认证形式

Auth_type Pass #认证类型PASS: Pass/ah 2 kinds of optional

Auth_pass 1111 #认证密码, same group VRRP passwords consistent

}

virtual_ipaddress {#虚拟服务地址, can be multiple, divided multiple lines

192.168.40.6

}

}

Virtual_server 192.168.40.6 {#虚拟服务地址和端口

Delay_loop 6 #运行情况检查, unit seconds

Lb_algo RR #负载调度算法, RR for polling

Lb_kind DR #LVS负载工作模式为DR, three modes NAT,TUN,DR

Nat_mask 255.255.255.0 #网络掩码

#persistence_timeout #会话保持时间, allocate the same node within 50 seconds, the test time to see the balance effect can be commented out

Protocol TCP #协议类型TCP/UDP

Real_server 192.168.40.86 {#配置真实服务器节点1 IP and port

Weight 5 #权值大小, the more powerful the higher the value

Tcp_check {#realserver state detection time, unit seconds

Connect_timeout 3 #连接超时时间3秒

Nb_get_retry 3 #重试次数: 3 times

Delay_before_retry 3 #重试间隔

Connect_port #连接端口

}

}

Real_server 192.168.40.87 80 {

Weight 5

Tcp_check {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 80

}

}

}

Standby server IPVS02 Copy the primary server configuration file, and then modify 2:

State BACKUP

Priority 100

Others remain unchanged.

Three: Service node configuration:

WEB01,WEB02, HTTP service installation slightly

[Root@web01 ~]# cat/var/www/html/index.html

[Root@web02 ~]# cat/var/www/html/index.html

Run scripts separately on WEB01 and WEB02

Ifconfig lo:0 192.168.40.6 netmask 255.255.255.0 up

Route add-host 192.168.40.6 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

View route after execution to have a virtual IP route pointing lo Interface

[Root@web01 ~]# Route-n

Kernel IP Routing Table

Destination Gateway genmask Flags Metric Ref use Iface

192.168.40.6 0.0.0.0 255.255.255.255 UH 0 0 0 Lo

Four: Test LVs

Will IPVS01,IPVS02, keepalived service launch

Will web01,web02, HTTP service start

View the LVS status on the main LVS server as described in the following configuration effective

[Root@ipvs01 ~]# Ipvsadm-ln

IP Virtual Server version 1.2.1 (size=4096)

Prot Localaddress:port Scheduler Flags

-> remoteaddress:port Forward Weight activeconn inactconn

TCP 192.168.40.6:80 RR Persistent 50

-> 192.168.40.86:80 Route 5 0 0

-> 192.168.40.87:80 Route 5 0 0

From the IP a command, the virtual IP is now on the ipvs01, and IP A has no virtual IP from the server

[Root@ipvs01 ~]# IP A

1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN

Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00

inet 127.0.0.1/8 Scope host Lo

INET6:: 1/128 Scope Host

Valid_lft Forever Preferred_lft Forever

2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU 1500 Qdisc pfifo_fast State up Qlen 1000

Link/ether 52:54:00:06:88:F4 BRD FF:FF:FF:FF:FF:FF

inet 192.168.40.90/24 BRD 192.168.40.255 Scope Global eth0

inet 192.168.40.6/32 Scope Global eth0

Inet6 FE80::5054:FF:FE06:88F4/64 Scope link

Valid_lft Forever Preferred_lft Forever

> Test Load Balancing Effect:

To open the browser test:

Refresh

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.