|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的好朋友们!LVS
LVS是LinuxVirtualServer的简写,意即Linux假造办事器,是一个假造的办事器集群体系。本项目在1998年5月由章文嵩博士建立,是中国国际最早呈现的自在软件项目之一。今朝有三种IP负载平衡手艺(VS/NAT、VS/TUN和VS/DR)本文是依照VS/DR的体例设置,十种调剂算法(rrr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq)。
Keepalvied
Keepalived在这里次要用作RealServer的安康形态反省和LoadBalance主机和BackUP主机之间failover的完成
安排情况:
体系:linuxcentos5.8
浮动IP:192.168.1.150
主LVSIP:192.168.1.86
备LVSIP:192.168.1.87
实在办事器WEB1IP:192.168.1.88
实在办事器WEB2IP:192.168.1.250
装置与设置步调
1.主备LVS下载软件包#wgethttp://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz #wgethttp://www.keepalived.org/software/keepalived-1.1.15.tar.gz 2.主备LVS装置LVS和Keepalived2.6.18-53.el5PAE#ln-s/usr/src/kernels/2.6.18-53.el5PAE-i686//usr/src/linux (实行ln-s堕落请看最初的罕见成绩处置)#tarzxvfipvsadm-1.24.tar.gz #find/-nameipvsadm#检察ipvsadm的地位 #tarzxvfkeepalived-1.1.15.tar.gz #./configure&&make&&makeinstall #find/-namekeepalived#检察keepalived地位 #cp/usr/local/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/ #cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/ #cp/usr/local/etc/keepalived/keepalived.conf/etc/keepalived/ #cp/usr/local/sbin/keepalived/usr/sbin/ #servicekeepalivedstart|stop 3.主备LVS设置Keepalived
修正设置文件/etc/keepalived/keepalived.conf为以下内容(注重实在情况下将#正文申明的内容往失落)
1global_defs{
2notification_email{
3admin@gmail.com
4}
5notification_email_fromsns-lvs@gmail.com
6smtp_server127.0.0.1
7router_idLVS_DEVEL
8}
9
10vrrp_instanceVI_1{
11stateMASTER#备份办事器大将MASTER改成BACKUP
12inte***ceeth0
13virtual_router_id88
14priority100#备份办事大将100改成99
15advert_int1
16authentication{
17auth_typePASS
18auth_pass123123
19}
20virtual_ipaddress{
21192.168.1.150
22#(假如有多个VIP,持续换行填写.)
23}
24}
25
26virtual_server192.168.1.15080{
27delay_loop3#(每隔3秒查询realserver形态)
28lb_algowrr#(lvs算法)
29lb_kindDR#(DirectRoute)
30persistence_timeout3#(统一IP的毗连3秒内被分派到统一台realserver)
31protocolTCP#(用TCP协定反省realserver形态)
32
33real_server192.168.1.8880{
34weight3#(权重)
35TCP_CHECK{
36connect_timeout10#(10秒无呼应超时)
37nb_get_retry3
38delay_before_retry3
39connect_port80
40}
41}
42
43real_server192.168.1.25080{
44weight3
45TCP_CHECK{
46connect_timeout10
47nb_get_retry3
48delay_before_retry3
49connect_port80
50}
51}
52}
4.设置供应实在办事的主机
增加设置文件/etc/realserver/realserver.sh为以下内容1SNS_VIP=192.168.1.150
2
3/etc/rc.d/init.d/functions
4
5case"$1"in
6start)
7/sbin/ifconfiglo:0$SNS_VIPnetmask255.255.255.255broadcast$SNS_VIPup
8/sbin/routeadd-host$SNS_VIPdevlo:0
9echo"1">/proc/sys/net/ipv4/conf/lo/arp_ignore
10echo"2">/proc/sys/net/ipv4/conf/lo/arp_announce
11echo"1">/proc/sys/net/ipv4/conf/all/arp_ignore
12echo"2">/proc/sys/net/ipv4/conf/all/arp_announce
13sysctl-p>/dev/null2>&1
14echo"RealServerStartOK"
15;;
16
17stop)
18/sbin/ifconfiglo:0down
19/sbin/routedel$SNS_VIP>/dev/null2>&1
20echo"0">/proc/sys/net/ipv4/conf/lo/arp_ignore
21echo"0">/proc/sys/net/ipv4/conf/lo/arp_announce
22echo"0">/proc/sys/net/ipv4/conf/all/arp_ignore
23echo"0">/proc/sys/net/ipv4/conf/all/arp_announce
24echo"RealServerStoped"
25;;
26
27*)
28echo"Usage:$0{start|stop}"
29exit1
30esac
31
32exit0
5.供应实在办事的主机修正/etc/rc.d/rc.loal增加
/etc/realserver/realserver.sh
6.主备LVS实行#chkconfig--levelkeepalived35on 7.主备LVS启动keepalived办事#/etc/init.d/keepalivedstart 8.供应实在办事的主机运转/etc/realserver/realserver.sh#chmod+x/etc/realserver/realserver.sh #/etc/realserver/realserver.sh 9.检察以后LVS的形态 |
|