设为首页 收藏本站
查看: 1137|回复: 0

[经验分享] Linux High Availabi

[复制链接]
累计签到:2 天
连续签到:1 天
发表于 2018-5-24 12:37:20 | 显示全部楼层 |阅读模式
  What is theLinux High Availabi
      简介:
[size=1.16em]     高可用性群集的出现是为了使群集的整体服务尽可能可用,以便考虑计算硬件和软件的易错性。如果高可用性群集中的主节点发生了故障,那么这段时间内将由次节点代替它。次节点通常是主节点的镜像,所以当它代替主节点时,它可以完全接管其身份,并且因此使系统环境对于用户是一致的。
   DSC0000.jpg
  消息交换和基础结构层
主层或第一层是消息交换/基础结构层,也称为OpenAIS层。此层包含了发送含 有“我在线”信号的消息及其他信息的组件。High Availability Extension的程序就位于此消息交换/基础结构层。
资源分配层
下一层是资源分配层。此层最复杂,它包含以下组件:
群集资源管理器(CRM)
在资源分配层中执行的每个操作都要经过群集资源管理器。如果资源分配层 的其他组件(或更高层中的组件)需要通讯,则它们通过本地CRM进行。
在每个节点上,CRM维护群集信息库(CIB)[12],包含所有群集选项、节 点、资源及其关系和当前状态的定义。如果选择群集中的CRM为指定协调 程序(DC),则意味着它具有主CIB。群集中的所有其他CIB是此主CIB的 复本。对CIB的常规读写操作通过主CIB进行排序。DC是群集中唯一可以 决定需要在整个群集执行更改(例如节点屏障或资源移动)的实体。
群集信息库(CIB)
群集信息库是整个群集配置和当前状态在内存中的XML表示。它包含所有 群集选项、节点、资源、约束及其之间的关系的定义。CIB还将更新同步到 所有群集节点。群集中有一个主CIB,由DC维护。所有其
他节点包含一个CIB副本.
  

  

  策略引擎(PE)
每当指定防阏程序需贤进行整个鮮集的史改(对新CIB做出反应),策略引擎就会根据群集的当前状态和配置计算集群的下一个状态,PE还生成个转換图,包含用于达到下一个群集状态的(资源)操作和依赖性的列表,PE在每个节点上都运行以加速DC故障转移。
本地资源管理器(LRM)
LRM代表CRM调用本地资源代理(淸参见“资源层”一节[13])。因此它 吋以执行ft动/停Ih./监视操作并将结果报告给crm3它还隐藏资源代理支持 的脚本标准(OCF、LSB、Heartbeat VI)之间的区别。LRM是其本地节点上所有资源相关信息的权威来源.

  

  资源层
最高层是资源层。资源层包括一个或多个资源代理(RA)。资源代理是为启动、 停止和监视某种服务(资源) 而编写的程序,通常是壳层脚本。资源代理仅由LRM调用。第三方可将他们自己的代理放在文件系统中定义的位皆,这样就为各自的软件提供了现成群集集成。

  

  处理流程
      SUSE linux Enterprise High Availability Extension 使用 Pacemaker 作为 CRM, CRMf作为守护程序执行(crmd),它在每个集群节点上都有一个实例。Pacemaker 通过将某个crmd实例选为主实例,从而集中了所有的群集决策制定。如果选定的crmd进程(或它所在的节点)出现故障,则将建立一个新的进程。
在每个节点上保留了一个CIB,它反映了群集的配置和群集中所有资源的当前状态。CIB的内容会在整个群集的同步过程屮自动保留下来。
群集中执行的许多操作都将导致整个群集的更改。这些操作包括添加或删除群集资源、更改资源约约束等。了解执行这样的操作时群集中会发生的状况是很重要。
例如,假设您要添加一个群集IP地址资源。为此,您可以使用一种命令行工具, 或GUI修改C1.您不必在DC上执行此操作,可以使用群集中任何节点上的任何工具,此操作会被传送到DC上。然后DC将把此CIB更改复制到所有群集节点。
根据CIB中的信息,PE便计算群集的理想状态及如何达到此状态,并将指令列表传递给DC.DC通过消息交换/基础结构层发出命令,其他节点上的crmd同级将收到此命令《每个crmd使用它的LRM (作为Irmd实观)执行资源修改.lrmd不是群集感知的,它直接与资源代理(脚本)交互
所有同级节点将操作的结果报告给DC。一旦DC做出所有必需操作已在群集中成功执行的结论,群集将返回至空闲状态并等待进一步亊件。如果有操作末按计划执行,则会再次调用PE,CIB中将记录新信息。

  

  在某系情况下,可能需要关闭节点以保护共享数据或完成资源恢复。为此,pacemaker附带了一个屏障子系统,stonithd。STONITH是"shoot the other node in the head"(关闭其他节点)"的首字母缩写,通常通过一个远程电源开关实施。在pacemaker中将STONITH设备构造成资源(并在CIB中配置)以便它们监视故障;然而,stonithd负责了解STONITH拓扑,这样它的客户端只需请求屏障节点,余下的工作由它来完成。
  

  Linux High Availabi  资源类型:

  original

  原始资源是最基本的资源类型。
  group

  组包含一系列需要放置在一起的资源、按顺序启动和以反序停止的资源。
  组具有以下属性:
