天天看点

Heartbeat--haresources配置文件详解

转自:http://blog.sina.com.cn/s/blog_7b6fc4c901012ols.html

资源文件(/etc/ha.d/haresources)

Haresources文件用于指定双机系统的主节点、集群IP、子网掩码、广播地址以及启动的服务等集群资源,文件每一行可以包含一个或多个资源脚本名,资源之间使用空格隔开,参数之间使用两个冒号隔开,在两个HA节点上该文件必须完全一致,此文件的一般格式为:

  1. node-name network  <resource-group> 
  1. node1 IPaddr::192.168.60.200/24/eth0/  Filesystem:: /dev/sdb5::/webdata::ext3  httpd tomcat 

node-name表示主节点的主机名,必须和ha.cf文件中指定的节点名一致。network用于设定集群的IP地址、子网掩码和网络设备标识 等。需要注意的是,这里指定的IP地址就是集群对外服务的IP地址,resource-group用来指定需要Heartbeat托管的服务,也就是这些 服务可以由Heartbeat来启动和关闭。如果要托管这些服务,就必须将服务写成可以通过start/stop来启动和关闭的脚步,然后放到/etc /init.d/或者/etc/ha.d/resource.d/目录下,Heartbeat会根据脚本的名称自动去/etc/init.d或者/etc /ha.d/resource.d/目录下找到相应脚步进行启动或关闭操作。

下面对配置方法进行具体说明:

其中,node1是HA集群的主节点,IPaddr为heartbeat自带的一个执行脚 步,Heartbeat首先将执行/etc/ha.d/resource.d/IPaddr 192.168.60.200/24 start的操作,也就是虚拟出一个子网掩码为255.255.255.0,IP为192.168.60.200的地址。此IP为Heartbeat对外 提供服务的网络地址,同时指定此IP使用的网络接口为eth0。接着,Heartbeat将执行共享磁盘分区的挂载操 作,"Filesystem::/dev/sdb5::/webdata::ext3"相当于在命令行下执行mount操作,即"mount -t ext3 /dev/sdb5 /webdata",最后依次启动httpd和Tomcat服务。

注意 主节点和备份节点中资源文件haresources要完全一样。

转自:http://blog.sina.com.cn/s/blog_7b6fc4c901012ols.html

# This is a list of resources that move from machine to machine as

# nodes go down and come up in the cluster.  Do not include

# "administrative" or fixed IP addresses in this file.

# 集群中的节点停机和启动时,这里配置的资源列表会从一个节点转移到另一个节点, 不过资源列表中不要包含管理或已经配置在服务器上的IP地址在这个文件中。

#

# <VERY IMPORTANT NOTE>

# The haresources files MUST BE IDENTICAL on all nodes of the cluster.

# 此haresources文件在所有的集群节点中都必须相同

# The node names listed in front of the resource group information

# is the name of the preferred node to run the service.  It is

# not necessarily the name of the current machine.  If you are running

# auto_failback ON (or legacy), then these services will be started

# up on the preferred nodes - any time they're up.

# 列在resource组信息前的节点名称是主机的hostname,它不需要是当前机器的名称,如果你配置auto_failback on(或者

# legacy),那么这些服务将会在主机上启动,只要主机是运行的。

#

# If you are running with auto_failback OFF, then the node information

# will be used in the case of a simultaneous start-up, or when using

# the hb_standby {foreign,local} command.

# 如果你配置的是auto_failback off,那么节点信息将使用在同时启动的情况,或当使用hb_standby {foreign,local}命令时。

# BUT FOR ALL OF THESE CASES, the haresources files MUST BE IDENTICAL.

# If your files are different then almost certainly something

# won't work right.

# 但是对于所有的这些情况,此haresources文件都必须相同。如果你的文件不同那么肯定有某些东西将不能正常工作。

# </VERY IMPORTANT NOTE>

#

# We refer to this file when we're coming up, and when a machine is being

# taken over after going down.

# 在开机和一个机器停机后被接管的时候会参考这个文件。

#

# You need to make this right for your installation, then install it in

# /etc/ha.d

# 安装时把它放到/etc/ha.d目录。

#

# Each logical line in the file constitutes a "resource group".

# A resource group is a list of resources which move together from

# one node to another - in the order listed.  It is assumed that there

# is no relationship between different resource groups.  These

# resource in a resource group are started left-to-right, and stopped

# right-to-left.  Long lists of resources can be continued from line

# to line by ending the lines with backslashes ("").

# 在文件里面的每个逻辑行组成一个“resource group”。一个resource group就是从一个节点切换到另一个节点时的resources列表。

# 可以假设不同的resource groups之间是没有关系的。resource group的resource启动时是从左到右的。关闭时是从右到左的。

# 长的resources列表可以以反斜杠(“\”)结尾来续行。

#

# These resources in this file are either IP addresses, or the name

# of scripts to run to "start" or "stop" the given resource.

# 在 这个文件里面的resources可以是IP地址,也可以是用于“start”或“stop”给定的resource的脚本名称

#

# The format is like this:

#

#node-name resource1 resource2 ... resourceN

#

# If the resource name contains an :: in the middle of it, the

# part after the :: is passed to the resource script as an argument.

#       Multiple arguments are separated by the :: delimeter

# 如果resource的名称包含一个::在它的中间,在::后面的部分会传递给resource的脚本中作为一个参数,多个参数会以::分割。

#

# In the case of IP addresses, the resource script name IPaddr is implied.

# 在IP地址的情况中,resource脚本名称IPaddr是隐含的。

#

# For example, the IP address 135.9.8.7 could also be represented

