CentOS 7下安装配置Heartbeat高可用集群(2)

vim /usr/local/heartbeat/etc/ha.d/haresources
#指定节点主机名,和VIP地址,以双冒号分隔资源,此处以apache为例进行配置
node1.pjy.com  192.168.146.222 apache::/etc/httpd/conf/httpd.conf

4.节点2上准备配置文件

#拷贝三个配置好的文件到节点2上,只需修改ha.cf配置文件中的单播地址为对方地址即可(ucast ens33 192.168.146.141)。

scp authkeys ha.cf haresources root@node2:/usr/local/heartbeat/etc/ha.d/

5.安装httpd资源服务

#在每个节点上安装httpd服务并测试

yum install httpd
echo "<h1>node1.pjy.com</h1>" >>/var/www/html/index.html
systemctl start httpd
curl 192.168.146.141

#测试httpd服务正常后关闭httpd服务并关闭自启动

systemctl stop httpd
systemctl disable httpd

6.启动服务

#启动每个节点上heartbeat服务

systemctl enable heartbeat
systemctl start heartbeat
ssh node2 'systemctl start heartbeat'

7.测试结果

# curl
<h1>node1.pjy.com</h1>
#使用heartbeat自带脚本切换主备节点
# /usr/local/heartbeat/share/heartbeat/hb_standby
Going standby [all].
# curl
<h1>node2.pjy.com</h1>

8.配置NFS共享存储

#在建立NFS的服务器上建立NFS存储:

yum install nfs-utils rpcbind
systemctl start rpcbind
systemctl start nfs
cat /etc/exports  #建立NFS共享存储
/data 192.168.146.0/24(ro)
mkdir /data  #建立测试文件
echo '<h1>nfs server</h1>' > /data/index.html

#然后修改haresources配置文件添加自动挂载nfs资源:

node1.pjy.com IPaddr::192.168.146.222/24/ens33 Filesystem::192.168.146.151:/data::/var/www/html::nfs::ro apache::/etc/httpd/conf/httpd.conf

#重启heartbeat服务加载配置

systemctl restart heartbeat
ssh node2 'systemctl restart heartbeat'

#测试是否加载资源:

ip addr
netstat -lntup
mount

#资源转移测试:

/usr/local/heartbeat/share/heartbeat/hb_standby

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a4b70d59a406ed593c04198c870676c1.html