lvs+keepalived安装
lvs+keepalived安装一、 LVS简介
LVS是Linux Virtual Server的简称,即Linux虚拟服务器。使用LVS技术要达到的目标是:通过LVS提供的负载均衡技术和Linux操作系统实现一个高性能、高可用的服务器群集,它具有良好可靠性、可扩展性和可操作性。从而以低廉的成本实现最优的服务性能。
二、网络拓扑
http://s3.运维网.com/wyfs02/M00/86/68/wKiom1e-VbeBdTRoAABNfUodNgM044.png-wh_500x0-wm_3-wmp_4-s_1469057335.png
三、接口IP及属性配置
1,在Master配置接口IP如下:
# ifconfig
ens33: flags=4163mtu 1500
inet 192.168.230.10netmask255.255.255.0broadcast 192.168.230.255
inet6 fe80::250:56ff:fe9a:55c5 prefixlen 64scopeid0x20
ether 00:50:56:9a:55:c5 txqueuelen 1000(Ethernet)
RX packets 1201bytes 94251 (92.0KiB)
RX errors 0dropped 0overruns 0 frame 0
TX packets 5964bytes 390181(381.0 KiB)
TX errors 0dropped 0 overruns0carrier 0collisions 0
ens33:0: flags=4163mtu 1500
inet 192.168.230.100netmask255.255.255.255broadcast192.168.230.100
ether 00:50:56:9a:55:c5 txqueuelen 1000(Ethernet)
2,在Slave配置接口IP如下:
# ifconfig
ens33:flags=4163mtu 1500
inet 192.168.230.11netmask255.255.255.0broadcast 192.168.230.255
inet6 fe80::250:56ff:fe9a:62e8 prefixlen 64scopeid0x20
ether 00:50:56:9a:62:e8 txqueuelen 1000(Ethernet)
RX packets 3bytes 620 (620.0 B)
RX errors 0dropped 0overruns 0 frame 0
TX packets 50bytes 7844 (7.6KiB)
TX errors 0dropped 0 overruns0carrier 0collisions 0
ens33:0:flags=4163mtu 1500
inet 192.168.230.100netmask255.255.255.255broadcast192.168.230.100
ether 00:50:56:9a:62:e8 txqueuelen 1000(Ethernet)
3,在rs1上配置接口IP如下:
# ifconfig
ens33:flags=4163mtu 1500
inet 192.168.230.12netmask255.255.255.0broadcast 192.168.230.255
inet6 fe80::250:56ff:fe9a:daa prefixlen 64scopeid0x20
ether 00:50:56:9a:0d:aa txqueuelen 1000(Ethernet)
RX packets 162543bytes 11199233(10.6 MiB)
RX errors 0dropped 66overruns 0 frame 0
TX packets 74236bytes 9216209(8.7 MiB)
TX errors 0dropped 0 overruns0carrier 0collisions 0
lo:0:flags=73mtu65536
inet 192.168.230.100netmask 255.255.255.255
looptxqueuelen 0(Local Loopback)
4,在rs2上配置接口IP如下:
# ifconfig
ens33:flags=4163mtu 1500
inet 192.168.230.13netmask255.255.255.0broadcast 192.168.230.255
inet6 fe80::250:56ff:fe9a:2be1 prefixlen 64scopeid0x20
ether 00:50:56:9a:2b:e1 txqueuelen 1000(Ethernet)
RX packets 161840bytes 11150452(10.6 MiB)
RX errors 0dropped 44overruns 0 frame 0
TX packets 73427bytes 7893814(7.5 MiB)
TX errors 0dropped 0 overruns0carrier 0collisions 0
lo:0:flags=73mtu65536
inet 192.168.230.100netmask255.255.255.255
looptxqueuelen 0(Local Loopback)
5,在Master和Slave上开启转发功能
# echo "1">/proc/sys/net/ipv4/ip_forward
6,在rs1和rs2配置接口属性
# 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
net.ipv4.conf.ens33.arp_announce = 2
net.ipv4.conf.ens33.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
四、软件安装
1,在Master上安装ipvsadm和keepalived
# yum install -ykeepalived ipvsadm
2,同样在Slave上安装ipvsadm和keepalived
# yum install -ykeepalived ipvsadm
3,在rs1和rs2安装测试服务,这里安装httpd服务,具体服务配置请参考官方配置文档。
# yum install -yhttpd
访问192.168.230.12服务:
http://s2.运维网.com/wyfs02/M02/86/68/wKioL1e-Vc2jEsaJAAA3uxhB3CA353.png-wh_500x0-wm_3-wmp_4-s_2213946703.png
访问192.168.230.13服务:
http://s1.运维网.com/wyfs02/M02/86/68/wKiom1e-VeChO3eHAAA6NABLTyU079.png-wh_500x0-wm_3-wmp_4-s_3097642534.png
五、keepalived配置
1,在Master配置如下:
# cat/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@test.com #全局配置,邮件通知配置。
failover@test.com
sysadmin@
test.com
}
notification_email_from Alexandre.Cassen@test.com
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 { #配置vrrp实例
state MASTER #配置vrrp状态,Mater配置为MASTER,Slave配置为SLAVE
interface ens33 #关联端口,根据实际修改
virtual_router_id 55 #vrrpid,Master和Slave需配置一致
priority 100 #vrrp优先级,Mater配置100,Slave应该配置小于100就行
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.230.100 #与vip对应
}
}
virtual_server 192.168.230.100 80 { #配置虚拟服务属性
delay_loop 6
lb_algo rr #配置算法,默认rr(轮询算法)
lb_kind DR #配置lvs模式
#persistence_timeout 50 #会话保持时间
protocol TCP #协议
real_server 192.168.230.12 80 { #真实服务器属性
weight 1 #权重
}
real_server 192.168.230.13 80 {
weight 1
}
}
2,在Slave上配置如下:
# cat/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@test.com
failover@test.com
sysadmin@test.com
}
notification_email_from Alexandre.Cassen@test.com
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP #vrrp状态slave配置为BACKUP
interface ens33
virtual_router_id 55
priority 90 #Slave优先级低于Mater的优先级
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.230.100
}
}
virtual_server 192.168.230.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol TCP
real_server 192.168.230.12 80 {
weight 1
}
real_server 192.168.230.13 80 {
weight 1
}
}
3,在Master和Slave上配置开机自启动服务
# chkconfig keepalived on
4,配置完在Master和Slave上重启keepalived服务
# servicekeepalived restart
六、测试
1,客户端通过vip访问
http://s3.运维网.com/wyfs02/M00/86/68/wKioL1e-VfThgtImAAAz7SgR8Lg803.png-wh_500x0-wm_3-wmp_4-s_2258327857.png
2,清除浏览器缓存再次访问
http://s2.运维网.com/wyfs02/M02/86/69/wKiom1e-VguyUE3lAAA1_l2mg68773.png-wh_500x0-wm_3-wmp_4-s_1736683230.png
3,将Mater关闭,再次通过vip依然可以正常访问
http://s4.运维网.com/wyfs02/M00/86/68/wKioL1e-ViDwE6xKAAAyx4yejWQ833.png-wh_500x0-wm_3-wmp_4-s_2295990236.png
4,丢包测试,重启Master过程丢1个ping包。
http://s5.运维网.com/wyfs02/M01/86/69/wKiom1e-VjeR4EnAAAA9PdZj4Vo159.png-wh_500x0-wm_3-wmp_4-s_2546348820.png
页:
[1]