HeartBeat(NFS文件挂载实现Web服务双机热备)

时间:2020-05-26
本文章向大家介绍HeartBeat(NFS文件挂载实现Web服务双机热备),主要包括HeartBeat(NFS文件挂载实现Web服务双机热备)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

2台主机互为备份,Web服务显示NFS文件系统上的资源。

新增一个Linux6.8的系统作为NFS文件服务器

目录:

1、完成HeartBeat基础配置

2、配置NFS服务器

3、配置HeartBeat资源管理服务器使用NFS资源

4、结果测试

1、完成HeartBeat基础配置

基础配置这里就不在叙述了,参考下面这篇文档。

HeartBeat基础配置(实现Web服务双机热备)

2、配置NFS服务器

创建共享文件夹/file/web/

mkdir -p /file/web/
echo "<h1>this is nfs server</h1>" >> /file/web/index.html

配置共享文件

vim /etc/exports
添加
/file/web  192.168.0.0/255.255.0.0(ro)

NFS服务配置

vim /etc/sysconfig/nfs

启动相应的NFS版本,这里我们使用4

启动服务,配置开机自启

service nfs start
chkconfig nfs on

检查共享的文件夹

关闭selinux

如果是临时测试

setenforce 0

如果长期使用

vim /etc/selinux/config

注意:

如果是实际生产环境,建议将selinux开启,然后乖乖去写安全规则。

NFS服务配置完毕

3、配置HeartBeat资源管理服务器使用NFS资源

测试文件挂载

NA1(关闭selinux)

setenforce 0
mkdir -p /mnt/webfile/
mount -t nfs 192.168.94.131:/file/web /mnt/webfile/

挂载没问题。取消挂载

umount /mnt/webfile

NA2(关闭selinux)

setenforce 0

配置heartbeat资源管理器

NA1&NA2关闭heartbeat服务

service heartbeat stop

将NFS共享目录挂载到/var/www/html下

vim /etc/ha.d/haresources
添加
na1.server.com IPaddr::192.168.94.222/24/eth1 Filesystem::192.168.94.131:/file/web::/var/www/html::nfs httpd

然后将haresource复制到NA2上。

scp /etc/ha.d/haresources na2:/etc/ha.d/

启动heartbeat服务

service heartbeat start
ssh na2 'service heartbeat start'

查看日志

