码迷,mamicode.com
首页 > 系统相关 > 详细

Linux 之HA集群酌置

时间:2016-12-19 22:29:24      阅读:428      评论:0      收藏:0      [点我收藏+]

标签:linux 之ha集群酌置

HA(高可用 High avaiilable)集群

Web1 提供服务,如果1主宕机了,2备就可以马上启用,这样有用户这端没有任何影响。

在架构的时候要配置一条心跳线来传递信息。流动IP 也是就是VIP,是主从对外共同的IP。

技术分享


[root@LNMP ~]# iptables -F

[root@LNMP ~]# getenforce 

Disabled


[root@LNMP ~]# vim /etc/hosts #在主上编译上

10.72.4.21 LNMP

10.72.4.14 OBird

[root@OBird ~]# vim /etc/hosts #复制到从上

10.72.4.21 LNMP

10.72.4.14 OBird


#

[root@LNMP ~]# wget  www.lishiming.net/data/attachment/forum/epel-release-6-8_64.noarch.rpm


#下载epel

[root@LNMP ~]# rpm -ivh epel-release-6-8_64.noarch.rpm  #安装(主从都安装)

[root@LNMP ~]# yum list |grep heartbeat

heartbeat.x86_64                            3.0.4-2.el6                  epel   

heartbeat-devel.i686                        3.0.4-2.el6                  epel   

heartbeat-devel.x86_64                      3.0.4-2.el6                  epel   

heartbeat-libs.i686                         3.0.4-2.el6                  epel   

heartbeat-libs.x86_64                       3.0.4-2.el6                  epel   


主从各自安装 heaerbeat & libnet

[root@LNMP ~]# yum install -y heartbeat

[root@LNMP ~]# yum install libnet

[root@OBird ~]# yun install -y heartbeat

[root@OBird ~]# yum install libnet


[root@LNMP ~]# cd /usr/share/doc/heartbeat-3.0.4/ #进到目录下拷贝样例

[root@LNMP heartbeat-3.0.4]# ls

apphbd.cf  authkeys  AUTHORS  ChangeLog  COPYING  COPYING.LGPL  ha.cf  haresources  README

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

[root@LNMP heartbeat-3.0.4]# 

技术分享

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

[root@LNMP ha.d]# ls

authkeys  ha.cf  harc  haresources  rc.d  README.config  resource.d  shellfuncs

[root@LNMP ha.d]# vim authkeys  #编译验证配置文件

#auth 1  #打开更改为 auth 1

#1 crc

#2 sha1 HI!

#3 md5 Hello! #打开md5验证:3 md5 Hello!

[root@LNMP ha.d]# chmod 600 authkeys #编译目录权限,不然heartbeat 服务不能启动


[root@LNMP ha.d]# cd /etc/sysconfig/network-scripts/ #配置虚拟网卡&IP

[root@LNMP network-scripts]# ls

ifcfg-eth0   ifdown-eth   ifdown-post    ifdown-tunnel  ifup-eth   ifup-plip   ifup-routes    init.ipv6-global

ifcfg-lo     ifdown-ippp  ifdown-ppp     ifup           ifup-ippp  ifup-plusb  ifup-sit       net.hotplug

ifdown       ifdown-ipv6  ifdown-routes  ifup-aliases   ifup-ipv6  ifup-post   ifup-tunnel    network-functions

ifdown-bnep  ifdown-isdn  ifdown-sit     ifup-bnep      ifup-isdn  ifup-ppp    ifup-wireless  network-functions-ipv6


[root@LNMP network-scripts]# cp ifcfg-eth0 ifcfg-eth0\:1 #配置虚拟网卡&IP

[root@LNMP network-scripts]# vim ifcfg-eht0\:1

DEVICE=eth0:1

#HWADDR=00:0C:29:5A:02:3F

TYPE=Ethernet

#UUID=22567e42-4d72-40e9-8ca3-98098c239d9c

ONBOOT=no #开机不不启动,楼主是桥接模式,所以是静态且不启动

NM_CONTROLLED=yes

BOOTPROTO=static

IPADDR=10.72.4.110

NETMASK=255.255.254.0

#GATEWAY=10.72.4.1

~                  

[root@LNMP network-scripts]# /etc/init.d/network restart #重新启动网络服务,可以看到两个IP


[root@LNMP ha.d]# vim haresources #编译

#node1  10.0.0.170 Filesystem::/dev/sda1::/data1::ext2 #直接加下面一行,更改当前行为下一行

LNMP    10.72.4.111/23/eth0:0 nginx



[root@LNMP ha.d]# >ha.cf #清空配置


[root@LNMP ha.d]# vim ha.cf  #写入以下内容


debugfile /var/log/ha-debug  #日志文件,和下面的ha.log 记录的东西差不多

logfile /var/log/ha-log

logfacility   local0         #日志的级别,此处是local 0,不要看成了10

keepalive     2              #多长时间探测一次对方是否还在

deadtime    30               #30秒Ping通宣告死亡

warntime    10               #10秒Ping不通发出警告

initdead    60               #防止对方服务器在重启,缓冲的时间

udpport     694              #心跳线通讯的端口  694

ucast eht0 10.72.4.14        # 对方的IP ,也可用bcast广播

auto_failback on             #如果备机启用,当主再次激活时还原主

node        LNMP             #master

node        OBird            #slave

ping 10.72.4.1               #仲裁地址,一般用路由或交换机,用稳定的设置

respawn hacluster /usr/lib64/heartbeat/ipfail #以哪个用户的身份来运行脚本。脚本是检测网络连通性的,检测对方是否存活。


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


技术分享

[root@OBird ha.d]# vim ha.cf #从上的配置 ,只需要更改IP 到对方,其它配置无需更改

ucast eht0 10.72.4.21


启动:先启动主,后启动从。先后顺序不要搞错了。

[root@LNMP ha.d]# /etc/init.d/heartbeat start #也是信了邪,主上的heartbeat 可以启动

Starting High-Availability services: INFO:  Resource is stopped

Done.


[root@OBird ha.d]# /etc/init.d/heartbeat start #同样的配置在从上却启动不了

技术分享

#在网上寻求解决方法

做HA实验时,启动heartbeat出现错误:

 ERROR: Client child command [/usr/lib/heartbeat/ipfail] is not executable

   ERROR: Heartbeat not started: configuration error.

   ERROR: Configuration error, heartbeat not started.

因为楼主的linux是64位的,ha.cf 配置文件里

/usr/lib/heartbeat/ipfail 这一句要改为:

/usr/lib64/heartbeat/ipfail

 

再次启动/etc/init.d/heartbeat start

Starting High-Availability services: INFO:  Resource is stopped

Done.成功(但是楼主不明,为何从上的配置的lib,为什么又可以启动)


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

[root@OBird ha.d]# /etc/init.d/heartbeat start #从上的heartbeat 启动成功

Starting High-Availability services: INFO:  Resource is stopped

Done.


[root@LNMP ha.d]# ip add  #vip启动了

[root@LNMP ha.d]# ps aux |grep nginx  #nginx 启动,详见下图


技术分享


[root@OBird ha.d]# ps aux |grep nginx  #从上的nginx 是可能启动的,如果启动则说明HA失败 

root      3654  0.0  0.0 103252   824 pts/0    S+   22:42   0:00 grep nginx



下面用nginx 的黙认页来做测试

[root@LNMP ~]# vim /data/dis 


[root@LNMP dis]# echo "2016-12-19-masterLNMP" > forum.php


 



#楼主的主(master)是在LNMP的环境中,没有重新安装装ngixn ,路径和黙认路径不一样。

#C:\Windows\System32\drivers\etc  10.72.4.21 www.linux.com


技术分享



[root@LNMP dis]# iptables -A INPUT -p icmp -j DROP #关掉主上的 ping ,心跳线是基于ping 的

查看日志

技术分享

在从上写入以下内容,通过VIP 访问。和上图比较,内容已发生改变,ha搭建成功。

[root@OBird ha.d]# echo "2016-12-19-masterSlvepppppppppppppppp" > /usr/share/nginx/html/index.html  #在从上的nginx黙认目下写入以下内容,通过IE 访问

技术分享

查看从上的nginx 服务启情况,

技术分享


本文出自 “CBO#Boy_Linux之路” 博客,请务必保留此出处http://20151213start.blog.51cto.com/9472657/1884003

Linux 之HA集群酌置

标签:linux 之ha集群酌置

原文地址:http://20151213start.blog.51cto.com/9472657/1884003

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!