免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 11568 | 回复: 10
打印 上一主题 下一主题

分享:heartbeat 2.x style的配置(使用cib.xml) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-12-07 14:20 |只看该作者 |倒序浏览
一) 前言:

网上关于heartbeat的文章很多,但大部分是基于1.x style的,

我把我配置的2.x style的heartbeat 过程发出来,

希望对大家能有一点用,

2.x和1.x最主要的区别在于,

1) 2.x支持CRM管理,资源文件由原来的haresources变为cib.xml,

2) 支持OCF格式的resource agent,

3) 可以对多资源组进行独立监控(这点我不确定在1.x里是否可以,没试过)

4)支持多节点

二) 配置

本文假设原有的heartbeat 已经配置好且能正常工作,
如和配置heartbeat不属于本文讨论范围.

我这里以两节点为例:
node1 和node2,
有两个资源作HA,apache和jboss,
其中apache使用vip :192.168.1.205,
jboss无vip,

1)在ha.cf里面增加
        crm yes
        apiauth cibmon   uid=hacluster
        respawn hacluster /usr/local/lib/heartbeat/cibmon -d

2)将haresources资源文件转换成cib.xml,2.x里编译好后自带有转换脚本,很方便.
        假设haresources文件如下,
        node1 192.168.1.205 runhttpd.sh
        node2 runjboss.sh
        每一行表示一个资源组,
        node1,node2表示prefered node,即该资源组优先在该node上运行,
        192.168.1.205与runhttpd.sh一起属于第一个资源组,为提供http服务的vip,
        启动的时候从左到右依次运行脚本,关闭的时候从右到左依次关闭.
        a):转换命令
        /usr/local/lib/heartbeat/haresources2cib.py --stout -c /usr/local/etc/ha.d/ha.cf /usr/local/etc/ha.d/haresources
        b):这一步可选
        清空/usr/local/etc/ha.d/haresources
        echo "" > /usr/local/etc/ha.d/haresources


3)
        修改heartbeat目录权限,可以用以下命令:
        find / -type d -name "heartbeat" -exec chown -R hacluster {} \;
        find / -type d -name "heartbeat" -exec chgrp -R haclient {} \;


4)LSB格式的resource agent script中必须支持status功能
                    所谓的resource agent就是服务的启动脚本,这我这里叫runhttpd.sh,runjboss等,
                    必须能接收start,stop,status,三个参数,如果是OCF格式agent,则必须支持
                    start,stop,monitor三个参数.其中status和monitor参数是用来监控资源的,非常重要.
        例如LSB风格的脚本,运行./runhttpd.sh status时候,
        返回值包含OK或则running则表示资源正常
        返回值包含stopped或者No则表示资源不正常。

        假如是OCF风格的脚本,运行./runhttpd.sh monitor时候,
        返回0表示资源是正常的,
        返回7表示资源出现问题.

三) 与1.x相比的区别

与1.x风格相比,功能变化:

1)保留原有所有功能
        如,网络,heartbeat ,机器down了时候均可以切换资源。

2)自动监控资源
        每2分钟检测资源运行情况,如果发现资源不在,则尝试启动资源,
        如果60s后还未启动成功,则资源切换向另节点。时间可以修改。
         <primitive class="heartbeat" id="runhttpd.sh_2" provider="heartbeat" type="runhttpd.sh">
           <operations>
             <op id="runhttpd.sh_2_mon" interval="120s" name="monitor" timeout="60s"/>
           </operations>
         </primitive>
        对VIP的监控,每5S监控一次,若vip失效,则尝试重启vip,timeout时间为5s,若5s后启动不成功,则切换向另节点。
         <primitive class="ocf" id="IPaddr_192_168_1_205" provider="heartbeat" type="IPaddr">
           <operations>
             <op id="IPaddr_192_168_1_205_mon" interval="5s" name="monitor" timeout="5s"/>
           </operations>
           <instance_attributes id="IPaddr_192_168_1_205_inst_attr">
             <attributes>
               <nvpair id="IPaddr_192_168_1_205_attr_0" name="ip" value="192.168.1.205"/>
             </attributes>
           </instance_attributes>
         </primitive>

3)可以对各资源组实现独立监控.
        比如jboss运行在node1上,apache运行在node2上,

4)同时监控系统负载
        可以自动将资源切换到负载低的node上


四) CRM管理程序crm_resource功能示例:

Examples
1)查看所有资源

  crm_resource -L

2)查看资源跑在哪个节点上

  crm_resource -W -r runhttpd.sh_2

  resource runhttpd.sh_2 is running on: server1

  crm_resource -W -r runhttpd.sh_2

  resource runhttpd.sh_2 is NOT running

4)启动/停止资源

  crm_resource -r runhttpd.sh_2 -p target_role -v started
  crm_resource -r runhttpd.sh_2 -p target_role -v stopped