# as IPaddr::135.9.8.7

# 例如:IP地址135.9.8.7也可以被表现为IPaddr::135.9.8.7

#

# THIS IS IMPORTANT!!     vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

#

# The given IP address is directed to an interface which has a route

# to the given address.  This means you have to have a net route

# set up outside of the High-Availability structure.  We don't set it

# up here -- we key off of it.

# 给定的IP地址会直接连到有路由到给定的地址的接口上,这也就意味着你必须要在 High-Availability 外部配置一个网络路由。

#

# The broadcast address for the IP alias that is created to support

# an IP address defaults to the highest address on the subnet.

# IP别名的广播地址将被缺省创建为支持IP地址的子网里的最高地址

#

# The netmask for the IP alias that is created defaults to the same

# netmask as the route that it selected in in the step above.

# IP别名的子网掩码将被缺省创建为与上面选择的路由相同的子网掩码

#

# The base interface for the IPalias that is created defaults to the

# same netmask as the route that it selected in the step above.

# IP别名的基础接口将被缺省创建为与上面选择的路由相同的子网掩码

#

# If you want to specify that this IP address is to be brought up

# on a subnet with a netmask of 255.255.255.0, you would specify

# this as IPaddr::135.9.8.7/24 .  

# 如果你想要指定某个IP地址用指定的子网掩码来启动,那么像这样指定它 IPaddr::135.9.8.7/24

#

# If you wished to tell it that the broadcast address for this subnet

# was 135.9.8.210, then you would specify that this way:

#  IPaddr::135.9.8.7/24/135.9.8.210

# 如果你想要指明这个子网的广播地址为135.9.8.210,那么可以像这样指定 IPaddr::135.9.8.7/24/135.9.8.210

#

# If you wished to tell it that the interface to add the address to

# is eth0, then you would need to specify it this way:

#  IPaddr::135.9.8.7/24/eth0

# 如果你希望指明要增加地址的接口是eth0,那么你需要像这样指定 IPaddr::135.9.8.7/24/eth0

#

#       And this way to specify both the broadcast address and the

#       interface:

#  IPaddr::135.9.8.7/24/eth0/135.9.8.210

# 同时指定广播地址和接口的方法为:

#  IPaddr::135.9.8.7/24/eth0/135.9.8.210

#

# The IP addresses you list in this file are called "service" addresses,

# since they're the publicly advertised addresses that clients

# use to get at highly available services.

# 列表在这个文件中的IP地址叫做服务地址,它们是客户端用于获取高可用服务的公共通告地址

#

# For a hot/standby (non load-sharing) 2-node system with only a single service address, 

# you will probably only put one system name and one IP address in here.

# The name you give the address to is the name of the default "hot"

# system.

# 对于一个hot/standby(非共享负载)单服务地址的双节点系统,你可能只需要放置一个系统名称和一个IP地址在这里。你给定的地址对应的名字就是缺省的hot系统的名字。

#

# Where the nodename is the name of the node which "normally" owns the

# resource.  If this machine is up, it will always have the resource

# it is shown as owning.

# 节点名称就是正常情况下拥有resource的节点的名称。如果此机器是up的,他将一直拥有以拥有显示的resource。

#

# The string you put in for nodename must match the uname -n name

# of your machine.  Depending on how you have it administered, it could

# be a short name or a FQDN.

# 设置作为节点名称的字符串必须匹配在机器上使用uname -n获得的名字。基于你如果进行管理,它可能是一个缩写名称或一个FQDN。

#

# Simple case: One service address, default subnet and netmask

#  No servers that go up and down with the IP address

# 简单情况:一个服务地址,缺省子网和掩码,没有服务与IP地址一起启动和关闭

#

#just.linux-ha.org 135.9.216.110

#

# Assuming the adminstrative addresses are on the same subnet...

# A little more complex case: One service address, default subnet

# and netmask, and you want to start and stop http when you get

# the IP address...

# 假定管理地址在相同的子网...

# 稍微复杂一些的情况:一个服务地址,缺省子网和子网掩码,同时你要在获得IP地址的时候启动和停止http。

#

#just.linux-ha.org 135.9.216.110 http

#-------------------------------------------------------------------

#

# A little more complex case: Three service addresses, default subnet

# and netmask, and you want to start and stop http when you get

# the IP address...

# 稍微复杂一些的情况:三个服务地址,缺省子网和掩码,同时你要在获得IP地址的时候启动和停止http。

#

#just.linux-ha.org 135.9.216.110 135.9.215.111 135.9.216.112 httpd

#-------------------------------------------------------------------

#

# One service address, with the subnet, interface and bcast addr

#       explicitly defined.

# 一个服务地址,显式指定子网,接口,广播地址

#

#just.linux-ha.org 135.9.216.3/28/eth0/135.9.216.12 httpd

#

#-------------------------------------------------------------------

#

#       An example where a shared filesystem is to be used.

#       Note that multiple aguments are passed to this script using

#       the delimiter '::' to separate each argument.

# 一个使用共享文件系统的例子

# 需要注意用'::'分隔的多个参数被传递到了这个脚本

#

#node1  10.0.0.170 Filesystem::/dev/sda1::/data1::ext2

#

# Regarding the node-names in this file:

# 关于这个文件中的节点名称:

# They must match the names of the nodes listed in ha.cf, which in turn

# must match the `uname -n` of some node in the cluster.  So they aren't

# virtual in any sense of the word.

# 它们必须匹配在ha.cf中列出的节点名称,依次必须匹配集群中的某些节点'unmae -n'的结果。所以它们不是对于词的虚假感觉。

#

继续阅读