heartbeat + nfs 实现高可用共享资源

Posted sunju

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了heartbeat + nfs 实现高可用共享资源相关的知识,希望对你有一定的参考价值。


主节点node1:192.168.200.101/24
备节点node2: 192.168.200.102/24
nfs: 192.168.200.103/24
安装前准备
heartbeat v2
ha web 实例
1、节点名称修改:
[[email protected] ~]#hostname node1
[[email protected] ~]# uname -n
node1
[[email protected] ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=node1

2、ssh 互相通信:
[[email protected] ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ‘‘ //自动生成秘钥
[[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected] //传送至节点node2
[[email protected] ~]# ssh node2 ‘ifconfig‘ //测试是否能操作节点node2
eth0 Link encap:Ethernet HWaddr 00:0C:29:65:7C:3F
inet addr:192.168.200.102 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe65:7c3f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:469456 errors:0 dropped:0 overruns:0 frame:0
TX packets:632160 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:224664819 (214.2 MiB) TX bytes:339254044 (323.5 MiB)

node2 节点配置相同,传送给node1.

3、主机名解析:
cat /etc/hosts
192.168.200.101 node1
192.168.200.102 node2

4、时间同步:
主节点配置:
[[email protected] ~]# yum -y install ntp
[[email protected] ~]# cp -p /etc/ntp.conf /etc/ntp.conf.origin
[[email protected] ~]# vim /etc/ntp.conf
22 server 127.127.1.0 //手动添加此两行内容
23 fudge 127.127.1.0 startum 8

[[email protected] ~]#service ntpd start
正在启动 ntpd: [确定]
[[email protected] ~]#chkconfig ntpd on
从节点配置:
[[email protected] ~]# yum -y instal ntpdate
[[email protected] ~]# ntpdate 192.168.200.101
4 Aug 16:41:16 ntpdate[40441]: adjust time server 192.168.200.101 offset -0.067223 sec
添加计划任务每5分钟执行一次。
[[email protected] ~]# crontab -l
*/5 * * * * /sbin/ntpdate 192.168.200.101 &>/dev/null
[[email protected] ~]# crontab -l
*/5 * * * * /sbin/ntpdate 192.168.200.101 &>/dev/null

nfs 和 node2 一样同步时间与node1时间服务器。

准备的安装包
[[email protected] heartbeat]# ls
cluster-glue-1.0.5-6.el6.x86_64.rpm perl-TimeDate-1.16-13.el6.noarch.rpm
cluster-glue-libs-1.0.5-6.el6.x86_64.rpm PyXML-0.8.4-19.el6.x86_64.rpm
heartbeat-3.0.4-2.el6.x86_64.rpm resource-agents-3.9.5-24.el6_7.1.x86_64.rpm
heartbeat-libs-3.0.4-2.el6.x86_64.rpm start.sh
lib64ltdl7-2.2.6-6.1mdv2009.1.x86_64.rpm
安装的顺序:
1、rpm -ivh PyXML-0.8.4-19.el6.x86_64.rpm
2、rpm -ivh resource-agents-3.9.5-24.el6_7.1.x86_64.rpm

3、rpm -ivh cluster-glue-libs-1.0.5-6.el6.x86_64.rpm

4、rpm -ivh perl-TimeDate-1.16-13.el6.noarch.rpm

5、rpm -ivh cluster-glue-1.0.5-6.el6.x86_64.rpm

6、rpm -ivh heartbeat-libs-3.0.4-2.el6.x86_64.rpm heartbeat-3.0.4-2.el6.x86_64.rpm //同时安装。
备节点node2 安装顺序相同。

安装后有三个配置文件:
1、秘钥文件,600,authkeys
2、heartbeat服务的配置文件ha.cf
3、资源管理配置文件:haresources(v2有2个资源管理器一个是crm,另一个默认v2版本使用haresources作为资源管理器)
[[email protected] heartbeat-3.0.4]# cd /etc/ha.d/
[[email protected] ha.d]# cp /usr/share/doc/heartbeat-3.0.4/haresources,authkeys,ha.cf ./
[[email protected] ha.d]# cat authkeys
#auth 1
#1 crc
#2 sha1 HI!
#3 md5 Hello!
auth 3
3 md5 3c94943451e56d84786bdf5072964350 // dd if=/dev/random cout=1 bs=512 |md5sum 添加一个随机码 放到md5 后面。
[[email protected] ha.d]# grep -v "^#" ha.cf
logfacility local0
keepalive 2
bcast eth0 # Linux
auto_failback on
node node1
node node2

[[email protected] ha.d]# cat haresources

node1 IPaddr::192.168.200.254/24/eth0:0 httpd

备节点和主节点配置一样。
======================================================================
各节点关闭httpd开机自启,让heartbeat启动httpd服务。
service httpd stop
chkconfg httpd off
[[email protected] ~]# echo "node1" > /var/www/html/index.html
[[email protected] ~]# echo "node2" > /var/www/html/index.html

测试:
主节点
[[email protected] html]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:4C:DD:5D
inet addr:192.168.200.101 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe4c:dd5d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8825 errors:0 dropped:0 overruns:0 frame:0
TX packets:4271 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1030060 (1005.9 KiB) TX bytes:723112 (706.1 KiB)

eth0:0 Link encap:Ethernet HWaddr 00:0C:29:4C:DD:5D
inet addr:192.168.200.254 Bcast:192.168.200.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
备节点
[[email protected] ha.d]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:65:7C:3F
inet addr:192.168.200.102 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe65:7c3f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:465233 errors:0 dropped:0 overruns:0 frame:0
TX packets:629414 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:224046430 (213.6 MiB) TX bytes:338744439 (323.0 MiB)

当主节点挂了备节点是否能接过来。
使用heartbeat自带的测试脚本工具
[[email protected] ha.d]# /usr/share/heartbeat/hb_standby
Going standby [all].
主节点
[[email protected] html]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:4C:DD:5D
inet addr:192.168.200.101 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe4c:dd5d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8825 errors:0 dropped:0 overruns:0 frame:0
TX packets:4271 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1030060 (1005.9 KiB) TX bytes:723112 (706.1 KiB)
备节点
[[email protected] ha.d]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:65:7C:3F
inet addr:192.168.200.102 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe65:7c3f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:465386 errors:0 dropped:0 overruns:0 frame:0
TX packets:629536 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:224070947 (213.6 MiB) TX bytes:338766983 (323.0 MiB)

eth0:0 Link encap:Ethernet HWaddr 00:0C:29:65:7C:3F
inet addr:192.168.200.254 Bcast:192.168.200.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1


========================================================================================================
配置nfs
[[email protected] ~]# cat /etc/exports
/web/htdocs 192.168.200.0/24(insecure,ro,no_root_squash)
echo "nfs server" >/web/htdocs/index.html
service rpcbind start
service nfs start

先开启rpc在开启nfs 顺序不能搞错。关闭也是先关闭rpc在关闭nfs.
[[email protected] ~]# showmount -e 192.168.200.103 //查看挂载情况
Export list for 192.168.200.103:
/web/htdocs 192.168.200.0/24
[[email protected] ~]# mount 192.168.200.103:/web/htdocs /var/www/html/ //测试手动挂载
[[email protected] ~]#umount /var/www/html/ //然后在卸载
先停止heartbeat node1 和node2 ,因为资源必须先启动在服务的前面。
然后配置haresources文件,添加Filesystem段nfs服务.
[[email protected] ~]# vim /etc/ha.d/haresources
node1 IPaddr::192.168.200.254/24/eth0:0 Filesystem::192.168.200.103:/web/htdocs::/var/www/html::nfs httpd
========================================================================================================
测试服务
[[email protected] ~]# curl http://192.168.200.254
nfs server
[[email protected] ~]# curl http://192.168.200.254
nfs server

 

以上是关于heartbeat + nfs 实现高可用共享资源的主要内容,如果未能解决你的问题,请参考以下文章

高可用集群之heartbeat v2--基于CRM实现mysql高可用集群(未完)

Heartbeat+Haresources+NFS配置一个简单的HA高可用+资源共享集群

heartbeat+drdb+nfs实现高可用

MySQL+heartbeat+nfs做高可用

drbd+nfs+heartbeat高可用

Heartbeat+DRBD+NFS高可用案例