Environment Introduction
650) this.width=650; "src=" http://img1.51cto.com/attachment/201312/154725413.jpg "alt=" 154725413.jpg "/>
Operating system: centos6.5_x64 Mini
Load Balancing Mode: DR (Direct routing)
LVS and keepalived Brief description:
LVSis aLinux Virtual Serverthe short, meaning thatLinux Virtual Server, is aa virtual server cluster system. Achieve a high-performance, high-availability server with cluster technology and Linux operating systems, with good scalability, reliability, and manageability.
lvs cluster with IP and content-based request distribution technology. The scheduler has a good throughput rate, transfers the request evenly to the different server execution, and the scheduler automatically shields off the server's failure, thereby composing a set of servers into a high-performance, highly available
First, configure the master-slave LVS Server
install dependency package:
[[email protected] ~]
# Yum install-y gcc gcc-c++ makepcre pcre-devel kernel-devel openssl-devel libnl-devel popt-devel
1, installation Ipvsadm
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
Tar zxvf ipvsadm-1.26.tar.gz
CD ipvsadm-1.26
Make && make install
2, Installation keepalived
wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
Tar zxvf keepalived-1.2.7.tar.gz
CD keepalived-1.2.7
./configure--prefix=/usr/local/keepalived
Make && make install
Configure keepalived as a system service
cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/
cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/
mkdir/etc/keepalived/
cp/usr/local/keepalived/etc/keepalived/keepalived.conf/etc/keepalived/
cp/usr/local/keepalived/sbin/keepalived/usr/sbin/
3. Modify the main keepalived configuration file (only modify router_id, state and priority)
[Email protected] ~]# vi/etc/keepalived/keepalived.conf
! Configuration File forkeepalived
Global_defs {
Notification_email {
[Email protected] #故障接受联系人
}
Notification_email_from [email protected] #故障发送人
Smtp_server 127.0.0.1 #本机发送邮件
Smtp_connect_timeout 30
router_id Lvs_master #BACKUP上修改为LVS_BACKUP
}
Vrrp_instance Vi_1 {
State MASTER #BACKUP上修改为BACKUP
Interface eth0
virtual_router_id #虚拟路由标识, the same as the master
Priority #BACKUP上修改为90
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111 #主从认证密码必须一致
}
virtual_ipaddress {#Web虚拟IP (VTP)
172.0.0.10
}
}
Virtual_server 172.0.0.10 {#定义虚拟IP和端口
Delay_loop 6 #检查真实服务器时间, units per second
Lb_algo RR #设置负载调度算法, RR to rotation
Lb_kind DR #设置LVS负载均衡DR模式
Persistence_timeout #同一IP的连接60秒内被分配到同一台真实服务器
Protocol TCP #使用TCP协议检查realserver状态
Real_server 172.0.0.13 {#第一个web服务器
Weight 3 #节点权重值
Tcp_check {#健康检查方式
Connect_timeout 3 #连接超时
Nb_get_retry 3 #重试次数
Delay_before_retry 3 #重试间隔/S
}
}
Real_server 172.0.0.14 {#第二个web服务器
Weight 3
Tcp_check {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
[Email protected] ~]# service keepalived Restart #启动keepalived
Script the two Web servers and start each one.
[Email protected] ~]# vi/etc/init.d/real.sh
#description: Start Realserver
vip=172.0.0.10
. /etc/init.d/functions
Case "$" in
Start
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
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
echo "LVS realserver Start OK"
;;
Stop
/sbin/ifconfig lo:0 Down
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 "LVS realserver stoped OK"
;;
*)
echo "Usage: $ {start|stop}"
Exit 1
Esac
[Email protected] ~]# chmod +x/etc/init.d/real.sh
[[email protected] ~]#/etc/init.d/real.sh start
LVS Realserver Start OK
[Email protected] ~]# echo "/etc/init.d/real.sh start" >>/etc/rc.local
[[Email protected] ~]# service httpd start
[Email protected] ~]# echo "192.168.0.30″>/var/www/html/index.html
[Email protected] ~]# echo "192.168.0.40″>/var/www/html/index.html
[[Email protected] ~]# service iptables stop #关闭防火墙
[Email protected] ~]# Setenforce 0 #临时关闭selinux
Third, test and common commands
http://172.0.0.10 #访问一直刷新会轮训显示172.0.0.13/14
Simulation of the main LVS, the server will work as usual, then the WEB1, then only display Web2, so that the IP load balancing, high availability of the cluster. When the main LVS is restored, it is switched to an active server, and if the Keepalived monitoring module detects a web failure recovery, the restored host joins the node in the cluster system.
Common commands:
[Email protected] ~]# Ipvsadm-ln #显示集群中服务器ip信息
[Email protected] ~]# IP addr #显示VTP绑定在哪个服务器上
[Email protected] ~]# tail-f/var/log/messges
(from the log, the host failure, the standby immediately detected, the standby machine becomes the master role, and take over the host's virtual IP resources, and finally bind the virtual IP on the Etho device)
This article is from the "System operation and maintenance website Development" blog, please be sure to keep this source http://cgc888.blog.51cto.com/3989433/1688875
Build lvs+keepalived under CentOS