5)查看资源在cib.xml中的定义

  crm_resource -x -r runhttpd.sh_2

6)将资源从当前节点移动向另个节点

  crm_resource -M -r runhttpd.sh_2

7)将资源移向指定节点

  crm_resource -M -r runhttpd.sh_2 -H c001n02

允许资源回到正常的节点

  crm_resource -U -r runhttpd.sh_2

NOTE: the values of resource_stickiness and default_resource_stickiness may mean that it doesnt move back. In such cases, you should use -M to move it back and then run this command.

9)将资源从CRM中删除

  crm_resource -D -r runhttpd.sh_2 -t primitive

10)将资源组从CRM中删除

  crm_resource -D -r my_first_group -t group

11)将资源从CRM中禁用

  crm_resource -p is_managed -r runhttpd.sh_2 -t primitive -v off

12)将资源从新从CRM中启用

  crm_resource -p is_managed -r runhttpd.sh_2 -t primitive -v on

13)Resetting a failed resource after having been manually cleaned up

  crm_resource -C -H c001n02 -r runhttpd.sh_2

14)检查所有节点上未在CRM中的资源

  crm_resource -P

15)检查指定节点上未在CRM中的资源

  crm_resource -P -H c001n02

Querying a parameter of a resource. Say the resource is the following:
<primitive id="example_mail" class="ocf" type="MailTo" provider="heartbeat">
  <instance_attributes id="example_mail_inst">
    <attributes>
      <nvpair id="example_mail_inst_attr0" name="email" value="root"/>
      <nvpair id="example_mail_inst_attr1" name="subject" value="Example Failover"/>
    </attributes>
  </instance_attributes>
</primitive>

You could query the email address using the following:
  crm_resource -r example_mail -g email

16)设置资源的某个属性

crm_resource -r example_mail -p email -v "myemailaddress@somedomain.com"


写的比较匆忙,有错误的地方请指正.

欢迎转载,修改,不需要标明作者,不过最好请标明来自CU.

参考文档:www.linux-ha.org

论坛徽章:
0
2 [报告]
发表于 2007-12-09 11:36 |只看该作者
good ,不过有 hagui这样的图形界面配置工具,大家可以用这个图形工具去配置。

另外,newstar ha是基于heartbeat,如果能放出他们的配置工具就更好了。(如果他们愿意遵守gpl协议的话)

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:50:39
3 [报告]
发表于 2007-12-11 11:48 |只看该作者
有没有试过将IPaddr + drbd + Filesystem + service(apache, ftp etc.)的全部使用ocf RA的例子?我正在研究这玩意,有很多问题。最好还能用上pingd作为连接的监控进程。

论坛徽章:
0
4 [报告]
发表于 2007-12-11 12:33 |只看该作者
好东西 谢谢分享
2楼图形配置?
有几台服务器装了图形界面?

论坛徽章:
0
5 [报告]
发表于 2007-12-20 13:34 |只看该作者
2.x的图形配置工具很复杂,折腾了很久

论坛徽章:
0
6 [报告]
发表于 2007-12-21 13:37 |只看该作者
好东西。一定要定。目前还没有详细说2.X的新资源配置文件的文档呢。

论坛徽章:
0
7 [报告]
发表于 2007-12-22 22:55 |只看该作者
对hb不熟悉,赞一个

论坛徽章:
0
8 [报告]
发表于 2008-01-14 11:17 |只看该作者
楼主对2.0的基本配置说的不是很详细。刚弄完了1.0的功能,正在捣腾CRM。资料不多,碰到了这篇文章真是庆幸,感谢一下。

论坛徽章:
0
9 [报告]
发表于 2008-01-23 16:43 |只看该作者
这几天主要在看HEARTBEAT,对楼主的文章提个疑问吧:

2)将haresources资源文件转换成cib.xml,2.x里编译好后自带有转换脚本,很方便.
        假设haresources文件如下,
        node1 192.168.1.205 runhttpd.sh
        node2 runjboss.sh
        每一行表示一个资源组,

在这一段中runhttpd.sh这个脚本,原因我不是很理解,如果针对VIP的话,其实没必要,直接写个node1 192.168.1.205 apache(apache的默认启动脚本)即可,HEARTBEAT可以自动增加个接口并赋予IP192.168.1.205。或许楼主的意思runhttpd.sh就是代表的默认的apache的启动脚本,那就是我误解了。如果不是的话还请楼主把这个脚本的程序内容贴出来让大家学习一下

论坛徽章:
0
10 [报告]
发表于 2008-07-15 11:37 |只看该作者
我发现heartbeat v2.1.3的haresource2cib.py转换ipaddr有问题,会把nic和netmask颠倒,需要手动修改回来
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP