重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

heartbeat+ipvs+keepalived-创新互联

1.高可用Heartbeat

专注于为中小企业提供网站设计、成都做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业科尔沁右翼前免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了近1000家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

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-*

[root@server1 ha.d]# cd /usr/share/doc/heartbeat-3.0.4/

[root@server1 heartbeat-3.0.4]# cp ha.cf authkeys haresources /etc/ha.d/

[root@server1 heartbeat-3.0.4]# cd /etc/ha.d

[root@server1 ha.d]# vim ha.cf

heartbeat+ipvs+keepalived

heartbeat+ipvs+keepalived

heartbeat+ipvs+keepalived

heartbeat+ipvs+keepalived

[root@server1 ha.d]# vim authkeys

heartbeat+ipvs+keepalived

[root@server1 ha.d]# chmod 600 authkeys

[root@server1 ha.d]# vim haresources

heartbeat+ipvs+keepalived

[root@server1 ha.d]# scp ha.cf authkeys haresources server4:/etc/ha.d

[root@server1 ha.d]# /etc/init.d/heartbeat start

Server4做相同的操作

[root@server4 ha.d]# /etc/init.d/heartbeat start

测试:

heartbeat+ipvs+keepalived

[root@server1 ha.d]# /etc/init.d/heartbeat stop

heartbeat+ipvs+keepalived

[root@server1 ha.d]# /etc/init.d/heartbeat start

heartbeat+ipvs+keepalived

1.ipvs负载均衡

首先停掉server1和server4上的heartbeat

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

[root@server1 ~]# yum install -y ldirectord-3.9.5-3.1.x86_64.rpm

[root@server1 ~]# cd /usr/share/doc/ldirectord-3.9.5/

[root@server1 ldirectord-3.9.5]# cp ldirectord.cf /etc/ha.d

[root@server1 ~]# yum install -y ipvsadm

[root@server1 ~]# ipvsadm -L  

[root@server1 ~]# ipvsadm -C  ##清除规则

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

[root@server1 ~]# ip addr add 172.25.6.100/24 dev eth0

[root@server1 ~]# ip addr

heartbeat+ipvs+keepalived

[root@server1 ~]# ipvsadm -a -t 172.25.6.100:80 -r 172.25.6.2:80 -g  ##添加新规则

[root@server1 ~]# ipvsadm -a -t 172.25.6.100:80 -r 172.25.6.3:80 -g

[root@server1 ~]# /etc/init.d/ipvsadm save  ##保存添加的规则

 [root@server1 ~]# ipvsadm -L     ##显示内核中虚拟服务器列表

heartbeat+ipvs+keepalived

[root@server1 ~]# /etc/init.d/httpd restart

Server2上的操作

[root@server2 ~]# ip addr add 172.25.6.100/32 dev eth0

[root@server2 ~]# ip addr

heartbeat+ipvs+keepalived

[root@server2 ~]# yum install -y arptables_jf

[root@server2 html]# arptables -A IN -d 172.25.6.100 -j DROP

[root@server2 html]# arptables -A OUT -s 172.25.6.200 -j mangle --mangle-ip-s 172.25.6.2

[root@server2 html]# /etc/init.d/arptables_jf  save

[root@server2 html]# /etc/init.d/httpd restart

Server3上的操作

[root@server3 ~]# /etc/init.d/httpd start

[root@server3 ~]# ip addr add 172.25.6.100/32 dev eth0  ##给内网网卡添加ip

[root@server3 ~]# ip addr

heartbeat+ipvs+keepalived

[root@server3 ~]# yum install -y arptables_jf

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

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

[root@server3 ~]# /etc/init.d/arptables_jf save ##保存添加的策略

[root@server3 ~]# /etc/init.d/arptables_jf start 

[root@server3 ~]# /etc/init.d/httpd restart

测试:

heartbeat+ipvs+keepalived

2.高可用与负载均衡

[root@server1 ~]# yum install -y ldirectord-3.9.5-3.1.x86_64.rpm

[root@server1 ~]# cd /etc/ha.d/

[root@server1 ha.d]# vim ldirectord.cf

heartbeat+ipvs+keepalived

[root@server1 ha.d]# ipvsadm -C  ##清除策略

[root@server1 ha.d]# ipvsadm -L   ##查看策略

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

[root@server1 ha.d]# vim haresources

heartbeat+ipvs+keepalived

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

打开server4上的heartbeat替代server1的heartbeat

[root@server1 html]# /etc/init.d/httpd restart

测试:

如果server2和server3的httpd打开

heartbeat+ipvs+keepalived

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

heartbeat+ipvs+keepalived

4.keepalived

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

Server1上的操作

[root@server1 ~]# tar zxf keepalived-1.2.20.tar.gz

[root@server1 ~]#cd keepalived-1.2.20/

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

[root@server1 keepalived-1.2.20]# make &&  make install

[root@server1 keepalived-1.2.20]# cd /usr/local/keepalived/

[root@server1 local]# scp -r keepalived/ 172.25.6.4:/usr/local/

[root@server1 sbin]#

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

[root@server1 etc]# ln -s /usr/local/keepalived/etc/keepalived/ /etc/

[root@server1 sysconfig]#

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

[root@server1 sysconfig]#

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

[root@server1 init.d]# chmod +x keepalived

[root@server1 init.d]# cd /etc/keepalived/

[root@server1 keepalived]# ls

keepalived.conf  samples

[root@server1 keepalived]# vim keepalived.conf

heartbeat+ipvs+keepalived

heartbeat+ipvs+keepalived

heartbeat+ipvs+keepalived

[root@server1 keepalived]# /etc/init.d/keepalived start

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

Server4上的操作

[root@server4 keepalived]#

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

[root@server4 keepalived]#

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

[root@server4 keepalived]#

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

[root@server4 keepalived]#

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

etc/sysconfig/

[root@server4 keepalived]# /etc/init.d/keepalived start

[root@server4 keepalived]# mkdir /etc/keepalived/

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

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

将keepalived进行重启

测试:

heartbeat+ipvs+keepalived

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享标题:heartbeat+ipvs+keepalived-创新互联
标题链接:http://cqcxhl.com/article/shpej.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP