Loading
0

Linux 之HA集群配置

[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 的
查看日志

分页阅读: 1 2 3
【声明】:8090安全小组门户(https://www.8090-sec.com)登载此文出于传递更多信息之目的,并不代表本站赞同其观点和对其真实性负责,仅适于网络安全技术爱好者学习研究使用,学习中请遵循国家相关法律法规。如有问题请联系我们:邮箱hack@ddos.kim,我们会在最短的时间内进行处理。