[root@na1 ~]# tail -f /var/log/messages
May 25 09:09:33 na1 heartbeat: [4960]: info: G_main_add_SignalHandler: Added signal handler for signal 17
May 25 09:09:33 na1 heartbeat: [4960]: info: Local status now set to: 'up'
May 25 09:09:33 na1 heartbeat: [4960]: info: Link na1.server.com:eth1 up.
May 25 09:09:44 na1 heartbeat: [4960]: info: Link na2.server.com:eth1 up.
May 25 09:09:44 na1 heartbeat: [4960]: info: Status update for node na2.server.com: status up
May 25 09:09:44 na1 harc(default)[4968]: info: Running /etc/ha.d//rc.d/status status
May 25 09:09:44 na1 heartbeat: [4960]: info: Comm_now_up(): updating status to active
May 25 09:09:44 na1 heartbeat: [4960]: info: Local status now set to: 'active'
May 25 09:09:45 na1 heartbeat: [4960]: info: Status update for node na2.server.com: status active
May 25 09:09:45 na1 harc(default)[4986]: info: Running /etc/ha.d//rc.d/status status
May 25 09:09:55 na1 heartbeat: [4960]: info: remote resource transition completed.
May 25 09:09:55 na1 heartbeat: [4960]: info: remote resource transition completed.
May 25 09:09:55 na1 heartbeat: [4960]: info: Initial resource acquisition complete (T_RESOURCES(us))
May 25 09:09:55 na1 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.94.222)[5038]: INFO:  Resource is stopped
May 25 09:09:55 na1 heartbeat: [5002]: info: Local Resource acquisition completed.
May 25 09:09:55 na1 harc(default)[5119]: info: Running /etc/ha.d//rc.d/ip-request-resp ip-request-resp
May 25 09:09:55 na1 ip-request-resp(default)[5119]: received ip-request-resp IPaddr::192.168.94.222/24/eth1 OK yes
May 25 09:09:55 na1 ResourceManager(default)[5138]: info: Acquiring resource group: na1.server.com IPaddr::192.168.94.222/24/eth1 Filesystem::192.168.94.131:/file/web::/var/www/html::nfs httpd
May 25 09:09:56 na1 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.94.222)[5164]: INFO:  Resource is stopped
May 25 09:09:56 na1 ResourceManager(default)[5138]: info: Running /etc/ha.d/resource.d/IPaddr 192.168.94.222/24/eth1 start
May 25 09:09:56 na1 IPaddr(IPaddr_192.168.94.222)[5285]: INFO: Adding inet address 192.168.94.222/24 with broadcast address 192.168.94.255 to device eth1
May 25 09:09:56 na1 IPaddr(IPaddr_192.168.94.222)[5285]: INFO: Bringing device eth1 up
May 25 09:09:56 na1 IPaddr(IPaddr_192.168.94.222)[5285]: INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-192.168.94.222 eth1 192.168.94.222 auto not_used not_used
May 25 09:09:56 na1 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.94.222)[5259]: INFO:  Success
May 25 09:09:56 na1 /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.94.131:/file/web)[5369]: INFO:  Resource is stopped
May 25 09:09:56 na1 ResourceManager(default)[5138]: info: Running /etc/ha.d/resource.d/Filesystem 192.168.94.131:/file/web /var/www/html nfs start
May 25 09:09:56 na1 Filesystem(Filesystem_192.168.94.131:/file/web)[5444]: INFO: Running start for 192.168.94.131:/file/web on /var/www/html
May 25 09:09:56 na1 /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.94.131:/file/web)[5436]: INFO:  Success
May 25 09:09:56 na1 ResourceManager(default)[5138]: info: Running /etc/init.d/httpd  start
May 25 09:09:57 na1 ntpd[1741]: Listen normally on 7 eth1 192.168.94.222 UDP 123

4、结果测试

访问VIP192.168.94.222

关闭NA1再访问

访问正常,查看NA2的日志

