keepalived
企业lvs负载均衡
1、hearbeart+lvs+ldirectord
hearbeart lvs切换
ldirectord 健康检查
2、lvs
3、redhat piranha
4、keepalived+lvs
负载不均
1、会话保持
2、lvs调度算法
3、节点的会话保持
keepalived(vrrp协议)
原理:keepalivedDirectors 之间故障切换是以vrrp(虚拟路由冗余网关协议)来实现,keepalivedDirectors 正常工作时,主Directors节点不断向备节点发送健康心中信息,表明自己还活着。一旦有变时,将会有备用节点接管主节点的资源。当主节点恢复时备节点还给主节点主控制权,备节点仍是备用接收心跳。
vrrp特点:
1、master and slave 竟选;通过多播。
2、slave接不到包时,便会接管。
3、slave多个时,通过优先级竞选。
1、healthcheck
2、failover
keepalived + lvs 负载均衡与高可用性服务实战
1、安装
下载
wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
./configure
--3个Yes ok!
make
make install
[root@localhost keepalived-1.1.19]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/
[root@localhost keepalived-1.1.19]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
[root@localhost keepalived-1.1.19]# mkdir /etc/keepalived -p
[root@localhost keepalived-1.1.19]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
[root@localhost keepalived-1.1.19]# cp /usr/local/sbin/keepalived /usr/sbin/
[root@localhost keepalived-1.1.19]# service keepalived start
#ps -ef | grep keep
#service keepalived stop
2、在10.0.0.9上安装lvs
同上文
modprobe ip_vs
lsmod | grep ip_vs
在10.0.0.9上安装keepalived
wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
[root@localhost keepalived-1.1.19]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/
[root@localhost keepalived-1.1.19]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
[root@localhost keepalived-1.1.19]# mkdir /etc/keepalived -p
[root@localhost keepalived-1.1.19]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
[root@localhost keepalived-1.1.19]# cp /usr/local/sbin/keepalived /usr/sbin/
[root@localhost keepalived-1.1.19]# service keepalived start
#ps -ef | grep keep
#service keepalived stop
rz keepalived.conf.2-dan
mv keepalived.conf keepalived.conf.bak
mv keepalived.conf.2-dan keepalived.conf
将vip:10.0.0.10
service keepalived restart
关闭iptables、selinux
一定要关闭原来的eth0:0
ifconfig eth0:0 down
3、测试
ip add | grep 0.10
在10.0.0.9
service keepalived stop
ping 来查看超时,发现很快又通了,这是因为备份lb上来了。