heartbeat+ipvs+keepalived

1.高可用Heartbeat

Server1和server4安装资源包

   heartbeat-3.0.4-2.el6.x86_64.rpm

   heartbeat-devel-3.0.4-2.el6.x86_64.rpm

   heartbeat-libs-3.0.4-2.el6.x86_64.rpm

   ldirectord-3.9.5-3.1.x86_64.rpm

yum install -y heartbeat-*

[[email protected] ha.d]# cd /usr/share/doc/heartbeat-3.0.4/

[[email protected] heartbeat-3.0.4]# cp ha.cf authkeys haresources /etc/ha.d/

[[email protected] heartbeat-3.0.4]# cd /etc/ha.d

[[email protected] ha.d]# vim ha.cf

[[email protected] ha.d]# vim authkeys

[[email protected] ha.d]# chmod 600 authkeys 

[[email protected] ha.d]# vim haresources 

[[email protected] ha.d]# scp ha.cf authkeys haresources server4:/etc/ha.d

[[email protected] ha.d]# /etc/init.d/heartbeat start

Server4做相同的操作

[[email protected] ha.d]# /etc/init.d/heartbeat start

测试:

[[email protected] ha.d]# /etc/init.d/heartbeat stop

[[email protected] ha.d]# /etc/init.d/heartbeat start

 

1.ipvs负载均衡

首先停掉server1和server4上的heartbeat

Server1上的操作,并且server1做调度器

[[email protected] ~]# yum install -y ldirectord-3.9.5-3.1.x86_64.rpm

[[email protected] ~]# cd /usr/share/doc/ldirectord-3.9.5/

[[email protected] ldirectord-3.9.5]# cp ldirectord.cf /etc/ha.d

[[email protected] ~]# yum install -y ipvsadm

[[email protected] ~]# ipvsadm -L  

[[email protected] ~]# ipvsadm -C   ##清除规则

[[email protected] ~]# ipvsadm -A -t 172.25.6.100:80 -s rr    ##rr表示采用轮询调度算法,添加新的虚拟ip

[[email protected] ~]# ip addr add 172.25.6.100/24 dev eth0

[[email protected] ~]# ip addr

[[email protected] ~]# ipvsadm -a -t 172.25.6.100:80 -r 172.25.6.2:80 -g   ##添加新规则

[[email protected] ~]# ipvsadm -a -t 172.25.6.100:80 -r 172.25.6.3:80 -g

[[email protected] ~]# /etc/init.d/ipvsadm save   ##保存添加的规则

 [[email protected] ~]# ipvsadm -L      ##显示内核中虚拟服务器列表

[[email protected] ~]# /etc/init.d/httpd restart

Server2上的操作

[[email protected] ~]# ip addr add 172.25.6.100/32 dev eth0

[[email protected] ~]# ip addr

[[email protected] ~]# yum install -y arptables_jf

[[email protected] html]# arptables -A IN -d 172.25.6.100 -j DROP

[[email protected] html]# arptables -A OUT -s 172.25.6.200 -j mangle --mangle-ip-s 172.25.6.2

[[email protected] html]# /etc/init.d/arptables_jf  save

[[email protected] html]# /etc/init.d/httpd restart

Server3上的操作

[[email protected] ~]# /etc/init.d/httpd start

[[email protected] ~]# ip addr add 172.25.6.100/32 dev eth0   ##给内网网卡添加ip

[[email protected] ~]# ip addr

[[email protected] ~]# yum install -y arptables_jf

[[email protected] html]# arptables -A IN -d 172.25.6.100 -j DROP  ##给这个地址追加策略

[[email protected] html]# arptables -A OUT -s 172.25.6.100 -j  mangle --mangle-ip-s 172.25.6.3  ##追加策略,由100源地址跳到3上

[[email protected] ~]# /etc/init.d/arptables_jf save  ##保存添加的策略

[[email protected] ~]# /etc/init.d/arptables_jf start 

[[email protected] ~]# /etc/init.d/httpd restart

 

测试:

 

2.高可用与负载均衡

[[email protected] ~]# yum install -y ldirectord-3.9.5-3.1.x86_64.rpm

[[email protected] ~]# cd /etc/ha.d/

[[email protected] ha.d]# vim ldirectord.cf 

[[email protected] ha.d]# ipvsadm -C  ##清除策略

[[email protected] ha.d]# ipvsadm -L   ##查看策略

[[email protected] ha.d]# ip addr del 172.25.6.100/24 dev eth0    ##删除内网网卡上的ip

[[email protected] ha.d]# vim haresources 

[[email protected] ha.d]# scp haresources ldirectord.cf  172.25.6.4:/etc/ha.d/      ##server4上做与server1相同的操作

打开server4上的heartbeat替代server1的heartbeat

[[email protected] html]# /etc/init.d/httpd restart

测试:

如果server2和server3的httpd打开

如果server2和server3  httpd关闭,则访问heartbeat所在的主机

4.keepalived

关闭server1和server4的heartbeat,打开server2和server3的httpd

Server1上的操作

[[email protected] ~]# tar zxf keepalived-1.2.20.tar.gz

[[email protected] ~]#cd keepalived-1.2.20/

[[email protected] keepalived-1.2.20]# ./configure --prefix=/usr/local/keepalived/  ##解译到指定路径

[[email protected] keepalived-1.2.20]# make &&  make install

[[email protected] keepalived-1.2.20]# cd /usr/local/keepalived/

[[email protected] local]# scp -r keepalived/ 172.25.6.4:/usr/local/

[[email protected] sbin]#

 ln -s /usr/local/keepalived/sbin/keepalived /sbin/

[[email protected] etc]# ln -s /usr/local/keepalived/etc/keepalived/ /etc/