启动和停止资源
资源以显示顺序启动,以相反顺序停止。
相关性
如果组中某个资源在某处无法运行,则该组中位于其之后的任何资源都不允 许运行。
组内容
组可能仅包含一些原始群集资源。要引用组资源的子代,请使用子代的ID 代替组的ID。
限制
尽管在约束中可以引用组的子代,但通常倾向于使用组的名称。
黏性
黏性在组中可以累加。每个活动的组成员可以将其黏性值累加到组的总分 中。因此,如果默认的resource-stickiness值为100,而组中有七个 成员,其中五个成员是活动的,则组总分为500,更喜欢其当前位置。

  资源监控
  要为组启用资源监视,必须为组中每个要监视的资源分配监视。

  注意: 组必须包含至少一个资源,否则无效.
  Web 服务器的资源组

  资源组示例是需要IP地址和文件系统的Web服务器。在这种情况下,每个组件 都是一个会合并到群集资源组中的独立群集资源。资源组在一台或多台服务器 上运行,如果软件或硬件有故障,故障转移至群集中的另一台服务器上,这与 单个群集资源相同。
  如下图所示:
   DSC0001.jpg
  

  clone

      克隆是可以在多个主机上处于活动状态的资源。如果各个资源代理支持,则任何资源均可克隆。(集群文件系统,文件共享服务器)

  您可能希望某些资源在群集的多个节点上同时运行。为此,必须将资源配置为 克隆资源。可以配置为克隆资源的资源示例包括STOMTH和群集文件系统(如 0CFS2)。如果受资源的资源代理支持,则可以克隆任何资源。克隆资源的配 置甚至也有不同,具体取决于资源驻留的节点。
资源克隆有三种类型:
匿名克隆
这是最简单的克隆类型。这种克隆类型在所有位置上的运行方式都相同。因 此,每台计算机上只能有一个匿名克隆实例是活动的。
全局唯一克隆
这些资源各不相同。一个节点上运行的克隆实例与另一个节点上运行的实例 不同,同一个节点上运行的任何两个实例也不同。
状态克隆
这些资源的活动实例分为两种状态:主动和被动。有时也称为主要和辅助, 或主和从。状态克隆可以是匿名克隆也可以是全局唯一克隆。

  master

  主资源是一种特殊的克隆资源,主资源可以具有多种模式。主资源必须只能包含一个组或一个常规资源。
  master/slave
  主从资源主的能读能写,从的不能读也不能写
  

  

  

  

  Linux High Availabi   配置资源约束
  配置好所有资源只是完成了该作业的一部分。即便群集熟悉所有必需资源,它 可能还无法进行正确处理。资源约束允许您指定在哪些群集节点上运行资源、 以何种顺序装载资源,以及特定资源依赖于哪些其他资源。
提供三种不同的约束:

  
Resource Location (资源位置)
位置约束定义资源可以、不可以或首选在哪些节点上运行。 优先级(inf:无穷大、- inf: 负无穷大  n:指定优先级大小  -n :负优先级大小)

  
Resource Collocation (资源排列)
排列约束告诉群集资源可以或不可以在某个节点上一起运行。 inf:    排列约束:资源无论如何都要在一起  -inf: 资源老死不相往来 (在某台服务器上)

  

  

  Resource Order (资源顺序)
排序约束定义操作的顺序。 资源启动次序及关闭次序(比如 在启动web服务器的时候是先启动IP,还是先启动web服务进程呀!)

  

  定义约束时,还需要指定分数。各种分数是群集工作方式的重要组成部分。其 实,从迁移资源到决定在已降级群集中停止哪些资源的整个过程是通过以某种 方式操纵分数来实现的。分数按每个资源来计算,资源分数为负的任何节点都 无法运行该资源。在计算出资源分数后,群集选择分数最高的节点。INFINITY (无穷大)目前定义为1, 000, 000。加减无穷大遵循以下3个基本规则:
  任何值+无穷大=无穷大
  任何值-无穷大=-无穷大
  ◆无穷大-无穷大=-无穷大
      定义资源约束时,也可以指定每个约束的分数。分数表示您指派给此资源约束 的值。分数较高的约束先应用,分数较低的约束后应用。通过使用不同的分数 为既定资源创建更多位置约束,可以指定资源要故障转移至的目标节点的顺序
  

  

  指定资源故障回复节点(资源黏性)
