Keepalived Load Balancer Instance

Source: Internet
Author: User

Objective: To realize load balancing of SR1 and SR2 by using keepalived to achieve load balance of HTTP user access 192.168.1.153.

Lab Environment:

sr1:192.168.1.151 HTTP Service

sr2:192.168.1.152 HTTP Service

ka1:192.168.1.150 Main keepalived

ka2:192.168.1.149 Preparation keepalived

vip:192.168.1.153 Virtual IP


Operation Steps:

One: SR1, SR2 install httpd service, configure virtual IP

Yum-y Install httpd

Mkdir/etc/sh

vim/etc/sh/dr.sh

#!/bin/bash
vip=192.168.1.153
Ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
Route Add-host $vip 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


Change permissions and run

chmod 700/etc/sh/dr.sh;bash/etc/sh/dr.sh

Ifconfig View lo:0 is in the up state.


II: KA1, KA2 installation keepalived, Ipvsadm service

Yum-y Install keepalived

Yum-y Install Ipvsadm

Three: Configure the primary keepalived

Vim/etc/keepalived/keeplived.conf

! Configuration File for Keepalived

Global_defs {#全局配置
Notification_email {
[Email protected] #If there is a malfunction, the email address of the receiving part is not filled
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 192.168.1.202
Smtp_connect_timeout 30#邮件服务器连接超时的最长时间
router_id Lvs_devel
}

Vrrp_instance Vi_1 {
State MASTER#主keepalived is MASTER, standby keepalived is set to backup
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 100#主keepalived的的优先级, prepared keepalived can be set to
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}

virtual_ipaddress {
192.168.1.153 #虚拟IP
}
}

Virtual_server 192.168.1.153 80 {
Delay_loop 6 #每6秒检查一次服务是否正常
Lb_algo RR #负载均衡的调度算法方式, typically using RR or WLC

Lb_kind Dr #负载均衡的模式, TUN, NTA, Dr three species
Nat_mask 255.255.255.0
Persistence_timeout 2 #会话保持时间, Unit: Sec. If it is a dynamic service, it is recommended to turn it on.

Protocol TCP#通讯模式. TCP UDP

Real_server 192.168.1.151 80 {#真实服务的IP
Weight 100#权重值, the larger the value, the higher the weight, the more likely the distributionTcp_check {
Connect_timeout 10# (10 seconds No response timeout)
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80#端口
}
}

Real_server 192.168.1.152 80 {
Weight 10
Tcp_check {
Connect_timeout 10 # (10 seconds No response timeout)
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
}


Four: Configuration standby keepalived

Vim/etc/keepalived/keepalived.conf

On the basis of the main keepalived.conf

1:state MASTER modified to State BACKUP

2:priority 100 modified to Priority 90


Five: Start ka1 first, then start KA2

KA1:/etc/init.d/keepalived start;

KA2:/etc/init.d/keepalived start;


VI: The browser accesses the http://192.168.1.153 for testing.

This article is from the "night Reading Wit Hope female Ghost" blog, please be sure to keep this source http://more3.blog.51cto.com/9929586/1631208

Keepalived Load Balancer Instance

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.