Lvs+keepalived for high-availability web load Balancing

Source: Internet
Author: User

Topology diagram

650) this.width=650; "Src=" http://linuxu.qiniudn.com/wp-content/uploads/2015/02/ Wpid-4d13c224248612e7ae61bc1f0269c904_44848000.png "border=" 0 "/>

Installing keepalived

[email protected] ~]# Yum install-y keepalived

Modify Keepalived MASTER configuration file

[[email protected] ~]# vim /etc/keepalived/keepalived.conf ! configuration  file for keepalived global_defs {   notification_email {      [email protected]     [email protected]      [email protected]   }   notification_email_from [email  protected]   router_id LVS_DEVEL} vrrp_instance VI_1 {     state master  # #定义主节点     interface eth0      virtual_router_id 51  # #识别虚拟路由的id, the same ID will be identified as 1 groups     priority  100  # #优先级, high priority will be elected as the main node     advert_int 1     authentication {        auth_type pass   ## The authentication method is pass  and ah  &Nbsp;     auth_pass 1111    }    virtual _ipaddress {        172.16.30.100   # #vip即虚拟IP         }} virtual_server 172.16.30.100 80 {     delay_loop 6    lb_algo rr   # #调度模式rr, polling      lb_kind dr   # #负载均衡模型为DR    also nat     persistence_timeout 0   # #超时时长, the time spent on each node, set here to 0, the default is 50s, will stay on a single node for 50 seconds on the other node      protocol TCP     real_server 172.16.30.10 80 {       # #后端rs主机         weight 1         TCP_CHECK {                  connect_port 80   # #连接端口              connect_timeout 3  # #连接超时时间              nb_get_retry 3   # #重试次数              delay_before_retry 3   # #每次重试之间的间隔时间          } real_server 172.16.30.11 80 {         weight 1        TCP_CHECK {                 connect_port 80             connect_timeout 3             nb_get_retry 3             delay_before_retry 3        }    } }


To copy a configuration file to another node

[Email protected] ~]# scp/etc/keepalived/keepalived.conf172.16.30.2:/etc/keepalived/keepalived.conf

Modify State priority as

650) this.width=650; "Src=" http://linuxu.qiniudn.com/wp-content/uploads/2015/02/ Wpid-4d13c224248612e7ae61bc1f0269c904_22255140.png "border=" 0 "/>

Start keepalived Test VIP

Master IP, stop the master keepalived service

650) this.width=650; "Src=" http://linuxu.qiniudn.com/wp-content/uploads/2015/02/ Wpid-4d13c224248612e7ae61bc1f0269c904_f2587950-c15e-43da-aa7f-eaf3e6e62fed.png "border=" 0 "/>

BACKUP IP

650) this.width=650; "Src=" http://linuxu.qiniudn.com/wp-content/uploads/2015/02/ Wpid-4d13c224248612e7ae61bc1f0269c904_b085a5ac-4987-44d1-b74c-b70b1b7f13ac.png "border=" 0 "/>

VIP Successful Transfer

Configure the Web server

Installing httpd

[email protected] ~]# Yum install-y httpd

Provide Web page files

[Email protected] ~]# vim/var/www/html/index.html


Node11 the same operation

Configuring the RS Model

[[email protected] ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore     # #关闭arp转发 [[Email protected] ~]# echo 1 > /proc/sys/net/ipv4 /conf/all/arp_ignore[[email protected] ~]# echo 2 > /proc/sys/net/ipv4/conf/ All/arp_announce [[email protected] ~]# echo 2 > /proc/sys/net/ipv4/conf /lo/arp_announce [[email protected] ~]# ifconfig lo:0 172.16.30.100 netmask  255.255.255.255 broadcast 172.16.30.100 up # #在lo: 0 Port set vip  and broadcast only to yourself [[email  protected] ~]# ifconfig eth0      link encap:ethernet   HWaddr 08:00:27:02:A7:9A             inet addr:172.16.30.10  bcast:172.16.255.255  mask:255.255.0.0           inet6 addr: fe80::a00:27ff:fe02:a79a/64 Scope:Link           UP BROADCAST RUNNING MULTICAST  MTU:1500   metric:1          rx packets:5319 errors:0  dropped:0 overruns:0 frame:0          tx  packets:685 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000            RX bytes:485435  (474.0 kib)   TX bytes:55938  (54.6  kib)  lo        Link encap:Local Loopback             inet addr:127.0.0.1  mask : 255.0.0.0          inet6 addr: ::1/128 scope:host           UP LOOPBACK RUNNING  MTU:65536  Metric:1           RX packets:0 errors:0 dropped:0  overruns:0 frame:0          tx packets:0  errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:0           RX  bytes:0  (0.0 b)   TX bytes:0  (0.0 b)  lo:0       Link encap:Local Loopback             inet addr:172.16.30.100  Mask:255.255.255.255           up loopbacK running  mtu:65536  metric:1 


Node11 same operation

Start the HTTPD service separately

Access test

650) this.width=650; "Src=" http://linuxu.qiniudn.com/wp-content/uploads/2015/02/ Wpid-4d13c224248612e7ae61bc1f0269c904_a6e8345d-8fdf-48df-90da-1af602bc55de.png "border=" 0 "/>

650) this.width=650; "Src=" http://linuxu.qiniudn.com/wp-content/uploads/2015/02/ Wpid-4d13c224248612e7ae61bc1f0269c904_02d20363-1736-4eef-8465-dd5b1812a35f.png "style=" FONT-SIZE:10.5PT; line-height:1.5; "border=" 0 "/>

Now stop the keepalived service on Node1.

Another visit or the same result, let's see if the IP,VIP on Node2 has been transferred.

650) this.width=650; "Src=" http://linuxu.qiniudn.com/wp-content/uploads/2015/02/ Wpid-4d13c224248612e7ae61bc1f0269c904_3f546530-8b42-4315-a305-513562757c1e.png "border=" 0 "/>

This enables high-availability load balancing of the lvs+keepalived, which is responsible for load balancing of the Web server, while keepalived guarantees that the LVS will not have a single point of failure.


This article is from the "Linuxu" blog, make sure to keep this source http://linuxu.blog.51cto.com/9471357/1613488

Lvs+keepalived for high-availability web load Balancing

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.