在CentOS 7中配置高可用性集群

时间:2020-02-23 14:40:32  来源:igfitidea点击:

在开始配置高可用性群集之前,我们必须了解与群集相关的基本术语。在本文中,我将分步共享"使用3个虚拟机在CentOS Linux 7中配置高可用性集群"的指南。这些虚拟机在Linux服务器上安装的Oracle VirtualBox上运行。

说明:

在" Red Hat 7"上配置高可用性集群的步骤将与" CentOS 7"相同。在RHEL系统上,我们必须具有RHN的有效订阅,或者我们可以配置本地脱机存储库,通过该本地脱机存储库,yum软件包管理器可以安装提供的rpm及其依赖项。

高可用集群的功能?

ClusterLabs堆栈结合了" Corosync"和" Pacemaker",定义了一个开放源代码,高可用性集群,该集群适用于小型和大型部署。

  • 检测和恢复机器和应用程序级别的故障

  • 几乎支持任何冗余配置

  • 支持集群和资源驱动的集群

  • 用于配置仲裁丢失的可配置策略(当多台计算机发生故障时)

  • 支持应用程序启动/关闭顺序,无论应用程序在哪台计算机上

  • 支持必须/一定不能在同一台计算机上运行的应用程序

  • 支持需要在多台计算机上处于活动状态的应用程序

  • 支持多种模式的应用程序(例如主/从)

什么是Pacemaker?

我们将使用Pacemaker和corosync配置高可用性群集。 " Pacemaker"是一个集群资源管理器,即负责所部署软件的生命周期的逻辑–甚至间接影响整个系统或者它们的互连–在一组计算机(也称为节点)的控制下,并由规定的规则驱动。

通过利用首选群集基础结构(Corosync或者Heartbeat)提供的消息传递和成员资格功能(可能还通过利用其他部分)检测并从节点和资源级故障中恢复,从而为群集服务(即资源)提供最大的可用性。整个群集堆栈的数量。

搭建环境

首先,在开始配置高可用性集群之前,让我们使用CentOS 7来启动我们的虚拟机。我正在使用Oracle VirtualBox。我们也可以在Linux环境中安装Oracle VirtualBox。

以下是我的虚拟机的配置详细信息

属性node1node2node3
OSCentOS 7CentOS 7
vCPU222
内存2GB2GB
磁盘10GB10GB10GB
FQDNnode1. example.comnode2. example.comnode3. example.com
主机名node1node2node3
IP地址(内部)10.0.2.2010.0.2.2110.0.2.22
IP地址(外部)DHCPDHCPDHCP

编辑/etc/hosts文件并添加IP地址,然后为每个可用的群集节点网络接口添加一个FQDN和一个简短的群集节点名称。