当原始节点恢复联机并位于群集中时,资源可能会故障回复到该节点。如果希望阻止资源故障回复到故障转移前运行的节点上,或如果希望指定其他的节点让资源进行故障回复,则必须更改资源黏性值。在创建资源时或在创建资源后, 都可以指定指定资源黏性。
在指定资源黏性值时,请考虑以下情况:
值为0:
这是默认选项。资源放置在系统中的最适合位置。这意味着当负载能力“较好”或较差的节点变得可用时才转移资源。此选项的作用几乎等同于自动故障回复,只是资源可能会转移到非之前活动的节点上。
值大于0:
资源更愿意留在当前位置,但是如果有更合适的节点可用时会移动。值越高表示资源越愿意留在当前位置。
值小于0:
资源更愿意移离当前位置。绝对值越高表示资源越愿意离开当前位置。
值为 INFINITY:
如果不是因节点不适合运行资源(节点关机、节点待机、达到migration-threshold或配置更改)而强制资源转移资源转移,资源总是留在当前位置。此选项的作用几乎等同于完全禁用自动故障回复.
值为-INFINITY:
资源总是移离当前位置。

  

  

  

  实例:配置web高可用集群:
  1、安装集群服务之前的工作;
  node1:
# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=node1.firefox.com
[root@localhost ~]# uname -n
node1.firefox.com
[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.0.1  server.magelinux.com server
172.16.249.101 node1.firefox.com   node1 node1
172.16.249.168 node2.firefox.com    node 2   node2
172.16.249.189 node3.firefox.com   node3    node3
# crontab  -l
*/2 * * * * /usr/sbin/ntpdate  172.16.0.1 &> /dev/null
# ssh-keygen  -t rsa -P ''
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
a6:58:a0:0d:3b:9f:e4:fa:f7:d8:87:27:1e:8a:e4:91 root@node1.firefox.com
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|  . .            |
|   = .           |
|  + o . S        |
|   = = o         |
|    E . ..       |
|   + o.+o.o      |
|  ..+.oo++       |
+-----------------+
[root@localhost ~]# ssh-copy-id  -i .ssh/id_rsa.pub  root@node2.firefox.com
The authenticity of host 'node2.firefox.com (172.16.249.168)' can't be established.
RSA key fingerprint is 76:7f:44:04:04:78:70:c4:42:7f:31:20:d0:d0:95:9e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2.firefox.com,172.16.249.168' (RSA) to the list of known hosts.
root@node2.firefox.com's password:
Now try logging into the machine, with "ssh 'root@node2.firefox.com'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
# ssh node2 'date '; date
The authenticity of host 'node2 (172.16.249.168)' can't be established.
RSA key fingerprint is 76:7f:44:04:04:78:70:c4:42:7f:31:20:d0:d0:95:9e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2' (RSA) to the list of known hosts.
Thu Apr 17 22:35:01 CST 2014
Thu Apr 17 22:35:01 CST 2014  

  下载heartbeat rpm包;
# lftp  172.16.0.1
lftp 172.16.0.1:~> ls
drwx------    2 0        0           16384 Jul 04  1980 lost+found
drwxrwxr-x   21 0        0            4096 Apr 01 06:15 pub
lftp 172.16.0.1:/> cd pub/Sources/6.x86_64/
lftp 172.16.0.1:/pub/Sources/6.x86_64> mirror heartbeat2/
Total: 1 directory, 7 files, 0 symlinks                                
New: 7 files, 0 symlinks
5829264 bytes transferred
in
2 seconds (2.35M/s)  

  安装及配置:
yum install perl-TimeDate net-snmp-libs libnet PyXML
# 安装heartbeat 所依赖的程序包
rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
# 安装heartbeat 2 以及程序包
Preparing...                ########################################### [100%]
1:heartbeat-pils         ########################################### [ 33%]
2:heartbeat-stonith      ########################################### [ 67%]
3:heartbeat              ########################################### [100%]
cp /usr/share/doc/heartbeat-2.1.4/{authkeys,ha.cf,haresources} /etc/ha.d/
# 复制配置文件、认证文件、以及集群资源配置文件
openssl  rand -hex 8
80dd467590678c72
# 使用openssl 生成加密秘钥
cat authkeys
#  更改 authkeys 文件
#    Authentication file.  Must be mode 600
#
#
#    Must have exactly one auth directive at the front.
#    auth    send authentication using this method-id
#
#    Then, list the method and key that go with that method-id
#
#    Available methods: crc sha1, md5.  Crc doesn't need/want a key.
#
#    You normally only have one authentication method-id listed in this file
#
#    Put more than one to make a smooth transition when changing auth
#    methods and/or keys.
#
#
#    sha1 is believed to be the "best", md5 next best.
#
#    crc adds no security, except from packet corruption.
#        Use only on physically secure networks.
#
auth 2
#1 crc
2 sha1  80dd467590678c72
#3 md5 Hello!
chmod  600 authkeys
# 更改authkeys 文件的默认权限为600  

  ha.cf配置文件部分参数详解:

ha.cf配置文件部分参数详解:
autojoin    none
#集群中的节点不会自动加入
logfile /var/log/ha-log
#指名heartbaet的日志存放位置
keepalive 2
#指定心跳使用间隔时间为2秒(即每两秒钟在eth1上发送一次广播)
deadtime 30
#指定备用节点在30秒内没有收到主节点的心跳信号后,则立即接管主节点的服务资源
warntime 10
#指定心跳延迟的时间为十秒。当10秒钟内备份节点不能接收到主节点的心跳信号时,就会往日志中写入一个警告日志,但此时不会切换服务
initdead 120
#在某些系统上,系统启动或重启之后需要经过一段时间网络才能正常工作,该选项用于解决这种情况产生的时间间隔。取值至少为deadtime的两倍。
udpport 694
#设置广播通信使用的端口,694为默认使用的端口号。
baud    19200
#设置串行通信的波特率
bcast   eth0
# Linux  指明心跳使用以太网广播方式,并且是在eth0接口上进行广播。
#mcast eth0 225.0.0.1 694 1 0
#采用网卡eth0的Udp多播来组织心跳,一般在备用节点不止一台时使用。Bcast、ucast和mcast分别代表广播、单播和多播,是组织心跳的三种方式,任选其一即可。
#ucast eth0 192.168.1.2
#采用网卡eth0的udp单播来组织心跳,后面跟的IP地址应为双机对方的IP地址
auto_failback on
#用来定义当主节点恢复后,是否将服务自动切回,heartbeat的两台主机分别为主节点和备份节点。主节点在正常情况下占用资源并运行所有的服务,遇到故障时把资源交给备份节点并由备份节点运行服务。在该选项设为on的情况下,一旦主节点恢复运行,则自动获取资源并取代备份节点,如果该选项设置为off,那么当主节点恢复后,将变为备份节点,而原来的备份节点成为主节点
#stonith baytech /etc/ha.d/conf/stonith.baytech
# stonith的主要作用是使出现问题的节点从集群环境中脱离,进而释放集群资源,避免两个节点争用一个资源的情形发生。保证共享数据的安全性和完整性。
#watchdog /dev/watchdog
#该选项是可选配置,是通过Heartbeat来监控系统的运行状态。使用该特性,需要在内核中载入"softdog"内核模块,用来生成实际的设备文件,如果系统中没有这个内核模块,就需要指定此模块,重新编译内核。编译完成输入"insmod softdog"加载该模块。然后输入"grep misc /proc/devices"(应为10),输入"cat /proc/misc |grep watchdog"(应为130)。最后,生成设备文件:"mknod /dev/watchdog c 10 130" 。即可使用此功能
node node1.magedu.com
#主节点主机名,可以通过命令“uanme –n”查看。
node node2.magedu.com
#备用节点主机名
ping 192.168.12.237
#选择ping的节点,ping 节点选择的越好,HA集群就越强壮,可以选择固定的路由器作为ping节点,但是最好不要选择集群中的成员作为ping节点,ping节点仅仅用来测试网络连接
ping_group group1 192.168.12.120 192.168.12.237
#类似于ping  ping一组ip地址
apiauth pingd  gid=haclient uid=hacluster
respawn hacluster /usr/local/ha/lib/heartbeat/pingd -m 100 -d 5s
#该选项是可选配置,列出与heartbeat一起启动和关闭的进程,该进程一般是和heartbeat集成的插件,这些进程遇到故障可以自动重新启动。最常用的进程是pingd,此进程用于检测和监控网卡状态,需要配合ping语句指定的ping node来检测网络的连通性。其中hacluster表示启动pingd进程的身份。  

  当前环境的配置:
# cat ha.cf
#
#   There are lots of options in this file.  All you have to have is a set
#   of nodes listed {"node ...} one of {serial, bcast, mcast, or ucast},
#   and a value for "auto_failback".
#
#   ATTENTION: As the configuration file is read line by line,
#          THE ORDER OF DIRECTIVE MATTERS!
#
#   In particular, make sure that the udpport, serial baud rate
#   etc. are set before the heartbeat media are defined!
#   debug and log file directives go into effect when they
#   are encountered.
#
#   All will be fine if you keep them ordered as in this example.
#
#
#       Note on logging:
#       If all of debugfile, logfile and logfacility are not defined,
#       logging is the same as use_logd yes. In other case, they are
#       respectively effective. if detering the logging to syslog,
#       logfacility must be "none".
#
#   File to write debug messages to
#debugfile /var/log/ha-debug
#
#
#   File to write other messages to
#
logfile /var/log/ha-log
#
#
#   Facility to use for syslog()/logger
#
#logfacility    local0
#
#
#   A note on specifying "how long" times below...
#
#   The default time unit is seconds
#       10 means ten seconds
#
#   You can also specify them in milliseconds
#       1500ms means 1.5 seconds
#
#
#   keepalive: how long between heartbeats?
#
keepalive 1000ms
#
#   deadtime: how long-to-declare-host-dead?
#
#       If you set this too low you will get the problematic
#       split-brain (or cluster partition) problem.
#       See the FAQ for how to use warntime to tune deadtime.
#
deadtime 8
#
#   warntime: how long before issuing "late heartbeat" warning?
#   See the FAQ for how to use warntime to tune deadtime.
#
warntime 4
#
#
#   Very first dead time (initdead)
#
#   On some machines/OSes, etc. the network takes a while to come up
#   and start working right after you've been rebooted.  As a result
#   we have a separate dead time for when things first come up.
#   It should be at least twice the normal dead time.
#
#initdead 120
#
#
#   What UDP port to use for bcast/ucast communication?
#
udpport 694
#
#   Baud rate for serial ports...
#
#baud   19200
#
#   serial  serialportname ...
#serial /dev/ttyS0  # Linux
#serial /dev/cuaa0  # FreeBSD
#serial /dev/cuad0      # FreeBSD 6.x
#serial /dev/cua/a  # Solaris
#
#
#   What interfaces to broadcast heartbeats over?
#
#bcast  eth0        # Linux
bcast    eth2   # Linux
#bcast  le0     # Solaris
#bcast  le1 le2     # Solaris
#
#   Set up a multicast heartbeat medium
#   mcast [dev] [mcast group] [port] [ttl] [loop]
#
#   [dev]       device to send/rcv heartbeats on
#   [mcast group]   multicast group to join (class D multicast address
#           224.0.0.0 - 239.255.255.255)
#   [port]      udp port to sendto/rcvfrom (set this value to the
#           same value as "udpport" above)
#   [ttl]       the ttl value for outbound heartbeats.  this effects
#           how far the multicast packet will propagate.  (0-255)
#           Must be greater than zero.
#   [loop]      toggles loopback for outbound multicast heartbeats.
#           if enabled, an outbound packet will be looped back and
#           received by the interface it was sent on. (0 or 1)
#           Set this value to zero.
#   
#
#mcast eth0 225.0.0.1 694 1 0
#
#   Set up a unicast / udp heartbeat medium
#   ucast [dev] [peer-ip-addr]
#
#   [dev]       device to send/rcv heartbeats on
#   [peer-ip-addr]  IP address of peer to send packets to
#
#ucast eth0 192.168.1.2
#
#
#   About boolean values...
#
#   Any of the following case-insensitive values will work for true:
#       true, on, yes, y, 1
#   Any of the following case-insensitive values will work for false:
#       false, off, no, n, 0
#
#
#
#   auto_failback:  determines whether a resource will
#   automatically fail back to its "primary" node, or remain
#   on whatever node is serving it until that node fails, or
#   an administrator intervenes.
#
#   The possible values for auto_failback are:
#       on  - enable automatic failbacks
#       off - disable automatic failbacks
#       legacy  - enable automatic failbacks in systems
#           where all nodes do not yet support
#           the auto_failback option.
#
#   auto_failback "on" and "off" are backwards compatible with the old
#       "nice_failback on" setting.
#
#   See the FAQ for information on how to convert
#       from "legacy" to "on" without a flash cut.
#       (i.e., using a "rolling upgrade" process)
#
#   The default value for auto_failback is "legacy", which
#   will issue a warning at startup.  So, make sure you put
#   an auto_failback directive in your ha.cf file.
#   (note: auto_failback can be any boolean or "legacy")
#
auto_failback on
#
#
#       Basic STONITH support
#       Using this directive assumes that there is one stonith
#       device in the cluster.  Parameters to this device are
#       read from a configuration file. The format of this line is:
#
#         stonith <stonith_type> <configfile>
#
#       NOTE: it is up to you to maintain this file on each node in the
#       cluster!
#
#stonith baytech /etc/ha.d/conf/stonith.baytech
#
#       STONITH support
#       You can configure multiple stonith devices using this directive.
#       The format of the line is:
#         stonith_host <hostfrom> <stonith_type> <params...>
#         <hostfrom> is the machine the stonith device is attached
#              to or * to mean it is accessible from any host.
#         <stonith_type> is the type of stonith device (a list of
#              supported drives is in /usr/lib/stonith.)
#         <params...> are driver specific parameters.  To see the
#              format for a particular device, run:
#           stonith -l -t <stonith_type>
#
#
#   Note that if you put your stonith device access information in
#   here, and you make this file publically readable, you're asking
#   for a denial of service attack ;-)
#
#   To get a list of supported stonith devices, run
#       stonith -L
#   For detailed information on which stonith devices are supported
#   and their detailed configuration options, run this command:
#       stonith -h
#
#stonith_host *     baytech 10.0.0.3 mylogin mysecretpassword
#stonith_host ken3  rps10 /dev/ttyS1 kathy 0
#stonith_host kathy rps10 /dev/ttyS1 ken3 0
#
#   Watchdog is the watchdog timer.  If our own heart doesn't beat for
#   a minute, then our machine will reboot.
#   NOTE: If you are using the software watchdog, you very likely
#   wish to load the module with the parameter "nowayout=0" or
#   compile it without CONFIG_WATCHDOG_NOWAYOUT set. Otherwise even
#   an orderly shutdown of heartbeat will trigger a reboot, which is
#   very likely NOT what you want.
#
#watchdog /dev/watchdog
#   
#   Tell what machines are in the cluster
#   node    nodename ...    -- must match uname -n
#node   ken3
#node   kathy
node    dc.firefox.com
node    node10.firefox.com
#   Less common options...
#
#   Treats 10.10.10.254 as a psuedo-cluster-member
#   Used together with ipfail below...
#   note: don't use a cluster node as ping node
#
ping 172.16.0.1
#
#   Treats 10.10.10.254 and 10.10.10.253 as a psuedo-cluster-member
#       called group1. If either 10.10.10.254 or 10.10.10.253 are up
#       then group1 is up
#   Used together with ipfail below...
#
#ping_group group1 10.10.10.254 10.10.10.253
#
#   HBA ping derective for Fiber Channel
#   Treats fc-card-name as psudo-cluster-member
#   used with ipfail below ...
#
#   You can obtain HBAAPI from http://hbaapi.sourceforge.net.  You need
#   to get the library specific to your HBA directly from the vender
#   To install HBAAPI stuff, all You need to do is to compile the common
#   part you obtained from the sourceforge. This will produce libHBAAPI.so
#   which you need to copy to /usr/lib. You need also copy hbaapi.h to
#   /usr/include.
#
#   The fc-card-name is the name obtained from the hbaapitest program
#   that is part of the hbaapi package. Running hbaapitest will produce
#   a verbose output. One of the first line is similar to:
#       Apapter number 0 is named: qlogic-qla2200-0
#   Here fc-card-name is qlogic-qla2200-0.
#
#hbaping fc-card-name
#
#
#   Processes started and stopped with heartbeat.  Restarted unless
#       they exit with rc=100
#
#respawn userid /path/name/to/run
#respawn hacluster /usr/lib/heartbeat/ipfail
#
#   Access control for client api
#           default is no access
#
#apiauth client-name gid=gidlist uid=uidlist
#apiauth ipfail gid=haclient uid=hacluster
###########################
#
#   Unusual options.
#
###########################
#
#   hopfudge maximum hop count minus number of nodes in config
#hopfudge 1
#
#   deadping - dead time for ping nodes
#deadping 30
#
#   hbgenmethod - Heartbeat generation number creation method
#       Normally these are stored on disk and incremented as needed.
#hbgenmethod time
#
#   realtime - enable/disable realtime execution (high priority, etc.)
#       defaults to on
#realtime off
#
#   debug - set debug level
#       defaults to zero
#debug 1
#
#   API Authentication - replaces the fifo-permissions-based system of the past
#
#
#   You can put a uid list and/or a gid list.
#   If you put both, then a process is authorized if it qualifies under either
#   the uid list, or under the gid list.
#
#   The groupname "default" has special meaning.  If it is specified, then
#   this will be used for authorizing groupless clients, and any client groups
#   not otherwise specified.
#
#   There is a subtle exception to this.  "default" will never be used in the
#   following cases (actual default auth directives noted in brackets)
#         ipfail    (uid=HA_CCMUSER)
#         ccm       (uid=HA_CCMUSER)
#         ping      (gid=HA_APIGROUP)
#         cl_status (gid=HA_APIGROUP)
#
#   This is done to avoid creating a gaping security hole and matches the most
#   likely desired configuration.
#
#apiauth ipfail uid=hacluster
#apiauth ccm uid=hacluster
#apiauth cms uid=hacluster
#apiauth ping gid=haclient uid=alanr,root
#apiauth default gid=haclient
#   message format in the wire, it can be classic or netstring,
#   default: classic
#msgfmt  classic/netstring
#   Do we use logging daemon?
#   If logging daemon is used, logfile/debugfile/logfacility in this file
#   are not meaningful any longer. You should check the config file for logging
#   daemon (the default is /etc/logd.cf)
#   more infomartion can be fould in the man page.
#   Setting use_logd to "yes" is recommended
#
# use_logd yes/no
#
#   the interval we  reconnect to logging daemon if the previous connection failed
#   default: 60 seconds
#conn_logd_time 60
#
#
#   Configure compression module
#   It could be zlib or bz2, depending on whether u have the corresponding
#   library in the system.
compression bz2
#
#   Confiugre compression threshold
#   This value determines the threshold to compress a message,
#   e.g. if the threshold is 1, then any message with size greater than 1 KB
#   will be compressed, the default is 2 (KB)
compression_threshold 2
crm respawn  在ha.cf添加此项能够使用hb_gui 图形化的方式管理集群;如果使用图像化配置集群服务器的话;haresources配置文件一定不能保留,不然会冲突的;      

  
  haresources配置文件; 主节点跟备节点的配置一定要一样;网卡地址也要一致,以及网卡类型一定要一致;不然就会报错

  5
cat haresources
#    virtual in any sense of the word.
#
node10.firefox.com  172.16.249.249.100/eth0 Filesystem::172.16.251.20:/www/htdoc::/var/www/html::nfs httpd  将主节点中的配置文件scp 之备用节点
# scp  /etc/ha.d/authkeys  ha.cf  haresources  dc.firefix.com:/etc/ha.d/  启动动服务 heartbeat;
[root@node10 ha.d]# service heartbeat start
在主节点上ssh命令执行备用节点启动
# ssh  dc.firefox.com 'service heartbeat start'
logd is already running
Starting High-Availability services:
2014/04/19_13:05:56 INFO:  Resource is stopped
Done.  查看监听端口;
  
  
# ss -tuanlp | grep 5560
tcp    LISTEN     0      10                     *:5560                  *:*      users:(("mgmtd",3386,11))  

  至此集群服务依然启动;但是我们今天的重点是以图形化的方式管理集群服务;所以你懂得;
  

  

  

  使用GUI配置群集资源
HA群集的主要0的是管理用户服务。用户服务的典型示例是Apache Web服务 器或数据厍。从用户角度来看,服务就姓在客户的要求下执行某些操作。但对 群集来说,服务则是可以启动或停止的资源一服务的本质与群集无关。
作力群集管理似,您需要在群集中为服务器上运行的每个资源或成用程序创建 群集资源。群集资源可以包括Web站点、电子邮件服务器、数据库、文件系 统、虚拟机和任何其他苺于服务器的说用程序或在任意时间对用户都可用的服 务。

  安装heartbeat-gui rpm包,支持以图形化方式配置管理集群服务
# rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm  因为以图形化配置集群服务,需要一个用户去配置;不能以root的身份去配置;那样太不安全了; 默认安装完成heartbeat-gui 之后;会创建一个名为hacluster的用户;你懂得;不过他没有密码;所以亦需要为他创建密码;
# passwd  hacluster
Changing password for user hacluster.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.  启动hb_gui 程序;使用图像化地方时管理集群服务啦;
# hb_gui &
[3] 3485
[root@dc heartbeat2]# Xlib:  extension "RANDR" missing on display "localhost:10.0".  启动之后;在xshell终端上就会出现该窗口;该窗口只针对于xshell;其它的终端程序没试过;
DSC0002.jpg

  点击connection之后;输入密码;就可以管理集群服务了

DSC0003.jpg

  

  Linux HA Management Client允许您添加和修改资源、约束及配置等.它还提供 管理群集组件的功能,如启动、停止或迁移资源,淸理资源,或将节点设置为待机。此外,还可以通过选择任意configure(配置)子项并选择show(显示)>XML Mode (XML模式),轻松地查看、编辑、导人和导出CIB的XML结构。

  
在下面可以找到一些如何使用Linux HAManagementCHent创建和管理辟集资源 的示例。

  

  4.2创建群集资源
可以创建以下类型的资源:
原始
原始资源是最基本的资源类型。

组包含一系列需要放晋在一起、按顺序启动和以反序停止的资源。

复制
克隆娃可以在多个主机上处于活动状态的资源。如果各个资源代理支持,则任何资源均可克隆。

主资源姓一种特殊的克隆资源,主资源可以具有多种模式。主资源必须只能 包含一个组或一个常规资源。

  

  过程4.1添加原始资源
1 启动 Linux HA Management Client并登录到群集。
2 在左窗格中,选择资源并单击添加> Add new ltem。
3 在下一个对话框中,为资源设晋以下参数:
3a为资源输人唯—的id。
3b从Class (类)列表中,选择要用于该资源的资源代理类:heartbeat,lsb、ocf或stonith。
3c如果选择了ocf作为类,请同时指定OCF资源代理的provider加(提供程序)。OCF规范允许多个供应商供应相同的资源代理。
3d从Type (类型)列表中,选择要使用的资源代理(例如IPaddr或Filesystem)。该资源代理的简短描述显示在下方。

    type(类型);列表中提供的选项取决于您选择的class(类)对于OCF资源还取决于provider(提供程序)中选择的内容
  3e在options(选项)下面,设置initial state of resource(资源的初始状态)。
  3f如果希望集群监视资源状况是否正常,请激活addmonitor operation(添加监视操作)。

DSC0004.jpg

  选择资源类型;这里我们选择的是组类型
DSC0005.jpg

  add parameter:能够选择资源的类型; broadcast;cidr_netmask;都在此选项中选择
DSC0006.jpg

DSC0007.jpg

  继续向组中添加web 服务的资源;

   DSC0008.jpg
  因为是lsb类型的资源代理所有;参数很少;只需点击添加即可;

DSC0009.jpg

   DSC00010.jpg
  查看活动节点;如下图所示:活动节点是node5.firefox.com;
   DSC00011.jpg
  查看VIP 以及web服务是否启动;
[root@node5 ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:0c:29:98:3a:e5 brd ff:ff:ff:ff:ff:ff
inet 172.16.249.27/16 brd 172.16.255.255 scope global eth0
inet 172.16.249.200/16 brd 172.16.255.255 scope global secondary eth0
inet6 fe80::20c:29ff:fe98:3ae5/64 scope link
valid_lft forever preferred_lft forever  查看web服务状态;   
# service httpd status
httpd (pid  1859) is running...  为组添加共享存储:
# setfacl  -m u:apache:rwx /www/htdoc/
# cat /etc/exports
/www/htdoc    172.16.0.0/16(rw)
/www/htdoc      172.16.0.0/16(rw,no_root_squash)  添加资源:
   DSC00012.jpg
  查看是否挂载成功:
[root@node5 ~]# mount
/dev/mapper/vg0-root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/vg0-usr on /usr type ext4 (rw)
/dev/mapper/vg0-var on /var type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
172.16.251.20:/www/htdoc on /var/www/html type nfs (rw,vers=4,addr=172.16.251.20,clientaddr=172.16.249.27)  访问:
   DSC00013.jpg
  将active节点更改为standby;右击node5
   DSC00014.jpg
   DSC00015.jpg
  查看资源是否成功转移;
[root@node4 ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:0c:29:6b:b8:52 brd ff:ff:ff:ff:ff:ff
inet 172.16.249.26/16 brd 172.16.255.255 scope global eth0
inet 172.16.249.200/16 brd 172.16.255.255 scope global secondary eth0
inet6 fe80::20c:29ff:fe6b:b852/64 scope link
valid_lft forever preferred_lft forever
[root@node4 ~]# mount
/dev/mapper/vg0-root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/vg0-usr on /usr type ext4 (rw)
/dev/mapper/vg0-var on /var type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
172.16.251.20:/www/htdoc on /var/www/html type nfs (rw,vers=4,addr=172.16.251.20,clientaddr=172.16.249.26)
[root@node4 ~]# service httpd status
httpd (pid  2967) is running...  验证:
  
  
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-480662-1-1.html 上篇帖子: 01_Linux学习 下篇帖子: Linux 压缩打包
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表