高可用叢集corosync+pacemaker之pcs安裝使用

1874發表於2020-09-05

  前文我們介紹了高可用叢集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高可用叢集架構;

相關文章