|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
欢迎大家来到仓酷云论坛!1、实行安排软件清单
CentOS6.4X64mini
Keepalived-1.2.7.tar.gz
Ipvsadm1.2.5-10
2、实行目标
利用Keepalived完成基于LVS(DR)形式的集群计划,体系架构以下拓朴布局图,我们利用Keepalived完成VIP在两台LVS之间切换,LVS1作为缺省调剂器,当LVS1调剂器呈现妨碍后,LVS2能够主动接受LVS1。以后的调剂器卖力把客户哀求转发给后端实在的办事器(web1与web2),因为LVS事情在DR形式下,一切的实在办事器必要在本人的Non-ARP装备上设置VIP,终极由后端实在办事器将呼应数据包经由过程路由传送给用户。
Keepalived+LVS拓朴图
办事器收集信息
3、实行历程
3.1web1操纵步调以下:
一时封闭iptables及selinux
[root@web1~]#iptables–F&&iptables–X&&serviceiptablessave
[root@web1~]#setenforce1&&echo“/usr/sbin/setenforce1”>>/etc/rc.local
设置主机名及ip地点
[root@web1~]#hostnameweb1.example.com
[root@web1~]#vi/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.21.111
PREFIX=24
GATEWAY=172.16.21.254
DNS1=8.8.8.8
增加假造接口地点
[root@web1~]#vi/etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.21.253
PREFIX=32
GATEWAY=172.16.21.254
因为收集中多个装备都设置了VIP地点,为了避免呈现地点抵触的成绩,必要做一些内核的变动:
[root@web1~]#vi/etc/sysctl.conf
net.ipv4.conf.lo.arp_ignore=1
net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2
修正sysctl.conf后实行sysctl–p当即失效
[root@web1~]#sysctl–p
[root@web1~]#servicenetworkrestart
装置httpd软件包,并设置启动它。
[root@web1~]#yum–yinstallhttpd
[root@web1~]#echo`uname–n`>/var/www/html/index.html
[root@web1~]#servicehttpdstart&&chkconfighttpdon
3.2web2操纵步调与web1是几近是分歧的:
一时封闭iptables及selinux
[root@web2~]#iptables–F&&iptables–X&&serviceiptablessave
[root@web2~]#setenforce1&&echo“/usr/sbin/setenforce1”>>/etc/rc.local
设置主机名及ip地点
[root@web2~]#hostnameweb2.example.com//并在network中增加
[root@web2~]#vi/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.21.112
PREFIX=24
GATEWAY=172.16.21.254
DNS1=8.8.8.8
增加假造接口地点
[root@web2~]#vi/etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.21.253
PREFIX=32
GATEWAY=172.16.21.254
[root@web2~]#vi/etc/sysctl.conf
net.ipv4.conf.lo.arp_ignore=1
net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2
修正sysctl.conf后实行sysctl–p当即失效
[root@web2~]#sysctl–p
[root@web2~]#servicenetworkrestart
装置httpd软件包,并设置启动它。
[root@web2~]#yum–yinstallhttpd
[root@web2~]#echo`uname–n`>/var/www/html/index.html
[root@web2~]#servicehttpdstart&&chkconfighttpdon
3.3lvs1调剂器操纵步调以下:
设置主机名及IP地点
[root@lvs1~]#hostnamelvs1.example.com
[root@lvs1~]#vi/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.21.211
PREFIX=24
GATEWAY=172.16.21.254
DNS1=8.8.8.8
装置keepalived
[root@lvs1~]#yum–yinstallgccmakewgetopenssl-develpopt-devellibnllibnl-develkernel-develipvsadm
[root@lvs1~]#wgethttp://www.keepalived.org/software/keepalived-1.2.7.tar.gz
[root@lvs1~]#tarzxvfkeepalived-1.2.7.tar.gz
[root@lvs1~]#cdkeepalived-1.2.7
[root@lvs1~]#./configure
[root@lvs1~]#make&&makeinstall
[root@lvs1~]#ln–s/usr/local/etc/keepalived//etc
[[root@lvs1~]#ln–s/usr/local/etc/rc.d/init.d/keepalived/etc/init.d/
[root@lvs1~]#ln–s/usr/local/etc/sysconfig/keepalived/etc/sysconfig/
[root@lvs1~]#ln–s/usr/local/sbin/keepalived/usr/sbin/
经由过程keepalived完成办事的高可用性,我们此时必要修正keepalived主设置文件DD本实行lvs1为主装备,lvs2为从装备,并包管个中一台呈现妨碍后,另外一台装备能够实时、激活妨碍的装备,另必要在该设置文件增加假造办事IP,并为该假造办事增加后端实在的WEB组与对应的算法,本实行中的算法为rr(轮循).
[root@lvs1~]#vi/etc/keepalived/keepalived.conf
global_defs{
notification_email{
root@localhost
}
notification_email_fromroot@example.com
smtp_serverlocalhost
smtp_connect_timeout30
router_idLVS_01
}
vrrp_instanceHA{
stateMASTER#主节点,备用节点上为BACKUP
inte***ceeth0#绑定假造IP的收集接口
virtual_router_id51#VRRP组名,两个节点必需分歧
priority100#优先级(1-254之间),数值年夜越高,备用低于100
advert_int1#组播信息发送距离,两个节点设置必需一样
authentication{#考证信息,两个节点必需分歧
auth_typePASS
auth_pass1111
}
virtual_ipaddress{#假造IP
172.16.21.253
}
}
virtual_server172.16.21.25380{
delay_loop6#安康反省工夫距离
lb_algorr#负载平衡调剂算法
lb_kindDR#负载平衡转发划定规矩
#persistence_timeout20#设置会话坚持工夫
protocolTCP#协定
real_server192.168.1.10580{
weight3#设置权重
TCP_CHECK{
connect_timeout3
nb_get_retry3
delay_before_retry3
connect_port80
}
}
real_server172.16.21.11180{
weight3
TCP_CHECK{
connect_timeout3
nb_get_retry3
delay_before_retry3
connect_port80
}
}
real_server172.16.21.11280{
weight3
TCP_CHECK{
connect_timeout3
nb_get_retry3
delay_before_retry3
connect_port80
}
}
}
将keepalived启动并到场到开机列表
[root@lvs1~]#servicekeepalivedstart&&chkconfigkeepalivedon
封闭iptables及selinux
[root@lvs1~]#iptables–F&&iptables–X&&serviceiptablessave
[root@lvs1~]#setenforce1&&echo“/usr/sbin/setenforce1”>>/etc/rc.local
3.4由于都是调剂器,lvs2调剂器操纵流程及步调与lvs1调试器分歧,纷歧致的中央keepalived设置文件(白色标志):
设置主机名及IP地点
[root@lvs2~]#hostnamelvs2.example.com
[root@lvs2~]#vi/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.21.212
PREFIX=24
GATEWAY=172.16.21.254
DNS1=8.8.8.8
装置keepalived
[root@lvs2~]#yum–yinstallgccmakewgetopenssl-develpopt-devellibnllibnl-develkernel-develipvsadm
[root@lvs2~]#wgethttp://www.keepalived.org/software/keepalived-1.2.7.tar.gz
[root@lvs2~]#tarzxvfkeepalived-1.2.7.tar.gz
[root@lvs2~]#cdkeepalived-1.2.7
[root@lvs2~]#./configure
[root@lvs2~]#make&&makeinstall
[root@lvs2~]#ln–s/usr/local/etc/keepalived//etc |
|