pcs installation and use of high availability cluster corosync+pacemaker

Previously, we introduced the use of common commands of crmsh, the cluster management tool of high availability cluster corosync+pacemaker. For review, please refer to https://www.cnblogs.com/qiuhom-1874/tag/crmsh/ ; Today, let's briefly introduce another cluster management tool pcs;

I. environmental preparation

1. Synchronize the time and configure the hosts file of each node of the cluster, and analyze the host name of each node;

Tip: all nodes need to verify whether the time is synchronized and the host name of hosts is resolved; After doing the above steps, if necessary, you can configure the ssh mutual trust of each node to facilitate the copying of files between hosts;

2. Install the package on each node of the cluster

yum install pacemaker pcs psmisc policycoreutils-python -y

Tip: execute the above commands on each node of the cluster to install the package;

3. After the package is installed, start pcsd at each node and set pcsd to start automatically

systemctl enable pcsd --now

Tip: at this point, the pcsd installation and startup are completed;

II. Use pcs to quickly create a startup cluster

1. Set the same password for the hacluster user on each node of the cluster

echo "you password" |passwd --stdin hacluster

Tip: you can also create a new user without this user. In short, there is an identical account on each node of the cluster, and the password must be the same; It is recommended to use hacluster users;

2. Authenticate the user name and password of each node

Tip: if there are many cluster hosts, you can expand the feature with curly braces of the shell; This does not need to be done on each node, but on the node where the current pcs is located;

3. Create a cluster

4. Start the cluster

OK, a 3-node corosync+pacemaker cluster will be created and started;

Verification: check whether the corosync pacemaker is started at each node?

  node01

  node02

  node03

Tip: when viewing pacemaker on node03, it tells us here that I have configured the stonith option, but I have not found the stonith device;

III. pcs management cluster

1. View cluster status

Verify cluster configuration information

2. Turn off the stonith option

Tip: you can see that after we turn off the stonith option, no error will be reported when we verify the cluster configuration again;

Verification: check the status of pacemaker on node03 to see if there will be any more stonith errors?

Tip: you can see that the status of pacemaker is checked on the DC (node03) node of the cluster, and no stonith related errors are found;

3. Check the help information of 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 ~]# 

Tip: the usage of pcs command is very simple, that is, pcs + line selection + subcommand. One subcommand corresponds to the management of an object. For example, cluster is the management related to cluster configuration, and resource is the resource related configuration; If we want to view the detailed usage of a subcommand, we can use pcs + subcommand -- help to view it;

4. List resource agents

5. View the help of the specified resource agent

Tip: this help information is similar to the help information we used crmsh before. If there is required after the corresponding parameter, it means that this parameter is a required parameter;

Use an example of IP address: addvif: heart to define a resource

[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 ~]# 

Tip: the method of creating resources is very similar to that of crmsh, except that the commands are different. They all need to give a name to the resource, specify the resource agent, and then create it directly with given parameters; Use the pcs resource command to list resources;

Create a web resource

Merge webip and webserver into a group

View cluster configuration

Set node node02 to standby state

Tip: you can see that after node02 is set to standby state, the resources running on node02 will also be moved to other nodes;

Bring node02 Online

Tip: online is no longer the online command in crmsh, but unstandby;

Manually migrate resources to other nodes

Tip: in the front crmsh, we will manually migrate resources. By default, it will add a location constraint to the configuration interface. pcs is the same routine, and it will also add a location constraint to the configuration interface;

View the position constraint configuration in the configuration information

Tip: pcs constraint is to view all constraints of the cluster; Followed by location indicates that only position constraints are viewed;

Create positional constraints

 

Tip: we have created a location constraint to make the tendency of web service towards node01 positive and infinite, but the resources corresponding to node03 have not been moved to node01. The reason is that the tendency of web service towards node03 is also positive and infinite;

Verification: modify the tendency of web service to node03 to 100 to see if the web service will move to node01?

Tip: you can see that after changing the tendency of web service to node03 to 100, the web service running on node03 will move to node01;

Displays the propensity score of resources to each node of the cluster

Tip: crm_simulate -sL this command can print the score of the tendency of each resource of the current cluster to each node; Well, for other command usage of pcs, you can check the help and practice it slowly; Personally, I think it is better to use corosync+pacemaker high availability cluster and crmsh for manual cluster management; pcs is more suitable for managing and deploying clusters by script; For beginners, it is better to start with crmsh, which allows us to understand the high availability cluster architecture of corosync+pacemaker;

Posted by hagen00 on Wed, 18 May 2022 16:33:07 +0300