前文我們介紹了高可用集群corosync+pacemaker的集群管理工具crmsh的常用命令的使用,回顧請參考https://www.cnblogs.com/qiuhom-1874/tag/crmsh/;今天我們來簡單介紹另一款集群管理工具pcs;
一、環境准備
1、集群各節點同步時間和配置hosts文件解析各節點主機名;
提示:各節點都要去驗證,是否時間同步了,hosts主機名解析;做了以上幾步以后,如果有需要可把各節點的ssh互信也配置起來,方便各主機間互相拷貝文件;
2、在集群各節點安裝程序包
yum install pacemaker pcs psmisc policycoreutils-python -y
提示:在集群各節點執行以上命令安裝程序包;
3、程序包安裝完成以后,在各節點啟動pcsd,並把pcsd設置為開機自動啟動
systemctl enable pcsd --now
提示:到此pcsd安裝和啟動就完成了;
二、利用pcs來快速創建啟動集群
1、在集群各節點上給hacluster用戶設定相同的密碼
echo "you password" |passwd --stdin hacluster
提示:也可以不用這個用戶,新建一個用戶也行,總之在集群各節點上有一個一模一樣的賬號,並且密碼也必須相同;建議使用hacluster用戶;
2、認證各節點的用戶名和密碼
提示:如果集群主機特別多可以用shell的大括號展開特性;這個不需要在每個節點上做,在當前pcs所在節點上做就行了;
3、創建集群
4、啟動集群
好了,到此一個3節點的corosync+pacemaker集群就創建啟動好了;
驗證:在各節點查看corosync pacemaker是否都啟動了?
node01
node02
node03
提示:在node03上查看pacemaker時,它這里告訴我們我配置了stonith選項,卻沒有發現stonith設備;
三、pcs管理集群
1、查看集群狀態
驗證集群配置信息
2、關閉stonith選項
提示:可以看到我們關閉了stonith選項以后,再次驗證集群配置就沒有報任何錯誤了;
驗證:在node03上查看pacemaker的狀態,看看是否還會有stonith的錯誤?
提示:可以看到在集群的DC(node03)節點上查看pacemaker的狀態,沒有發現stonith相關錯誤;
3、查看pcs的幫助信息
[root@node01 ~]# pcs Usage: pcs [-f file] [-h] [commands]... Control and configure pacemaker and corosync. Options: -h, --help Display usage and exit. -f file Perform actions on file instead of active CIB. --debug Print all network traffic and external commands run. --version Print pcs version information. List pcs capabilities if --full is specified. --request-timeout Timeout for each outgoing request to another node in seconds. Default is 60s. --force Override checks and errors, the exact behavior depends on the command. WARNING: Using the --force option is strongly discouraged unless you know what you are doing. Commands: cluster Configure cluster options and nodes. resource Manage cluster resources. stonith Manage fence devices. constraint Manage resource constraints. property Manage pacemaker properties. acl Manage pacemaker access control lists. qdevice Manage quorum device provider on the local host. quorum Manage cluster quorum settings. booth Manage booth (cluster ticket manager). status View cluster status. config View and manage cluster configuration. pcsd Manage pcs daemon. node Manage cluster nodes. alert Manage pacemaker alerts. client Manage pcsd client configuration. [root@node01 ~]#
提示:pcs命令的用法很簡單,就是pcs + 選線 +子命令,其中一個子命令對應一個對象的管理,比如cluster就是對集群配置相關管理,resource就是資源相關配置;如果我們要查看一個子命令的詳細用法,可以使用pcs + 子命令 --help來查看;
4、列出資源代理
5、查看指定資源代理的幫助
提示:這個幫助信息和我們之前用crmsh的幫助信息類似,如果對應參數后面有required就表示這個參數是必選參數;
示例:利用ocf:heartbeat:IPaddr定義一個vip資源
[root@node01 ~]# pcs resource create webip ocf:heartbeat:IPaddr ip="192.168.0.199" nic="ens33" cidr_netmask="24" [root@node01 ~]# pcs resource webip (ocf::heartbeat:IPaddr): Started node01.test.org [root@node01 ~]# pcs status Cluster name: mycluster Stack: corosync Current DC: node03.test.org (version 1.1.21-4.el7-f14e36fd43) - partition with quorum Last updated: Sat Sep 5 11:58:49 2020 Last change: Sat Sep 5 11:58:40 2020 by root via cibadmin on node01.test.org 3 nodes configured 1 resource configured Online: [ node01.test.org node02.test.org node03.test.org ] Full list of resources: webip (ocf::heartbeat:IPaddr): Started node01.test.org Daemon Status: corosync: active/disabled pacemaker: active/disabled pcsd: active/enabled [root@node01 ~]#
提示:創建資源的方式和crmsh的方式很類似,只是命令不同而已,都是要給資源取一個名稱,然后指定資源代理,然后給定參數直接創建即可;使用pcs resource命令可以列出資源列表;
創建一個web資源
把webip和webserver歸並為一個組
查看集群配置
將節點node02設置為standby狀態
提示:可以看到node02設置為standby狀態以后,運行在node02上的資源也隨之遷往其他節點;
將node02上線
提示:上線不再是crmsh里的online命令,而是unstandby;
手動遷移資源到其他節點
提示:前邊crmsh里執行手動遷移資源,它默認會在配置界面給我們添加一條位置約束,pcs也是一樣的套路,它也會給配置界面添加一條位置約束;
查看配置信息中位置約束配置
提示:pcs constraint 是查看集群所有約束;后面跟location表示只查看位置約束;
創建位置約束
提示:我們創建了一條位置約束,讓webservice對node01的傾向性為正無窮,但是對應node03的資源並沒有遷往node01,這其中的原因是webservice目前對node03的傾向性也是正無窮;
驗證:修改webservice對node03的傾向性為100,看看webservice是否會遷往node01呢?
提示:可以看到把webservice對node03的傾向性改為100以后,運行在node03上的webservice就遷往node01上去了;
顯示資源對集群各節點的傾向性分數
提示:crm_simulate -sL這個命令可以打印出當前集群各資源對各節點的傾向性的分數;好了,有關pcs的其他命令用法,自己可以查看幫助去慢慢實踐;我個人覺得使用corosync+pacemaker高可用集群,手動管理集群用crmsh更好;pcs更適合用腳本的方式去管理部署集群;初學建議從crmsh入手比較好,它可以讓我們很好的去理解corosync+pacemaker高可用集群架構;