五.利用Keepalvied实现负载均衡和和高可用性
1.配置在主负载均衡服务器上配置keepalived.conf
#vi /etc/keepalived/keepalived.conf (主调度器)
! Configuration File for keepalived global_defs { vrrp_instance VI_1 { virtual_server 192.168.2.170 80 { real_server 192.168.2.172 80 { } } } |
在备用调度器上:
#vi /etc/keepalived/keepalived.conf (备用调度器)
! Configuration File for keepalived global_defs { vrrp_instance VI_1 { virtual_server 192.168.2.170 80 { real_server 192.168.2.172 80 { } } } |
2. BACKUP服务器同上配置,先安装lvs再按装keepalived,仍后配置/etc/keepalived/keepalived.conf,只需将红色标示的部分改一下即可.
3. vi /etc/rc.local
#/usr/local/sbin/lvs-dr.sh 将lvs-dr.sh这个脚本注释掉。
#/usr/local/sbin/lvs-dr.sh stop 停止lvs-dr脚本
#/etc/init.d/keepalived start 启动keepalived 服务,keepalived就能利用keepalived.conf 配
置文件,实现负载均衡和高可用.
4. 查看lvs服务是否正常
#watch ipvsadm –ln
IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddressort Scheduler Flags -> RemoteAddressort Forward Weight ActiveConn InActConn TCP 61.164.122.8:80 wrr persistent 60 -> 61.164.122.10:80 Route 3 0 0 -> 61.164.122.9:80 Route 3 0 0 |
复制代码
#tail –f /var/log/message 监听日志,查看状态,测试LVS负载均衡及高可用性是否有效。
5.停Master服务器的keepalived服务,查看BAKCUP服务器是否能正常接管服务。
四.相关参考
1.LVS 基础知识汇总
LVS的算法介绍 http://www.linuxtone.org/viewthread.php?tid=69
学习LVS的三种转发模式 http://www.linuxtone.org/viewthread.php?tid=77
LVS中的IP负载均衡技术 http://www.linuxtone.org/viewthread.php?tid=68
更多的请到http://www.linuxtone.org 负载均衡版查看
Keepalived 相关参考资料。
http://www.keepalived.org/documentation.html