下文來為各位整理一篇關于corosync+pacemaker的crmsh crm 實例的,希望這個例子可以幫助到各位,corosync和pacemaker實現高可用的難點就在crm命令,子命令多,參數多等,下面說一些常用的例子.
一,crm有兩種工作方式
1,批處理模式,就是在shell命令行中直接輸入命令
2,交互式模式(crm(live)#)進入到crmsh中交互執行.
二,命令詳解
1,一級子命令,代碼如下:
- [root@node1 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)交互模式
2,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 //退出交互式程序
3,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交互模式
4,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 //退出
5,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,系統資源查看,代碼如下:
- crm(live)ra# classes //系統所使用的資源代理
- lsb
- ocf / heartbeat pacemaker
- service
- stonith
2,默認系統資源列表,代碼如下:
- 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
3,查看外加的系統資源,代碼如下:
- 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
4,查看系統資源的參數,代碼如下:
- 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".
- 。。。。。。。。。。。。。。。。。。。省略。。。。。。。。。。。。。。。。。。。。。。。。
5,屬性修改,代碼如下:
- crm(live)configure# property stonith-enabled=false //禁用stonith-enable
- crm(live)configure# property no-quorum-policy=ignore //忽略投票規則
6,定義一資源所使用的命令,代碼如下:
- /**
- * 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
- crm(live)configure# primitive nginx_res lsb:nginx //那些在/etc/init.d/*的腳本就是屬于lsb的
- params后面的參數,可以通過meta命令來查找,不同的系統資源參數是不一樣的。
7,定義排列約束,代碼如下:
- /**
- * 定義排列約束
- * colocation:排列約束命令
- * nginx_web : 約束名
- * inf:#(可能性,inf表示永久在一起,也可以是數值)
- * webip nginx_res:#資源名稱
- */
- crm(live)configure# colocation nginx_web inf: nginx_res webip
8,定義資源啟動順序,代碼如下:
- /**
- * 定義資源啟動順序
- * order : 順序約束的命令
- * nginx_after_ip : 約束ID
- * mandatory: #指定級別(此處有三種級別:mandatory:強制, Optional:可選,Serialize:序列化)
- * webip nginx_res:#資源名稱,這里書寫的先后順序相當重要
- */
- crm(live)configure# order nginx_after_ip mandatory: webip nginx_res
9,定義節點權重,代碼如下:
- /**
- * 定義節點權重
- * location:節點權重命令
- * webip_and_webnfs_and_webserver:約束名稱
- * webip 500: node1:webip這個資源的node1節點的權重是500
- */
- crm(live)configure# location webip_and_webnfs_and_webserver webip 500: node1
10,定義默認資源屬性,代碼如下:
- /**
- * 定義默認資源屬性
- * rsc_defaults:默認資源
- * 這樣定義代表集群中每一個資源的默認權重,只有當資源服務不在當前節點時,權重才會生效,比如,這里我定義了三個資源webip、webnfs、webserver,對每一個資源的權重為100,那么加在一起就變成了300,之前己經定義node1的位置約束的值為500,當node1宕機后,重新上線,這樣就切換到node1上了。 Vevb.com
- */
- crm(live)configure# rsc_defaults resource-stickiness=100
11,刪除資源或者節點,代碼如下:
- crm(live)configure# delete nginx_res //刪除一個資源,約束,排序,組等
- crm(live)node# delete node1 //刪除一個節
12,資源其他,代碼如下:
- crm(live)configure# verify //審核
- crm(live)configure# commit //提交
- crm(live)configure# show //顯示
13,節點掛起和在線,代碼如下:
- crm(live)node# standby node1 //節點掛起
- crm(live)node# online node1 //節點上線
|
新聞熱點
疑難解答