[[email protected] sysconfig]#

 ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

[[email protected] sysconfig]#

 ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

[[email protected] init.d]# chmod +x keepalived

[[email protected] init.d]# cd /etc/keepalived/

[[email protected] keepalived]# ls

keepalived.conf  samples

[[email protected] keepalived]# vim keepalived.conf 

[[email protected] keepalived]# /etc/init.d/keepalived start

将修改的配置文件发送到server4同位置

Server4上的操作

[[email protected] keepalived]#

 ln -s /usr/local/keepalived/sbin/keepalived /sbin/

[[email protected] keepalived]#

 ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d

[[email protected] keepalived]#

 chmod +x /usr/local/keepalived/etc/rc.d/init.d/keepalived

[[email protected] keepalived]#

 ln -s /usr/local/keepalived/etc/sysconfig/keepalived /

etc/sysconfig/

[[email protected] keepalived]# /etc/init.d/keepalived start

[[email protected] keepalived]# mkdir /etc/keepalived/

将文件中的server1改为server4,state改为backup,

两者的virtual_router_id一定不同,server4的priority值小于server1的值

将keepalived进行重启

测试:

时间: 2024-08-24 23:34:56

heartbeat+ipvs+keepalived的相关文章

heartbeat与keepalived的区别

Heartbeat与Keepalived的区别 Keepalived使用的vrrp协议方式,虚拟路由冗余协议 (Virtual Router Redundancy Protocol,简称VRRP):Heartbeat是基于主机或网络的服务的高可用方式:keepalived的目的是模拟路由器的双机heartbeat的目的是用户service的双机lvs的高可用建议用keepavlived业务的高可用用heartbeat 两款高可用开源方案:Keepalived和Heartbeat.两者都很流行,但

高可用 heartbeat和keepalived

双机热备heartbeat和keepalived 一.heartbeat安装配置   用heartbet搭建nginx服务高可用 环境:两台Centos6.5_x64系统下的高可用,每一台都需要两块网卡.       两台机器上都需要安装 nginx  主服务器 master ip(可以访问外网)172.18.9.89  ip(用于心跳检测):192.168.8.200 从服务器 slave ip(可以访问外网)172.18.9.99  ip(用于心跳检测):192.168.8.100  分别在

(heartbeat与KeepAlived)

总拓扑图 两种实现方式: 实验一. LVS+heartbeat+ldirectord实现集群负载: 1.在主Director Server上和备用Director Server上分别安装heartbeat.libnet与httpd: [[email protected] ~]# yum -y install heartbeat libnet httpd heartbeat-ldirectord ipvsadm 2.获得heartbeat的相关默认配置文件: [[email protected] 

高可用开源方案Heartbeat vs Keepalived

转:http://www.kuqin.com/shuoit/20140623/340745.html 最近因为项目需要,简单的试用了两款高可用开源方案:Keepalived和Heartbeat.两者都很流行,但差异还是很大的,现将试用过程中的感受以及相关知识点简单总结一下,供大家选择方案的时候参考. 1)Keepalived使用更简单:从安装.配置.使用.维护等角度上对比,Keepalived都比Heartbeat要简单得多,尤其是Heartbeat2.1.4后拆分成3个子项目,安装.配置.使用

MySQL+DRBD+heartbeat+LVS+keepalived

在node1上的操作:[[email protected] 桌面]# iptables -F[[email protected] 桌面]# chkconfig iptables off[[email protected] 桌面]# setenforce 0[[email protected] 桌面]# ip addr show1: lo: mtu 16436 qdisc noqueue state UNKNOWN     link/loopback 00:00:00:00:00:00 brd 0

heartbeat与keepalived对比

heartbeat: heartbeat高可用方案LVS+Heartbeat heartbeat有三个配置文件,比较复杂 heartbeat使用心跳机制,除了网络,还可以通过串口通信 heartbeat的脚本有约束 heartbeat的目的是用户service的双机 业务的高可用建议用heartbeat keepalived: keepalived高可用方案LVS+keepalived keepalived安装配置更加简单,只有一个安装.配置文件: keepalived使用VRRP协议,虚拟路由

ipvs-dr模型及算法、keepalived基本应用、keepalive+ipvs实现高可用

keepalived应用案例及其ipvs-dr模型原理解释 [LVS--的调度方法] 分类:静态方法:只根据调度方法本身来调度,不关心RS的负载情况来调度. 动态方法:根据调度方法本身和RS的负载状况来调度. [ 静态方法] RR  算法 : ROUND ROBIN,轮询 WRR算法:加权轮询 SH: sourcehashing源地址的hash绑定. 实现的方式: Session:绑定方式,无冗余能力丢失客户端要重来.实现方式;负载均衡器内部有一个会话表.他可以记录一个会话信息哈希编码记录(CI

LVS+Keepalived 实现高可用负载均衡集群

简介: 随着网站业务量的增长,网站的服务器压力越来越大?需要负载均衡方案!商业的硬件如 F5 ,Array又太贵,你们又是创业型互联公司如何有效节约成本,节省不必要的浪费?同时还需要实现商业硬件一样的高性能高可用的功能?有什么好的负载均衡可伸张可扩展的方案吗?有!我们利用LVS+Keepalivd基于完整开源软件的架构可以为你提供一个负载均衡及高可用的服务器.  一.LVS+Keepalived  介绍 1.  LVS LVS是Linux Virtual Server的简写,意即Linux虚拟服

HA Cluster和KeepAlived

HA Cluster和KeepAlived =========================================================================== 概述: =========================================================================== HA Cluster:  1.介绍 ★Linux Cluster类型: LB:Load Balancing,负载均衡集群: 存在SPoF(单点故