[root@node1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.2.20 node1.example.com node1
10.0.2.21 node2.example.com node2
10.0.2.22 node3.example.com node3
[root@node2 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.2.20 node1.example.com node1
10.0.2.21 node2.example.com node2
10.0.2.22 node3.example.com node3
[root@node3 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.2.20 node1.example.com node1
10.0.2.21 node2.example.com node2
10.0.2.22 node3.example.com node3

要完成此操作,我们必须检查并确认集群节点之间的连接。我们可以通过简单地向每个群集节点释放一个ping命令来做到这一点。

在"所有节点"上停止并禁用网络管理器

[root@node1 ~]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.

说明:

我们必须删除或者禁用NetworkManager服务,因为我们要避免对群集节点上的网络接口进行任何自动配置。

删除或者禁用NetworkManager服务后,必须重新启动网络服务。

配置NTP

要配置高可用性群集,重要的是连接群集中的所有节点并将其同步到NTP服务器。由于我的计算机处于IST时区,因此我将使用印度NTP服务器池。

[root@node1 ~]# systemctl start ntpd
[root@node1 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

安装必备的rpm

高可用性软件包不是CentOS存储库的一部分,因此我们将需要epel-release存储库。

提示:

在RHEL 8中安装EPEL存储库的步骤

[root@node1 ~]# yum install epel-release -y

pcs是pcaemaker软件及其所有依赖项fence-agents-all将安装所有可用于Red Hat Cluster的默认防护代理。

[root@node1 ~]# yum install pcs fence-agents-all -y

添加防火墙规则

[root@node1 ~]# firewall-cmd --permanent --add-service=high-availability; firewall-cmd --reload
success
success

说明:

如果我们直接使用iptables或者除firewalld以外的其他防火墙解决方案,只需打开以下端口:TCP端口2224、3121和21064,以及UDP端口5404、5405.
如果在测试过程中遇到任何问题,则可能要完全禁用防火墙和SELinux,直到一切正常为止。这可能会导致严重的安全问题,因此不应在暴露于外界的计算机上执行此操作,但在受保护主机上进行开发和测试期间可能是适当的。

配置高可用性集群

安装的软件包将使用禁用的密码创建一个hacluster用户。虽然这对于在本地运行pcs命令很好,但是该帐户需要一个登录密码才能执行诸如同步corosync配置或者在其他节点上启动和停止集群之类的任务。

使用以下命令在每个群集节点上为Pacemaker群集设置"密码"。我的密码是"密码"

[root@node1 ~]# echo password | passwd --stdin hacluster
Changing password for user hacluster.
passwd: all authentication tokens updated successfully.

在每个节点上启动Pacemaker集群管理器:

[root@node1 ~]# systemctl enable --now pcsd
Created symlink from /etc/systemd/system/multi-user.target.wants/pcsd.service to /usr/lib/systemd/system/pcsd.service.

配置Corosync

要配置Openstack高可用性,我们需要在任何一个节点上配置corosync,使用pcs cluster auth身份验证为hacluster用户

[root@node1 ~]# pcs cluster auth node1.example.com node2.example.com node3.example.com
Username: hacluster
Password:
node2.example.com: Authorized
node1.example.com: Authorized
node3.example.com: Authorized

说明:

如果我们在此步骤遇到任何问题,请检查firewalld/iptables或者selinux策略

最后,在第一个节点上运行以下命令以创建集群并启动它。这里我们的集群名称将是mycluster

[root@node1 ~]# pcs cluster setup --start --name mycluster node1.example.com node2.example.com node3.example.com
Destroying cluster on nodes: node1.example.com, node2.example.com, node3.example.com...
node3.example.com: Stopping Cluster (pacemaker)...
node2.example.com: Stopping Cluster (pacemaker)...
node1.example.com: Stopping Cluster (pacemaker)...
node1.example.com: Successfully destroyed cluster
node2.example.com: Successfully destroyed cluster
node3.example.com: Successfully destroyed cluster
Sending 'pacemaker_remote authkey' to 'node1.example.com', 'node2.example.com', 'node3.example.com'
node1.example.com: successful distribution of the file 'pacemaker_remote authkey'
node2.example.com: successful distribution of the file 'pacemaker_remote authkey'
node3.example.com: successful distribution of the file 'pacemaker_remote authkey'
Sending cluster config files to the nodes...
node1.example.com: Succeeded
node2.example.com: Succeeded
node3.example.com: Succeeded
Starting cluster on nodes: node1.example.com, node2.example.com, node3.example.com...
node2.example.com: Starting Cluster...
node1.example.com: Starting Cluster...
node3.example.com: Starting Cluster...
Synchronizing pcsd certificates on nodes node1.example.com, node2.example.com, node3.example.com...
node2.example.com: Success
node1.example.com: Success
node3.example.com: Success
Restarting pcsd on the nodes in order to reload the certificates...
node1.example.com: Success
node3.example.com: Success
node2.example.com: Success

启用集群服务,即pacemakercorosync,以便它们可以在启动时自动启动

[root@node1 ~]# pcs cluster enable --all
node1.example.com: Cluster Enabled
node2.example.com: Cluster Enabled
node3.example.com: Cluster Enabled

最后检查集群状态

[root@node1 ~]# pcs cluster status
Cluster Status:
 Stack: corosync
 Current DC: node2.example.com (version 1.1.18-11.el7_5.3-2b07d5c5a9) - partition with quorum
 Last updated: Sat Oct 27 08:41:52 2016
 Last change: Sat Oct 27 08:41:18 2016 by hacluster via crmd on node2.example.com
 3 nodes configured
 0 resources configured
PCSD Status:
  node3.example.com: Online
  node1.example.com: Online
  node2.example.com: Online

使用corosync-quorumtool命令检查集群的Quorum状态。

[root@node1 ~]# corosync-quorumtool
Quorum information
-----------------
Date:             Sat Oct 27 08:43:22 2016
Quorum provider:  corosync_votequorum
Nodes:            3
Node ID:          1
Ring ID:          1/8
Quorate:          Yes
Votequorum information
---------------------
Expected votes:   3
Highest expected: 3
Total votes:      3
Quorum:           2
Flags:            Quorate
Membership information
---------------------
    Nodeid      Votes Name
         1          1 node1.example.com (local)
         2          1 node2.example.com
         3          1 node3.example.com

要获取集群的实时状态,请使用crm_mon

[root@node1 ~]# crm_mon
Connection to the CIB terminated

验证集群配置

在进行任何更改之前,最好检查一下配置的有效性。

[root@node1 ~]#  crm_verify -L -V
   error: unpack_resources:     Resource start-up disabled since no STONITH resources have been defined
   error: unpack_resources:     Either configure some or disable STONITH with the stonith-enabled option
   error: unpack_resources:     NOTE: Clusters with shared data need STONITH to ensure data integrity
Errors found during check: config not valid

如我们所见,该工具发现了一些错误。

为了保证数据的安全性,默认情况下启用[5]防护(也称为" STONITH")。但是,它也知道何时未提供STONITH配置,并将其报告为问题(因为如果出现需要进行节点防护的情况,集群将无法继续运行)。

我们将暂时禁用此功能,并在以后进行配置。要禁用STONITH,请将两个控制器节点上的启用了stonith的集群选项设置为false:

警告:

对于生产集群而言,使用stonith-enabled = false完全不合适。它告诉集群简单地假装发生故障的节点已安全地处于关闭状态。一些供应商将拒绝支持STONITH禁用的群集。

[root@node1 ~]# pcs property set stonith-enabled=false

接下来重新验证集群

[root@node1 ~]# crm_verify -L -V

这全部与在Linux上配置高可用性群集有关,下面是有关群集的更多文章,我们可以用来了解群集体系结构,资源组和资源限制等。