CRM工具簡介

大囚長發表於2018-08-07

pacemaker是高可用叢集中的CRM(Cluster Resource Manager)資源管理層,他是一個服務,可以作為一個單獨的服務啟動,不過在如果使用corosync1.4中,我們可以設定corosync來啟動pacemaker。pacemaker的配置介面可以在任意節點上安裝crmsh或者pcs還有一些GUI介面的軟體來完成。crmsh在Redhat6.4以後不是官方自帶的,官方預設使用的pcs,crm是OpenSUSE的開源專案,所以如果需要還是用crm的話還需要去OpenSUSE源中下載。

CRM下載源

crmsh依賴於pssh,pssh在epel源中也有下載,這裡給出crmsh的下載源:
centos7的源:http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/network:ha-clustering:Stable.repo

[network_ha-clustering_Stable]
name=Stable High Availability/Clustering packages (CentOS_CentOS-7)
type=rpm-md
baseurl=http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/
gpgcheck=1
gpgkey=http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7//repodata/repomd.xml.key
enabled=1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

CRM命令幫助

在pacemaker1.0之後,pacemaker有了一個繼承的校本化的叢集控制shell,他把麻煩的XML配置隱藏起來,允許你一次做出許多修改並且自動提交(檢測是否合法)。
監控叢集狀態的主要命了是crm_mon(這個和crm status是一樣的效果)。它可以執行在很多模式下並且有許多輸出選項。如果要檢視pacemaker相應的工具,可以通過–help或者man pages來檢視。這些輸出都是靠命令來生成的,所以他總是會在各個節點和工具之間同步。此外,pacemaker的版本和至此的stack可以通過–version選項看到。

本次試驗中所安裝的pacemaker如下:

[root@node-1 ~]# crm_mon --version
Pacemaker 1.1.15-11.el7_3.4
Written by Andrew Beekho

crm_mon --help
crm_mon - Provides a summary of cluster's current state.

Outputs varying levels of detail in a number of different formats.

Usage: crm_mon mode [options]
Options:
 -?, --help        This text
 -$, --version        Version information
 -V, --verbose        Increase debug output
 -Q, --quiet        Display only essential output

Modes:
 -h, --as-html=value        Write cluster status to the named html file
 -X, --as-xml            Write cluster status as xml to stdout. This will enable one-shot mode.
 -w, --web-cgi            Web mode with output suitable for cgi
 -s, --simple-status        Display the cluster status once as a simple one line output (suitable for nagios)

Display Options:
 -n, --group-by-node        Group resources by node
 -r, --inactive            Display inactive resources
 -f, --failcounts        Display resource fail counts
 -o, --operations        Display resource operation history
 -t, --timing-details        Display resource operation history with timing details
 -c, --tickets            Display cluster tickets
 -W, --watch-fencing        Listen for fencing events. For use with --external-agent, --mail-to and/or --snmp-traps where supported
 -L, --neg-locations[=value]    Display negative location constraints [optionally filtered by id prefix]
 -A, --show-node-attributes    Display node attributes
 -D, --hide-headers        Hide all headers
 -R, --show-detail        Show more details (node IDs, individual clone instances)
 -b, --brief            Brief output
 -j, --pending            Display pending state if 'record-pending' is enabled

Additional Options:
 -i, --interval=value        Update frequency in seconds
 -1, --one-shot            Display the cluster status once on the console and exit
 -N, --disable-ncurses        Disable the use of ncurses
 -d, --daemonize        Run in the background as a daemon
 -p, --pid-file=value        (Advanced) Daemon pid file location
 -E, --external-agent=value    A program to run when resource operations take place.
 -e, --external-recipient=value    A recipient for your program (assuming you want the program to send something to someone).

Examples:

Display the cluster status on the console with updates as they occur:

    # crm_mon

Display the cluster status on the console just once then exit:

    # crm_mon -1

Display your cluster status, group resources by node, and include inactive resources in the list:

    # crm_mon --group-by-node --inactive

Start crm_mon as a background daemon and have it write the cluster status to an HTML file:

    # crm_mon --daemonize --as-html /path/to/docroot/filename.html

Start crm_mon and export the current cluster status as xml to stdout, then exit.:

    # crm_mon --as-xml
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67

如果SNMP或者email的選項沒有出現在選項中,說明pacemaker編譯的時候沒有開啟對他們的支援,你需要聯絡提供這個發行版的人,或者自己編譯。