May 25 09:09:04 na2 heartbeat: [3838]: info: Status update for node na1.server.com: status up
May 25 09:09:04 na2 harc(default)[3845]: info: Running /etc/ha.d//rc.d/status status
May 25 09:09:05 na2 heartbeat: [3838]: info: Comm_now_up(): updating status to active
May 25 09:09:05 na2 heartbeat: [3838]: info: Local status now set to: 'active'
May 25 09:09:05 na2 heartbeat: [3838]: info: Status update for node na1.server.com: status active
May 25 09:09:05 na2 harc(default)[3861]: info: Running /etc/ha.d//rc.d/status status
May 25 09:09:15 na2 heartbeat: [3838]: info: local resource transition completed.
May 25 09:09:15 na2 heartbeat: [3838]: info: Initial resource acquisition complete (T_RESOURCES(us))
May 25 09:09:15 na2 heartbeat: [3879]: info: No local resources [/usr/share/heartbeat/ResourceManager listkeys na2.server.com] to acquire.
May 25 09:09:15 na2 heartbeat: [3838]: info: remote resource transition completed.
May 25 09:15:28 na2 dhclient[1500]: DHCPREQUEST on eth1 to 192.168.94.254 port 67 (xid=0x14aa7d01)
May 25 09:15:28 na2 dhclient[1500]: DHCPACK from 192.168.94.254 (xid=0x14aa7d01)
May 25 09:15:28 na2 dhclient[1500]: bound to 192.168.94.130 -- renewal in 848 seconds.
May 25 09:15:28 na2 NetworkManager[1470]: <info> (eth1): DHCPv4 state changed renew -> renew
May 25 09:15:28 na2 NetworkManager[1470]: <info>   address 192.168.94.130
May 25 09:15:28 na2 NetworkManager[1470]: <info>   prefix 24 (255.255.255.0)
May 25 09:15:28 na2 NetworkManager[1470]: <info>   gateway 192.168.94.2
May 25 09:15:28 na2 NetworkManager[1470]: <info>   nameserver '192.168.94.2'
May 25 09:15:28 na2 NetworkManager[1470]: <info>   domain name 'localdomain'
May 25 09:15:28 na2 heartbeat: [3838]: info: Received shutdown notice from 'na1.server.com'.
May 25 09:15:28 na2 heartbeat: [3838]: info: Resources being acquired from na1.server.com.
May 25 09:15:28 na2 heartbeat: [3931]: info: acquire local HA resources (standby).
May 25 09:15:28 na2 heartbeat: [3931]: info: local HA resource acquisition completed (standby).
May 25 09:15:28 na2 heartbeat: [3838]: info: Standby resource acquisition done [all].
May 25 09:15:28 na2 heartbeat: [3932]: info: No local resources [/usr/share/heartbeat/ResourceManager listkeys na2.server.com] to acquire.
May 25 09:15:28 na2 harc(default)[3957]: info: Running /etc/ha.d//rc.d/status status
May 25 09:15:29 na2 mach_down(default)[3972]: info: Taking over resource group IPaddr::192.168.94.222/24/eth1
May 25 09:15:29 na2 ResourceManager(default)[3997]: info: Acquiring resource group: na1.server.com IPaddr::192.168.94.222/24/eth1 Filesystem::192.168.94.131:/file/web::/var/www/html::nfs httpd
May 25 09:15:29 na2 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.94.222)[4023]: INFO:  Resource is stopped
May 25 09:15:29 na2 ResourceManager(default)[3997]: info: Running /etc/ha.d/resource.d/IPaddr 192.168.94.222/24/eth1 start
May 25 09:15:29 na2 IPaddr(IPaddr_192.168.94.222)[4144]: INFO: Adding inet address 192.168.94.222/24 with broadcast address 192.168.94.255 to device eth1
May 25 09:15:29 na2 IPaddr(IPaddr_192.168.94.222)[4144]: INFO: Bringing device eth1 up
May 25 09:15:29 na2 IPaddr(IPaddr_192.168.94.222)[4144]: INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-192.168.94.222 eth1 192.168.94.222 auto not_used not_used
May 25 09:15:29 na2 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.94.222)[4118]: INFO:  Success
May 25 09:15:29 na2 /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.94.131:/file/web)[4228]: INFO:  Resource is stopped
May 25 09:15:29 na2 ResourceManager(default)[3997]: info: Running /etc/ha.d/resource.d/Filesystem 192.168.94.131:/file/web /var/www/html nfs start
May 25 09:15:29 na2 Filesystem(Filesystem_192.168.94.131:/file/web)[4303]: INFO: Running start for 192.168.94.131:/file/web on /var/www/html
May 25 09:15:29 na2 /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.94.131:/file/web)[4295]: INFO:  Success
May 25 09:15:30 na2 ResourceManager(default)[3997]: info: Running /etc/init.d/httpd  start
May 25 09:15:30 na2 mach_down(default)[3972]: info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
May 25 09:15:30 na2 mach_down(default)[3972]: info: mach_down takeover complete for node na1.server.com.
May 25 09:15:59 na2 heartbeat: [3838]: WARN: node na1.server.com: is dead
May 25 09:15:59 na2 heartbeat: [3838]: info: Dead node na1.server.com gave up resources.
May 25 09:15:59 na2 heartbeat: [3838]: info: Link na1.server.com:eth1 dead.

红色字体表示,NA1dead后,NA2进行的一系列活动。

接管VIP,挂载资源,启动httpd服务。


读书和健身总有一个在路上

原文地址:https://www.cnblogs.com/Renqy/p/12964761.html