Virtual Linux cluster building based on VMware-lvs+keepalivedIn this paper, the load balancing between Lvsserver and real server is realized by keepalived. This aspect of the blog is quite a lot, but each person to build a cluster of different environments, the problems encountered are different. This article outlines some of the processes that are configured and how to resolve them when you encounter problems during configuration. Quasi-current work 1. Create a Linux virtual machineThis paper is based on vmare virtual environment to build a cluster. So first create some virtual machines in Vmare (Install a Linux system). The other replication will be installed for the first time). This article creates 4 virtual machines. The NIC mode is set to bridged. This ensures that the network and host IP in the virtual machine are in the same network segment. The advantage is that after you have set up IP for each virtual machine, you will be able to log on to Linux through the same network segment and a single host. You don't have to switch back and forth between virtual machines. (Linux release number 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
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvz3vveglhb2ppzv80mtu=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">
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 types. Must be capitalized, i.e. too host a standby machine
Interface eth0#设置对外服务网卡
VIRTUAL_ROUTER_ID 51
Priority #设置优先级. The priority of an alternate host is more than the host must not can
Advert_int 1#设置同步时间间隔
Authentication {#设置验证类型和password
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 rotation algorithm of tacit feeling
Lb_kind DR#负载均衡转发规则, which is the IP forwarding rule, the fastest Dr forwarding method. But all the machines must be in a network segment. and Nat and Tunel. Two ways to Forward
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
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvz3vveglhb2ppzv80mtu=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">
Lvsmaster:ipvsadm
Lvsbak:ip Addr
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvz3vveglhb2ppzv80mtu=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">
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 scripts such as the followingsns_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 the script is finished editing
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
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvz3vveglhb2ppzv80mtu=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">
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 (the main LVS is 100.) Spare LVS only less than 100 can be)
② to close the iptables or open the corresponding service port, or you will not be able to access through the browser
Virtual Linux cluster building based on VMware-lvs+keepalived