CRM命令詳解

crm有兩種工作方式

1,批處理模式,就是在shell命令列中直接輸入命令
2,互動式模式(crm(live)#)進入到crmsh中互動執行

二,命令詳解

ps:這裡筆者找到了網上允許轉載的詳細博文中整合了個人覺得算是解釋的比較全面的命令詳解,有興趣的朋友不妨拷貝下來放到自己的記事本里以備不時之需。

一級子命令

[root@node-1 corosync]# crm  
crm(live)# help  
This is crm shell, a Pacemaker command line interface.  
Available commands:  
    cib              manage shadow CIBs //cib沙盒  
    resource         resources management //所有的資源都在這個子命令後定義  
    configure        CRM cluster configuration //編輯叢集配置資訊  
    node             nodes management //叢集節點管理子命令  
    options          user preferences //使用者優先順序  
    history          CRM cluster history //命令歷史記錄  
    site             Geo-cluster support  
    ra               resource agents information center //資源代理子命令(所有與資源代理相關的程都在此命令之下)  
    status           show cluster status //顯示當前叢集的狀態資訊  
    help,?           show help (help topics for list of topics)//檢視當前區域可能的命令  
    end,cd,up        go back one level //返回第一級crm(live)  
    quit,bye,exit    exit the program //退出crm(live)互動模式 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

resource資源狀態控制子命令

crm(live)resource# help  
vailable commands:  
        status           show status of resources //顯示資源狀態資訊  
        start            start a resource //啟動一個資源  
        stop             stop a resource //停止一個資源  
        restart          restart a resource //重啟一個資源  
        promote          promote a master-slave resource //提升一個主從資源  
        demote           demote a master-slave resource //降級一個主從資源  
        manage           put a resource into managed mode  //將一個資源加入到管理模式下  
        unmanage         put a resource into unmanaged mode  //從管理模式下去除一個資源  
        migrate          migrate a resource to another node //將資源遷移到另一個節點上  
        unmigrate        unmigrate a resource to another node  
        param            manage a parameter of a resource //管理資源的引數  
        secret           manage sensitive parameters //管理敏感引數  
        meta             manage a meta attribute //管理源屬性  
        utilization      manage a utilization attribute  
        failcount        manage failcounts //管理失效計數器  
        cleanup          cleanup resource status //清理資源狀態  
        refresh          refresh CIB from the LRM status //從LRM(LRM本地資源管理)更新CIB(叢集資訊庫),在  
        reprobe          probe for resources not started by the CRM //探測在CRM中沒有啟動的資源  
        trace            start RA tracing //啟用資源代理(RA)追蹤  
        untrace          stop RA tracing //禁用資源代理(RA)追蹤  
        help             show help (help topics for list of topics) //顯示幫助  
        end              go back one level //返回一級(crm(live)#)  
        quit             exit the program //退出互動式程式  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

configure資源定義子命令

crm(live)configure# help  
Available commands:  
        node             define a cluster node //定義一個叢集節點  
        primitive        define a resource //定義資源  
        monitor          add monitor operation to a primitive //對一個資源新增監控選項(如超時時間,啟動失敗後的操作)  
        group            define a group //定義一個組型別(將多個資源整合在一起)  
        clone            define a clone //定義一個克隆型別(可以設定總的克隆數,每一個節點上可以執行幾個克隆)  
        ms               define a master-slave resource //定義一個主從型別(叢集內的節點只能有一個執行主資源,其它從的做備用)  
        rsc_template     define a resource template //定義一個資源模板  
        location         a location preference //定義位置約束優先順序(預設執行於那一個節點(如果位置約束的值相同,預設傾向性那一個高,就在那一個節點上執行))  
        colocation       colocate resources //排列約束資源(多個資源在一起的可能性)  
        order            order resources //資源的啟動的先後順序  
        rsc_ticket       resources ticket dependency  
        property         set a cluster property //設定叢集屬性  
        rsc_defaults     set resource defaults //設定資源預設屬性(粘性)  
        fencing_topology node fencing order //隔離節點順序  
        role             define role access rights //定義角色的訪問許可權  
        user             define user access rights //定義用使用者訪問許可權  
        op_defaults      set resource operations defaults //設定資源預設選項  
        schema           set or display current CIB RNG schema  
        show             display CIB objects //顯示叢集資訊庫對  
        edit             edit CIB objects //編輯叢集資訊庫物件(vim模式下編輯)  
        filter           filter CIB objects //過濾CIB物件  
        delete           delete CIB objects //刪除CIB物件  
        default-timeouts set timeouts for operations to minimums from the meta-data  
        rename           rename a CIB object //重新命名CIB物件  
        modgroup         modify group //改變資源組  
        refresh          refresh from CIB //重新讀取CIB資訊  
        erase            erase the CIB //清除CIB資訊  
        ptest            show cluster actions if changes were committed  
        rsctest          test resources as currently configured  
        cib              CIB shadow management  
        cibstatus        CIB status management and editing    //cib狀態管理和編輯  
        template         edit and import a configuration from a template   //編輯或匯入配置模板  
        commit           commit the changes to the CIB //將更改後的資訊提交寫入CIB  
        verify           verify the CIB with crm_verify //CIB語法驗證  
        upgrade          upgrade the CIB to version 1.0 //升級CIB到1.0  
        save             save the CIB to a file //將當前CIB匯出到一個檔案中(匯出的檔案存於切換crm 之前的目錄)  
        load             import the CIB from a file //從檔案內容載入CIB  
        graph            generate a directed graph  
        xml              raw xml  
        help             show help (help topics for list of topics) //顯示幫助資訊  
        end              go back one level //回到第一級(crm(live)#)  
        quit             exit the program  //退出crm互動模式  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

node節點管理子命令

crm(live)# node  
crm(live)node# help  
Node management and status commands.  
Available commands:  
    status           show nodes status as XML //以xml格式顯示節點狀態資訊  
    show             show node //命令列格式顯示節點狀態資訊  
    standby          put node into standby //模擬指定節點離線(standby在後面必須的FQDN)  
    online           set node online // 節點重新上線  
    maintenance      put node into maintenance mode  //將一個節點狀態改為maintenance  
    ready            put node into ready mode   //將一個節點狀態改為ready  
    fence            fence node //隔離節點  
    clearstate       Clear node state //清理節點狀態資訊  
    delete           delete node //刪除 一個節點  
    attribute        manage attributes  
    utilization      manage utilization attributes  
    status-attr      manage status attributes  
    help             show help (help topics for list of topics)  
    end              go back one level  //回到上一次  
    quit             exit the program    //退出  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

ra資源代理子命令

crm(live)# ra  
crm(live)ra# help  
Available commands:  
        classes          list classes and providers //為資源代理分類  
        list             list RA for a class (and provider)//顯示一個類別中的提供的資源  
        meta             show meta data for a RA //顯示一個資源代理序的可用引數(如meta ocf:heartbeat:IPaddr2)  
        providers        show providers for a RA and a class  
        help             show help (help topics for list of topics)  
        end              go back one level  
        quit             exit the program
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

例項

系統資源檢視

crm(live)ra# classes   //系統所使用的資源代理  
lsb  
ocf / heartbeat pacemaker  
service  
stonith  
  • 1
  • 2
  • 3
  • 4
  • 5

預設系統資源列表

crm(live)ra# list ocf   //列表預設系統資源  
CTDB               ClusterMon         Delay              Dummy              Filesystem         HealthCPU  
IPaddr             IPaddr2            IPsrcaddr          HealthCPU          HealthSMART        HealthSMART  
LVM                MailTo             Route              SendArp            Squid  
Stateful           SysInfo            SystemHealth       VirtualDomain      Xinetd  
apache             conntrackd         controld           db2                dhcpd  
ethmonitor         exportfs           iSCSILogicalUnit   mysql              named  
nfsnotify          nfsserver          pgsql              ping               pingd  
postfix            remote             rsyncd             symlink            tomcat  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

檢視外加的系統資源

crm(live)ra# list lsb  //列表外加的系統資源  
NetworkManager     abrt-ccpp          abrt-oops          abrtd              acpid  
atd                auditd             autofs             blk-availability   certmonger  
corosync           corosync-notifyd   cpuspeed           crond              cups  
dnsmasq            firstboot          haldaemon          halt               hsqldb  
ip6tables          iptables           irqbalance         jexec              kdump  
killall            lvm2-lvmetad       lvm2-monitor       mdmonitor          messagebus  
mysqld             netconsole         netfs              network            nfs  
nfslock            nginx              nmb                ntpd               ntpdate  
oddjobd            openfire           pacemaker          php-fpm            portreserve  
postfix            psacct             quota_nld          rdisc              redis  
restorecond        rngd               rpcbind            rpcgssd            rpcidmapd  
rpcsvcgssd         rsyslog            sandbox            saslauthd          single  
slapd              smartd             smb                snmpd              snmptrapd  
spice-vdagentd     sshd               sssd               sysstat            udev-post  
vsftpd             wdaemon            winbind            wpa_supplicant     ypbind  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

檢視系統資源的引數

crm(live)ra# meta ocf:heartbeat:IPaddr //檢視系統資源IPaddr的引數
Manages virtual IPv4 and IPv6 addresses (Linux specific version) (ocf:heartbeat:IPaddr)

This Linux-specific resource manages IP alias IP addresses.
It can add an IP alias, or remove one.
In addition, it can implement Cluster Alias IP functionality
if invoked as a clone resource.

If used as a clone, you should explicitly set clone-node-max >= 2,
and/or clone-max < number of nodes. In case of node failure,
clone instances need to be re-allocated on surviving nodes.
This would not be possible if there is already an instance on those nodes,
and clone-node-max=1 (which is the default).

Parameters (*: required, []: default):

ip* (string): IPv4 or IPv6 address
The IPv4 (dotted quad notation) or IPv6 address (colon hexadecimal notation)
example IPv4 “192.168.1.1”.
example IPv6 “2001:db8:DC28:0:0:FC57:D4C8:1FFF”.

屬性修改

crm(live)configure# property stonith-enabled=false //禁用stonith-enable  

crm(live)configure# property no-quorum-policy=ignore //忽略投票規則  
  • 1
  • 2
  • 3

定義一資源所使用的命令

/** 
 * primitive:定義一資源所使用的命令 
 * webip:為資源起一個名字 
 * ocf:heartbeat;IPaddr:所使用資源代理的類別,由誰提供的那一個代理程式 
 * op monitor 對webip做監控 
 * interval:間隔時間 
 * timeout:超時時間 
 * on-fail:失敗自起 
 */  
crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=192.168.10.130 op monitor interval=30s timeout=20s on-fail=restart  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

crm(live)configure# primitive nginx_res lsb:nginx //那些在/etc/init.d/*的指令碼就是屬於lsb的
params後面的引數,可以通過meta命令來查詢,不同的系統資源引數是不一樣的。

定義排列約束

/** 
 * 定義排列約束 
 * colocation:排列約束命令 
 * nginx_web : 約束名 
 * inf:#(可能性,inf表示永久在一起,也可以是數值) 
 * webip nginx_res:#資源名稱 
 */  
crm(live)configure# colocation nginx_web inf: nginx_res webip  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

定義資源啟動順序

/** 
 * 定義資源啟動順序 
 * order : 順序約束的命令 
 * nginx_after_ip : 約束ID 
 * mandatory: #指定級別(此處有三種級別:mandatory:強制, Optional:可選,Serialize:序列化) 
 * webip nginx_res:#資源名稱,這裡書寫的先後順序相當重要 
 */  
crm(live)configure# order nginx_after_ip mandatory: webip nginx_res  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

定義節點權重

/** 
 * 定義節點權重 
 * location:節點權重命令 
 * webip_and_webnfs_and_webserver:約束名稱 
 * webip 500: node1:webip這個資源的node1節點的權重是500 
 */  
crm(live)configure# location webip_and_webnfs_and_webserver webip 500: node1  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

定義預設資源屬性

/** 
 * 定義預設資源屬性 
 * rsc_defaults:預設資源 
 * 這樣定義代表叢集中每一個資源的預設權重,只有當資源服務不在當前節點時,權重才會生效,比如,這裡我定義了三個資源webip、webnfs、webserver,對每一個資源的權重為100,那麼加在一起就變成了300,之前己經定義node1的位置約束的值為500,當node1當機後,重新上線,這樣就切換到node1上了。 
 */  
crm(live)configure# rsc_defaults resource-stickiness=100  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

刪除資源或者節點

crm(live)configure# delete nginx_res  //刪除一個資源,約束,排序,組等  
crm(live)node# delete node1  //刪除一個節  
  • 1
  • 2

資源其他

crm(live)configure# verify //稽核  
crm(live)configure# commit //提交  
crm(live)configure# show //顯示  
  • 1
  • 2
  • 3

節點掛起和線上

crm(live)node# standby node1   //節點掛起  
crm(live)node# online node1    //節點上線 
  • 1
  • 2
  • 3

相關文章