天天看點

叢集理論講解(續六)

資源監控

預設情況下,高可用叢集并不會對資源健康狀态進行檢查(資源出現故障後的處理操作,如下),如果要實作此功能,需要專門為資源定義monitor功能,資源可以定義的監控屬性有以下幾個:

id:資源操作的id,必須唯一。

name:資源操作的動作,可用動作有monitor、start、stop,執行資源監控的操作當然是monitor

interval:資源操作的時間間隔,就是多久進行一次監控,預設是0,就是不監控

timeout:确定某個動作失敗的逾時時長

on-fail:正在執行的動作失敗時要采取的措施,可用值包括:

ignore:忽略動作失敗,不做處理。

block:不在資源上執行任何動作,類似ignore

stop:停止資源,并且不在任何節點上啟動它。

restart:重新開機資源,如果目前節點啟動不了會嘗試在其他節點啟動。

fence:stonith其運作的節點。預設設定

standby:将其所在的節點轉變為standby模式。

enabled:是否啟用此操作,可用值為true、false

crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=10.40.0.228  op monitor interval=30s timeout=20s on-fail=restart 

crm(live)configure# verify

WARNING: cib-bootstrap-options: unknown attribute 'show'

WARNING: cib-bootstrap-options: unknown attribute 'help'

WARNING: vip: specified timeout 15 for monitor is smaller than the advised 20s

crm(live)configure# edit

crm(live)configure# commit

[[email protected] ~]# crm status

Stack: classic openais (with plugin)

Current DC: node5.dtedu.com (version 1.1.15-5.el6-e174ec8) - partition with quorum

Last updated: Mon Apr 17 01:28:23 2017 Last change: Mon Apr 17 01:28:19 2017 by root via cibadmin on node5.dtedu.com

, 2 expected votes

2 nodes and 2 resources configured

Online: [ node5.dtedu.com node6.dtedu.com ]

Full list of resources:

 web-httpd (lsb:httpd): Started node5.dtedu.com

 webip (ocf::heartbeat:IPaddr): Started node6.dtedu.com

批處理式:就是在shell模式下直接使用crm指令,比如crm status就是批處理模式的執行個體。

檢視資源類别

[[email protected] ~]# crm ra classes

lsb

ocf / .isolation heartbeat pacemaker

service

stonith

檢視資源代理者

[[email protected] ~]# crm ra list ocf heartbeat

CTDB                Delay               Dummy               Filesystem          IPaddr

IPaddr2             IPsrcaddr           LVM                 MailTo              Route

SendArp             Squid               VirtualDomain       Xinetd              apache

conntrackd          db2                 dhcpd               ethmonitor          exportfs

iSCSILogicalUnit    mysql               named               nfsnotify           nfsserver

nginx               oracle              oralsnr             pgsql               portblock

postfix             rsyncd              symlink             tomcat              

[[email protected] ~]# 

檢視資源屬性

[[email protected] ~]# crm ra meta ocf:heartbeat:IPaddr

删除指定資源

[[email protected] ~]# crm configure delete webip

ERROR: resource webip is running, can't delete it

[[email protected] ~]# crm resource stop webip

[[email protected] ~]# crm resource stop web-httpd

2、pacemaker作為獨立的守護程序運作

PCS配置工具

1、安裝

[[email protected] ~]# yum install pcs -y

同crm比較:

pcs status = crm status

pcs config = crm configure show

pcs resource standards = crm ra classes

pcs resource agents 資源名 = crm ra list ocf heartbeat

顯示資源類别

[[email protected] ~]# pcs resource standards

ocf

檢視資源管理者

[[email protected] ~]# pcs resource providers

heartbeat

pacemaker

檢視資源的代理者

[[email protected] ~]# pcs resource agents ocf

apache

ClusterMon

conntrackd

CTDB

db2

Delay

dhcpd

Dummy

ethmonitor

exportfs

[[email protected] ~]# pcs resource describe ocf:heartbeat:IPaddr

幫助資訊

[[email protected] ~]# pcs resource help

定義一個資源

[[email protected] ~]# pcs resource create web-vip ocf:heartbeat:IPaddr params ip=10.40.0.222

定義一個資源,同時對這個資源進行健康,時間間隔30s,逾時時間30s,資源失敗就重新開機。

