在Suse10下尝试编译安装配置Linux-HA
时间:2006-07-21 来源:icymoon
(零)系统环境:
两台Suse Linux 10
假设其IP为x.x.x.1和x.x.x.2(使用ifconfig查看)
主机名为ha1与ha2(使用uname -n查看)
gcc v4, python
(一)下载
http://linux-ha.org/download/index.html
可以下载源码,也可以根据系统需要选择下载rpm包等
本例中使用了CVS源码。
(二)编译&安装
1.解压
#tar -zvxf heartbeat-2.0.5.tar.gz
2.添加系统用户(如果是RPM安装则无需手动添加)
编辑/etc/group,加入
haclient:x:90:
编辑/etc/passwd,加入
hacluster:x:90:90:icymoon:/home:/bin/false
或者
#groupadd -g 90 haclient
#useradd -g 90 hacluster
3.Configure, make, make install
#cd heartbeat-2.0.5
#./ConfigureMe configure
make
make install
注意:需要python-devel包中的Python.h、pam-devel包中的security/pam_appl.h和GNU/TLS的支持才可以使用图形界面的管理工具。
(三)配置
//version 2的配置和version 1有所差别,安装过程也有部分配置文件不自动copy到相关目录 下,所以得手动从源码目录中copy并修改
一共有三个配置文件:
软件参数 ha.cf
认证信息配置 authkeys
资源配置
(1)ha.cf(/etc/ha.d下)
注意:不要改动文件中各项配置的顺序!
Eg:
----------------------------------------
logfacility local0 #如果上面的logfile未被定义,则日志全部送往local0,即/var/log/messages
#以下是设置一些时间相关的参数,默认以s为单位,也可以使用<数字ms>的形式以ms为单位。
keepalive 1 #每次心跳信息的间隔时间
deadtime 5 #多长时间没收到心跳信息就判断节点为不可用
warntime 3 #报警时间(应该小于deadtime)
initdead 10 #在一些机器/系统中,系统起动后网卡需要一段时间才会开始工作 ,基于此,在起动时使用此项来代替deadtime.此项至少要设置为deadtime的两倍。
udpport 694 #使用bcast或者ucast时候的UDP端口
ucast eth0 x.x.x.2 #指定通信设备与目标地址,此处使用了ucast
node ha1 #指定集群内的节点
node ha2
crm yes #Version 2的新功能,使用CRM(Cluster Resource Management)
------------------------------------------
其他部分选项的说明:
#debugfile /var/log/ha-debug
#logfile /var/log/ha-log
分别指定debug与其它信息写入的位置
#baud 19200
使用串口通信时的波特率
#serial /dev/ttyS0 # Linux
#serial /dev/cuaa0 # FreeBSD
#serial /dev/cua/a # Solaris
串口通信设备的选择,linux-ha支持多种通信方式
#bcast eth0 # Linux
#bcast eth1 eth2 # Linux
#bcast le0 # Solaris
#bcast le1 le2 # Solaris
选择广播心跳信息的设备
#mcast eth0 225.0.0.1 694 1 0
多播方式发送心跳信息,格式为mcast [设备] [多播组] [端口] [ttl] [loop]
#auto_failback on
当拥有该资源的机器恢复后,是否将服务进行回迁。
例如,如果最初服务运行在ha1上,ha1故障后交由ha2运行,这个选项决定了在ha1恢复后,ha2是否把服务交还给ha1在两台机器性能相等的情况下,是没有必要的,但如果两台机器性能差异较大,则尽量保证服务运行在性能较好的机器上为好。
#stonith baytech /etc/ha.d/conf/stonith.baytech
用于共享资源的集群环境中,是否采用stonith防御技术来保证数据的一致性,格式为 stonith <设备类型> <配置文件>
#watchdog /dev/watchdog
此项为可选项。可以让系统发现自己没有心跳信息的时候重起。如果使用,需要加载softdog的模块(insmod softdog)。
#ping 10.10.10.254
#ping_group group1 10.10.10.254 10.10.10.253
ping集群以外的节点来检查自己的网络是否正常
#respawn userid /path/name/to/run
#respawn hacluster /usr/lib/heartbeat/ipfail
指定与heartbeat一起启动与停止的进程
(2)authkeys(/etc/ha.d)
格式如下:
auth <number>
<number> <authmethod> [<authkey>]
注意:两节点的此配置文件必须相同!
其中,authmethod指定认证所用的算法,支持crc、sha1与md5
例如:
auth 1
1 sha1 password
(3)/var/lib/heartbeat/crm/cib.xml
在2.x版本中,不再使用haresources做CRM,而是使用/var/lib/heartbeat/crm/cib.xml代替。
在1.x版本中,每个节点的haresources文件必须是相同的,否则会引发错误。而在2.x中则可自动从集群内别的节点进行同步。
Eg:
---------------------------------------------
<cib>
<configuration>
<crm_config/>
<nodes/>
<resources>
<primitive id="ip_resource_1" class="ocf" type="IPaddr" provider="heartbeat"> <instance_attributes>
<attributes>
<nvpair name="ip" value="1.2.3.4"/>
</attributes>
</instance_attributes>
</primitive>
<primitive id="ip_resource_2" class="ocf" type="IPaddr" provider="heartbeat"> <instance_attributes>
<attributes>
<nvpair name="ip" value="1.2.3.5"/>
</attributes>
</instance_attributes>
</primitive>
</resources>
<constraints>
<rsc_location id="run_ip_resource_1" rsc="ip_resource_1">
<rule id="pref_run_ip_resource_1" score="100">
<expression attribute="#uname" operation="eq" value="paul"/>
</rule>
</rsc_location>
<rsc_location id="run_ip_resource_2" rsc="ip_resource_2">
<rule id="pref_run_ip_resource_2" score="100">
<expression attribute="#uname" operation="eq" value="silas"/>
</rule>
</rsc_location>
</constraints>
</configuration>
<status/>
</cib>
---------------------------------------------
(四)测试与使用
(1)进程启动|停止
#/etc/init.d/heartbeat start|stop
(2)图形界面的使用
#/usr/lib/heartbeat/haclient.py &
(3)其它工具
hb_addnode 向集群中添加节点
hb_delnode 从集群中删除节点
mgmtdtest 似乎有问题???
(五)参考
www.linux-ha.org
wiki.linux-ha.org
(六)其它
File: heartbeat/heartbeat.c
Func: main()->get_localnodeinfo()
main()调用get_localnodeinfo()来得到节点名。先通过uname(),然后又读取HA_D/nodeinfo。在实际使用中,/etc/ha.d/nodeinfo文件可以用于配置节点名,没有也可,但写错了会导致heartbeat无法启动。
File: lib/plugins/HBcomm/ucast.c
Func: ucast_init()
里面只检查了通信用的udp端口是否小于0,没有检查>65535的情况。
两台Suse Linux 10
假设其IP为x.x.x.1和x.x.x.2(使用ifconfig查看)
主机名为ha1与ha2(使用uname -n查看)
gcc v4, python
(一)下载
http://linux-ha.org/download/index.html
可以下载源码,也可以根据系统需要选择下载rpm包等
本例中使用了CVS源码。
(二)编译&安装
1.解压
#tar -zvxf heartbeat-2.0.5.tar.gz
2.添加系统用户(如果是RPM安装则无需手动添加)
编辑/etc/group,加入
haclient:x:90:
编辑/etc/passwd,加入
hacluster:x:90:90:icymoon:/home:/bin/false
或者
#groupadd -g 90 haclient
#useradd -g 90 hacluster
3.Configure, make, make install
#cd heartbeat-2.0.5
#./ConfigureMe configure
make
make install
注意:需要python-devel包中的Python.h、pam-devel包中的security/pam_appl.h和GNU/TLS的支持才可以使用图形界面的管理工具。
(三)配置
//version 2的配置和version 1有所差别,安装过程也有部分配置文件不自动copy到相关目录 下,所以得手动从源码目录中copy并修改
一共有三个配置文件:
软件参数 ha.cf
认证信息配置 authkeys
资源配置
(1)ha.cf(/etc/ha.d下)
注意:不要改动文件中各项配置的顺序!
Eg:
----------------------------------------
logfacility local0 #如果上面的logfile未被定义,则日志全部送往local0,即/var/log/messages
#以下是设置一些时间相关的参数,默认以s为单位,也可以使用<数字ms>的形式以ms为单位。
keepalive 1 #每次心跳信息的间隔时间
deadtime 5 #多长时间没收到心跳信息就判断节点为不可用
warntime 3 #报警时间(应该小于deadtime)
initdead 10 #在一些机器/系统中,系统起动后网卡需要一段时间才会开始工作 ,基于此,在起动时使用此项来代替deadtime.此项至少要设置为deadtime的两倍。
udpport 694 #使用bcast或者ucast时候的UDP端口
ucast eth0 x.x.x.2 #指定通信设备与目标地址,此处使用了ucast
node ha1 #指定集群内的节点
node ha2
crm yes #Version 2的新功能,使用CRM(Cluster Resource Management)
------------------------------------------
其他部分选项的说明:
#debugfile /var/log/ha-debug
#logfile /var/log/ha-log
分别指定debug与其它信息写入的位置
#baud 19200
使用串口通信时的波特率
#serial /dev/ttyS0 # Linux
#serial /dev/cuaa0 # FreeBSD
#serial /dev/cua/a # Solaris
串口通信设备的选择,linux-ha支持多种通信方式
#bcast eth0 # Linux
#bcast eth1 eth2 # Linux
#bcast le0 # Solaris
#bcast le1 le2 # Solaris
选择广播心跳信息的设备
#mcast eth0 225.0.0.1 694 1 0
多播方式发送心跳信息,格式为mcast [设备] [多播组] [端口] [ttl] [loop]
#auto_failback on
当拥有该资源的机器恢复后,是否将服务进行回迁。
例如,如果最初服务运行在ha1上,ha1故障后交由ha2运行,这个选项决定了在ha1恢复后,ha2是否把服务交还给ha1在两台机器性能相等的情况下,是没有必要的,但如果两台机器性能差异较大,则尽量保证服务运行在性能较好的机器上为好。
#stonith baytech /etc/ha.d/conf/stonith.baytech
用于共享资源的集群环境中,是否采用stonith防御技术来保证数据的一致性,格式为 stonith <设备类型> <配置文件>
#watchdog /dev/watchdog
此项为可选项。可以让系统发现自己没有心跳信息的时候重起。如果使用,需要加载softdog的模块(insmod softdog)。
#ping 10.10.10.254
#ping_group group1 10.10.10.254 10.10.10.253
ping集群以外的节点来检查自己的网络是否正常
#respawn userid /path/name/to/run
#respawn hacluster /usr/lib/heartbeat/ipfail
指定与heartbeat一起启动与停止的进程
(2)authkeys(/etc/ha.d)
格式如下:
auth <number>
<number> <authmethod> [<authkey>]
注意:两节点的此配置文件必须相同!
其中,authmethod指定认证所用的算法,支持crc、sha1与md5
例如:
auth 1
1 sha1 password
(3)/var/lib/heartbeat/crm/cib.xml
在2.x版本中,不再使用haresources做CRM,而是使用/var/lib/heartbeat/crm/cib.xml代替。
在1.x版本中,每个节点的haresources文件必须是相同的,否则会引发错误。而在2.x中则可自动从集群内别的节点进行同步。
Eg:
---------------------------------------------
<cib>
<configuration>
<crm_config/>
<nodes/>
<resources>
<primitive id="ip_resource_1" class="ocf" type="IPaddr" provider="heartbeat"> <instance_attributes>
<attributes>
<nvpair name="ip" value="1.2.3.4"/>
</attributes>
</instance_attributes>
</primitive>
<primitive id="ip_resource_2" class="ocf" type="IPaddr" provider="heartbeat"> <instance_attributes>
<attributes>
<nvpair name="ip" value="1.2.3.5"/>
</attributes>
</instance_attributes>
</primitive>
</resources>
<constraints>
<rsc_location id="run_ip_resource_1" rsc="ip_resource_1">
<rule id="pref_run_ip_resource_1" score="100">
<expression attribute="#uname" operation="eq" value="paul"/>
</rule>
</rsc_location>
<rsc_location id="run_ip_resource_2" rsc="ip_resource_2">
<rule id="pref_run_ip_resource_2" score="100">
<expression attribute="#uname" operation="eq" value="silas"/>
</rule>
</rsc_location>
</constraints>
</configuration>
<status/>
</cib>
---------------------------------------------
(四)测试与使用
(1)进程启动|停止
#/etc/init.d/heartbeat start|stop
(2)图形界面的使用
#/usr/lib/heartbeat/haclient.py &
(3)其它工具
hb_addnode 向集群中添加节点
hb_delnode 从集群中删除节点
mgmtdtest 似乎有问题???
(五)参考
www.linux-ha.org
wiki.linux-ha.org
(六)其它
File: heartbeat/heartbeat.c
Func: main()->get_localnodeinfo()
main()调用get_localnodeinfo()来得到节点名。先通过uname(),然后又读取HA_D/nodeinfo。在实际使用中,/etc/ha.d/nodeinfo文件可以用于配置节点名,没有也可,但写错了会导致heartbeat无法启动。
File: lib/plugins/HBcomm/ucast.c
Func: ucast_init()
里面只检查了通信用的udp端口是否小于0,没有检查>65535的情况。
相关阅读 更多 +