-lvs+keepalived of Virtual Linux cluster building based on Vmare

Source: Internet
Author: User

-lvs+keepalived of Virtual Linux cluster building based on VmareIn this paper, the load balance between the two-machine hot standby and the real server of LVS server is realized by keepalived. This aspect of the blog is quite a lot, but each person to build a cluster of different environments, encountered different problems, this article briefly describes the configuration of some of the process and the configuration process encountered problems in the solution. Quasi-current work 1. Create a Linux virtual machineThis article is based on the Vmare virtual environment to build a cluster, so first in the Vmare to create some virtual machines (install a Linux system, the other replication first installed), this article to create 4 virtual machines. Network card mode is set to bridge, this can ensure that the virtual machine and the host IP in the same network segment, the advantage is that after each virtual machine is set up IP, you can go through the same network segment of another host landing to Linux, you do not have to switch between the virtual machine. (Linux distribution is CentOS 5.5) 2. Configuring the Yum Library

If this machine does not have the Yum library, it is best to install the Yum Library to facilitate software installation

Yum Library Create basic steps

① installation Createrepo

②yum-y installl Createrepo

③ created with Createrepo

The Createrepo command is used to generate some basic configuration information needed for the Yum repository.

For details, please refer to "Installing the Yum Library in Configuration"


Cluster configuration 1. Set the virtual machine IP

Virtual four Linux hosts in a vmare virtual machine

Lvsmaster:192.168.10.101

lvsbak:192.168.10.102

realserver1:192.168.10.121

realserver2:192.168.10.122



topology diagram between hosts


2. Installing Ipvsadm and Keepalived① are installed on Lvsmaster and Lvsbak respectively Ipvsadm

Yum-y Install *ipvsadm*

: wget Http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar

② are installed on Lvsmaster and Lvsbak respectively keepalived

Install dependent libraries: Yum install-y OpenSSL Openssl-devel

Download Keepalived:wget http://www.keepalived.org/software/keepalived-1.2.6.tar.gz

Tar zxvf keepalived-1.2.6.tar.gz
./configure--prefix=/usr/local/keepalived
Make
Make install
cp/usr/local/keepalived/sbin/keepalived/usr/sbin/
cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/
cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/
Mkdir/etc/keepalived

Cp/usr/local/keepalived/etc/keepalived/keepalived/etc/keepalived.conf

③ Configuration keepalived

Lvsmaster Configuration

Global_defs {
Notification_email {
[Email protected]#emial通知
}
Notification_email_from [email protected]
Smtp_server 192.168.200.1
Smtp_connect_timeout 30
router_id Lvs_devel
}

Vrrp_sync_group Test {#设置vrrp组
Group {
LoadBalance
}
}
Vrrp_instance LoadBalance {
State MASTER#设置主机类型, master and backup two, must be capitalized, that is, too host a standby machine
Interface eth0#设置对外服务网卡
VIRTUAL_ROUTER_ID 51
Priority #设置优先级, standby host is lower than the host
Advert_int 1#设置同步时间间隔
Authentication {#设置验证类型和密码
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {#设置虚拟ip, floating IP
192.168.10.115
}

Virtual_server 192.168.10.115 80 {
Delay_loop 6#健康检查时间间隔
Lb_algo RR#负载调度算法, the default is the rotation algorithm
Lb_kind DR#负载均衡转发规则, which is the IP forwarding rule, the fastest Dr forwarding, but all the machines must be in a network segment, there are NAT and Tunel two ways of forwarding
Protocol TCP

Real_server 192.168.10.121 80 {
Weight 1
Tcp_check {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}

Real_server 192.168.10.122 80 {
Weight 1
Tcp_check {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}

}


Lvsbakr Configuration

Global_defs {
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 192.168.200.1
Smtp_connect_timeout 30
router_id Lvs_devel
}

Vrrp_sync_group Test {
Group {
LoadBalance
}
}


Vrrp_instance LoadBalance {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 99
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.10.115
}
}

Virtual_server 192.168.10.115 80 {
Delay_loop 6
Lb_algo RR
Lb_kind DR
Protocol TCP

Real_server 192.168.10.121 80 {
Weight 1
Tcp_check {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}

Real_server 192.168.10.122 80 {
Weight 1
Tcp_check {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}

④ Start keepalived

Lvsmastrer:/etc/init.d/keepalived Start

Lvsbak:/etc/init.d/keepalived Start

View startup status

Lvsmaster:tail-f/var/log/messages


Lvsbak:tail-f/var/log/messages


Viewing routing conditions with IP addr and ipvsadm

Lvsmaster:ip Addr

Lvsmaster:ipvsadm

Lvsbak:ip Addr

lvsbak: Ipvsadm

3. Setting RealServer1 and RealServer2① Editing Realserve ScriptsThe script settings for RealServer1 and ResalServer2 are the same, all realserver.sh, and the settings script is as followssns_vip=192.168.10.115
Source/etc/rc.d/init.d/functions
Case "$" in
Start
Ifconfig lo:0 $SNS _vip netmask 255.255.255.255 broadcast $SNS _VIP up
/sbin/route add-host $SNS _vip 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
Sysctl-p >/dev/null 2>&1
echo "Realserver Start OK"
;;
Stop
Ifconfig lo:0 Down
Route del $SNS _VIP >/dev/null 2>&1
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "Realserver stoped"
;;
*)
echo "Usage: $ {start|stop}"
Exit 1
Esac
Exit 0 start realserver.sh When script editing is complete
RealServer1:./realserver.sh startRealServer2:./realserver.sh start View IP② installing Apache on RealServer1 and RealServer2 installationYum-y Install httpd ConfigurationServerName www.example.comNamevirtualhost 192.168.10.121:80<virtualhost 192.168.10.121:80>
Documentroot/var/www/html
ServerName www.example.com
</VirtualHost>
Add index.html Test Home under/var/www/hmtl/ start Apache:/etc/init.d/httpd start 4. Test load balancing and dual-machine hot standby using Ipvsadm to view routing conditions for Lvsmaster and Lvsbak
Lvsmaster:ipvsadm L Vsbak:ipvsadm

5. Issues to be aware of during configuration ① configuration keepalvied issues to be aware ofLvsmaster and Lvsbak only have two different state MASTER | Backup (Master LVs is master, backup LV is backup)
Priority 100 | 90 (main LVS is 100, spare LVS as long as less than 100)

② to close the iptables or open the appropriate service port, otherwise it cannot be accessed through the browser

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.