[[email protected] ~]# pcs resource create  web-httpd lsb:httpd op monitor interval=30s timeout=30s on-fail=restart 

[[email protected] ~]# pcs config

Cluster Name: 

Corosync Nodes:

Pacemaker Nodes:

 node5.dtedu.com node6.dtedu.com

Resources:

 Resource: web-vip (class=ocf provider=heartbeat type=IPaddr)

  Attributes: ip=10.40.0.218

  Operations: start interval=0s timeout=20s (web-vip-start-interval-0s)

              stop interval=0s timeout=20s (web-vip-stop-interval-0s)

              monitor interval=30s on-fail=restart timeout=30s (web-vip-monitor-interval-30s)

 Resource: web-httpd (class=lsb type=httpd)

  Operations: start interval=0s timeout=15 (web-httpd-start-interval-0s)

              stop interval=0s timeout=15 (web-httpd-stop-interval-0s)

              monitor interval=30s on-fail=restart timeout=30s (web-httpd-monitor-interval-30s)

Stonith Devices:

Fencing Levels:

Location Constraints:

Ordering Constraints:

Colocation Constraints:

Ticket Constraints:

Alerts:

 No alerts defined

Resources Defaults:

 No defaults set

Operations Defaults:

Cluster Properties:

 cluster-infrastructure: classic openais (with plugin)

 dc-version: 1.1.15-5.el6-e174ec8

 expected-quorum-votes: 2

 have-watchdog: false

 stonith-enabled: false

[[email protected] ~]# 

添加資源到組

[[email protected] ~]# pcs resource group add web web-vip

[[email protected] ~]# pcs resource group add web web-httpd

[[email protected] ~]# pcs status

Cluster name: 

 Resource Group: web

     web-vip (ocf::heartbeat:IPaddr): Started node5.dtedu.com

     web-httpd (lsb:httpd): Started node5.dtedu.com

從組中删除指定資源

[[email protected] ~]# pcs resource group remove web web-vip

[[email protected] ~]# pcs resource group remove web web-httpd

Current DC: node6.dtedu.com (version 1.1.15-5.el6-e174ec8) - partition with quorum

Last updated: Mon Apr 17 04:09:58 2017 Last change: Mon Apr 17 04:09:23 2017 by root via cibadmin on node6.dtedu.com

 web-vip (ocf::heartbeat:IPaddr): Started node6.dtedu.com

 web-httpd (lsb:httpd): Started node5.dtedu.com

定義優先啟動那個節點作為主節點,将資源定位到相同的節點上colocation,定義資源間的啟動順序order

[[email protected] ~]# pcs constraint colocation add web-vip web-httpd 

[[email protected] ~]# pcs constraint order first start web-vip then start web-httpd

[[email protected] ~]# pcs config

  start web-vip then start web-httpd (kind:Mandatory) (id:order-web-vip-web-httpd-mandatory)

  web-vip with web-httpd (score:INFINITY) (id:colocation-web-vip-web-httpd-INFINITY)

将正在工作的節點進行下線操作。

[[email protected] ~]# pcs cluster standby node5.dtedu.com

挂載一個nfs遠端檔案系統

[[email protected] ~]# pcs resource create web-store ocf:heartbeat:Filesystem params device=‘10.40.0.37:/web/htdocs’ directory=‘/var/www/html’ fstype=‘nfs’ op monitor interval=30s timeout=30s on-fail=restart 

[[email protected] ~]# crm staus

Last updated: Mon Apr 17 06:47:41 2017 Last change: Mon Apr 17 06:47:37 2017 by root via cibadmin on node5.dtedu.com

2 nodes and 3 resources configured

Node node6.dtedu.com: standby

Online: [ node5.dtedu.com ]

 web-vip (ocf::heartbeat:IPaddr): Started node5.dtedu.com

 web-store (ocf::heartbeat:Filesystem): Started node5.dtedu.com

Failed Actions:

* web-httpd_monitor_30000 on node6.dtedu.com 'not running' (7): call=141, status=complete, exitreason='none',

    last-rc-change='Mon Apr 17 04:06:27 2017', queued=0ms, exec=0ms

本文轉自 blackstome 51CTO部落格,原文連結:http://blog.51cto.com/137783/1968790,如需轉載請自行聯系原作者

繼續閱讀