Linxu Standard HA Solution (一)

最近有个linux上的HA的任务,所以开始研究linux平台的HA通用解决方案。目标平台是SLES 64b,但是目标是linux平台通用的HA方案。这里我记录一些操作层面的一些心得。

 

查了一些资料,感觉用heartbeat + pacemaker方案的比较多,加上这两个开源软件已经出现很久了,应该在很多平台上验证过,所以我首先尝试这个组合。

 

在这个组合中heartbeat 作为节点之前的通讯层,管理着节点之前的信息传输和节点监控,pacemaker作为资源管理组件,在beartbeat之上,管理着各个资源。

 

 

 

首先,SLES(SUSE Linux Enterprise Server)是没有现成的heartbeat rpm包的,应该SLES的HA方案用的是openAIS(heartbeat的替代品),所以只有从网上下载源代码自己编译,安装。

编译,安装可以从网站 http://www.linux-ha.org/doc/ 找到。

 

一般来说,你需要xmldoc, docbook, libxlst这些库以及开发包(xmldoc-devel, docbook-devel, libxlst-devel, libuuid-devel),网上要求先安装lib-glue,SUSE自带了lib-glue,你可以从官网上下到开发包。然后你就可以编译成功。

 

SLSE是自带pacemaker的,但是应该SLSE默认是openAIS方案,所以自带的pacemaker是不支持heatbeat3.0的,现象就是ha.log里你可以看到类似错误“cluster_type 'null' not supported",安装完后,启动heartbeat, /etc/init.d/heartbeat start, 然后...你就会发现报错,因为没有配置文件,/etc/ha.d/ha.cf

 

autojoin none
logfile /var/log/ha.log
mcast eth0 230.8.8.8 695 1 0
warntime 5
deadtime 15
initdead 60
keepalive 2
node linux-x86-HA1
node linux-x86-HA2
crm respawn

 

可以看到,日志文件是/var/log/ha.log,使用multi-broacasting eth0, 最后一行说明使用pacemaker作为crm(Cluster Resource Manager)。

 

刚才说了,slse自带的pacemaker不支持heartbeat,所以要去网上下载source code,自己重新编译。

http://hg.clusterlabs.org/pacemaker/stable-1.0/archive/tip.tar.bz2

 

编译的时候记得加参数 ./configure --enable_fatal_warnings=no --with-heartbeat。

 

不知道怎么配置pacemaker,但是可以用以下方解决pacemaker和heartbeat的配置问题

/usr/var/run> ln -s /usr/lib64/heartbeat .

 

pacemaker作为资源管理器,需要配置资源。crm是资源配置管理的界面。如果crm可以成功连接到cluster,说明之前的配置成功了。下面举个例子说明怎么配置一个failover的resource。

# crm_mon -n

============
Last updated: Sat Nov 27 22:27:22 2010
Stack: Heartbeat
Current DC: linux-x86-ha2 (1a5aaae0-a655-4c70-a980-f41d92ab6128) - par
tition with quorum
Version: 1.0.10-b2e39d318fda501e2fcf223c2d039b721f3679a9
2 Nodes configured, unknown expected votes
1 Resources configured.
============

Node linux-x86-ha2 (1a5aaae0-a655-4c70-a980-f41d92ab6128): online
Node linux-x86-ha1 (89cb9d86-3385-4a9d-932e-21a926211292): online
        example_anything        (ocf::heartbeat:anything) Started

 

可以看到,这个集群里有两个节点,crm是资源管理器,他可以根据不同的资源定义来管理资源,pacemaker支持的resource agent可以从这里查到  http://linux-ha.org/wiki/Resource_agents

 

这里我使用ocf:heartbeat:anything,这个resource agent是比较简单的资源代理,只是简单的管理进程,我们可以用crm命令来配置资源。http://www.clusterlabs.org/doc/crm_cli.html

 # crm
crm(live)# configure
crm(live)configure# property stonith-enabled=false
crm(live)configure# primitive example_anything ocf:heartbeat:anything \
	params binfile="/home/sogadm/HA/resource/resource" \
	params monitor_hook="/home/sogadm/HA/resourceAgent/myResourceAgent.sh" \
	params logfile="/home/sogadm/HA/resourceAgent/myResource.log" \
	params logfile="/home/sogadm/HA/resourceAgent/myResourceErr.log" \
	op monitor interval="10" timeout="20s" depth="0" \
crm(live)configure#commit

这里首先disable stonith, 可以看到定义了可执行程序

 

params binfile="/home/sogadm/HA/resource/resource" \

 

定义了管理程序,一般都是脚本

 

params monitor_hook="/home/sogadm/HA/resourceAgent/myResourceAgent.sh"

 

根据规范,这个管理程序需要可以接受以下参数和输出标准

start		start the service
stop		stop the service
restart		stop and restart the service if the service is already running, otherwise start the service
try-restart	restart the service if the service is already running
reload		cause the configuration of the service to be reloaded without actually stopping and restarting the service
force-reload	cause the configuration to be reloaded if the service supports this, otherwise restart the service if it is running
status		print the current status of the service

 

0	program is running or service is OK
1	program is dead and /var/run pid file exists
2	program is dead and /var/lock lock file exists
3	program is not running
4	program or service status is unknown
5-99	reserved for future LSB use
100-149	reserved for distribution use
150-199	reserved for application use
200-254	reserved

 

 http://refspecs.linux-foundation.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html

 

配置完后就可以看到资源的情况,也可以切换到其他节点

 

linux-x86-HA1:~/Desktop # crm
crm(live)# resource 
crm(live)resource# show
 example_anything	(ocf::heartbeat:anything) Started 
crm(live)resource# status example_anything
resource example_anything is running on: linux-x86-ha1 
crm(live)resource# move example_anything linux-x86-ha2
crm(live)resource# status example_anything
resource example_anything is running on: linux-x86-ha2 

 

到这里,简单的安装配置HA成功了。

 

可以看到,用户接触到的只是CRM,和底层用的是heartbeat还是openAIS用户是感觉不到的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值