New features of openGauss 3.0.0 - new cluster management tools to improve high availability

As an enterprise-level open source relational database, openGauss has the characteristics of high performance, high availability, high security, and easy operation and maintenance. The addition of CM further improves the openGauss cluster in terms of ease of operation and maintenance and reliability.

What is CM?

CM (Cluster Manager) is a cluster resource management software. It supports self-defined resource monitoring, and provides the ability to monitor the status of the active and standby databases, network communication fault monitoring, file system fault monitoring, and automatic active-standby switchover.

What can a CM do?

CM provides a wealth of cluster management capabilities, such as cluster, node, instance-level startup and shutdown, cluster status query, master selection, active-standby switching, log management, etc.

The CM architecture diagram is shown above, and the component includes 4 executable files:

cm_server : The server side of cm, responsible for collecting the status reported by cma, and serving as the arbitration center and global configuration center, whether the cluster can run stably and whether the standby instance can be switched to the master normally after a single point of failure occurs to ensure the availability of the cluster. Both are related to the stability of the CMS.

cm_agent : Usually, one is installed on each machine in the cluster, which is responsible for managing the status detection and reporting of all instances of this node and the execution of commands issued by cms.

om_monitor : Usually, one is installed on each machine in the cluster, which is responsible for ensuring the health of the cm_agent process of this node.

cm_ctl : The client tool for cm that provides cluster management operations.

Process monitoring

After cm takes over the cluster, it will periodically detect and monitor all processes in the cluster (including cma, cms, openGauss and other processes), and is responsible for the keep alive and zombie recovery of cluster processes.

Database status collection

cma will periodically collect the running status of the openGauss database. The collected indicators include the active and standby status, log location and playback rate, log sending and receiving progress and other information, and will be summarized in cms. This information will be used for master selection arbitration and tool display.

log compression

CMA provides log management capabilities. It monitors log directories, automatically archives, and cleans logs through dimensions such as the total size of log files, the number of log files, and log time.

Reliable Primary Arbitration

当数据库主机发生不可恢复的故障而无法继续提供服务时,集群管理会感知并基于qurom协议,进行选主仲裁。CM的仲裁都是使用的状态机模式,依据当前数据库状态进行仲裁逻辑的推进。

以上是CMS选主仲裁的时序图,总体流程包含上报和仲裁两大部分(仲裁命令实际实时都是通过信息上报获取的,图中返回结果只是为了方便理解)。

信息采集上报:

每个数据库实例的状态都会被cma定时采集并上报cms。

选主仲裁:

cms周期性的检测数据库的主备状态,如果发现主机不能够正常提供服务,则会触发选主仲裁。

1. 状态:无主。

操作:给所有备机发送命令,使其进入LOCK1状态。

说明: 如果备机此时连接主机,则lock1不会成功。Lock1状态成功主要有两个条件:1)备机与主机复制链路永久断开且不再主动重连。2)备机日志全部回放结束,不再增加。

2. 状态:(n+1)/2个备机已经进入LOCK1状态。

操作:选合适的主,发送failover

说明:根据qurom的特点,当(n+1)/2个备机进入LOCK1状态后,这几个备机中一定有至少1个同步备,cms从这几个备机中找到日志最多的节点(一定是同步备),发送升主命令。如果有多个满足条件的备机,则按照以下策略:

a)原主能起来,则选原主

b)选择与原主同AZ的

c)按节点顺序

3. 状态:新主升主成功。

操作:给主备机发送unlock/lock2消息,恢复成正常状态

说明:如果主机处于lock1状态,则给主机发送unlock消息使其退出lock1状态,如果备机处于lock1状态,则给备机发送lock2消息,指定新主ip,使其连接新主。

通过以上逻辑,CM保证了集群永远只有一个可写主机,且RPO=0。

CM集群的安装

在安装带CM的openGauss之前,需要创建clusterconfig.xml配置文件。XML文件包含部署openGauss+CM的服务器信息、安装路径、IP地址以及端口号等。用于告知openGauss、CM如何部署。用户需根据不同场配置对应的XML文件,带CM的安装,除安装配置文件需要添加CM外,其余步骤与openGauss安装完全相同。

下面以一主二备的部署方案为例,说明如何创建带CM的openGauss集群XML配置文件。以下value取值信息仅为示例,可自行替换。每行信息均有注释进行说明。

集群安装xml样例

注:此处xml中的ip、nodeNames、path等变量均只作为演示,需要按实际情况填写。

<?xml version="1.0" encoding="UTF-8"?><ROOT>    <!-- openGauss整体信息 -->    <CLUSTER>    <!-- 数据库名称 -->        <PARAM name="clusterName" value="dbCluster" />    <!-- 数据库节点名称(hostname) -->        <PARAM name="nodeNames" value="node1,node2,node3" />    <!-- 节点IP,与nodeNames一一对应 -->        <PARAM name="backIp1s" value="192.168.0.11,192.168.0.12,192.168.0.13"/>    <!-- 数据库安装目录-->        <PARAM name="gaussdbAppPath" value="/opt/huawei/install/app" />    <!-- 日志目录-->        <PARAM name="gaussdbLogPath" value="/var/log/omm" />    <!-- 临时文件目录-->        <PARAM name="tmpMppdbPath" value="/opt/huawei/tmp"/>    <!--数据库工具目录-->        <PARAM name="gaussdbToolPath" value="/opt/huawei/install/om" />    <!--数据库core文件目录-->        <PARAM name="corePath" value="/opt/huawei/corefile"/>    <!-- openGauss类型,此处示例为单机类型,“single-inst”表示单机一主多备部署形态-->        <PARAM name="clusterType" value="single-inst"/>    </CLUSTER>    <!-- 每台服务器上的节点部署信息 -->    <DEVICELIST>        <!-- node1上的节点部署信息 -->        <DEVICE sn="1000001">        <!-- node1的hostname -->            <PARAM name="name" value="node1"/>        <!-- node1所在的AZ及AZ优先级 -->            <PARAM name="azName" value="AZ1"/>            <PARAM name="azPriority" value="1"/>        <!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->            <PARAM name="backIp1" value="192.168.0.11"/>            <PARAM name="sshIp1" value="192.168.0.11"/>                    <!--CM-->     <!--CM数据目录-->            <PARAM name="cmDir" value="/opt/huawei/install/data/cm" />            <PARAM name="cmsNum" value="1" />      <!--CM监听端口-->            <PARAM name="cmServerPortBase" value="5000" />            <PARAM name="cmServerlevel" value="1" />      <!--CM所有实例所在节点名及监听ip-->            <PARAM name="cmServerListenIp1" value="192.168.0.11,192.168.0.12,192.168.0.13" />            <PARAM name="cmServerRelation" value="node1,node2,node3" />                  <!--dbnode-->        <PARAM name="dataNum" value="1"/>      <!--DBnode端口号-->        <PARAM name="dataPortBase" value="26000"/>      <!--DBnode主节点上数据目录,及备机数据目录-->        <PARAM name="dataNode1" value="/opt/huawei/install/data/db1,node2,/opt/huawei/install/data/db1,node3,/opt/huawei/install/data/db1"/>      <!--DBnode节点上设定同步模式的节点数-->        <PARAM name="dataNode1_syncNum" value="0"/>        </DEVICE>
       <!-- node2上的节点部署信息,其中“name”的值配置为主机名称(hostname) -->        <DEVICE sn="1000002">            <PARAM name="name" value="node2"/>            <PARAM name="azName" value="AZ1"/>            <PARAM name="azPriority" value="1"/>            <!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->            <PARAM name="backIp1" value="192.168.0.12"/>            <PARAM name="sshIp1" value="192.168.0.12"/>            <PARAM name="cmDir" value="/opt/huawei/install/data/cm" />        </DEVICE>
       <!-- node3上的节点部署信息,其中“name”的值配置为主机名称(hostname) -->        <DEVICE sn="1000003">            <PARAM name="name" value="node3"/>            <PARAM name="azName" value="AZ1"/>            <PARAM name="azPriority" value="1"/>            <!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->            <PARAM name="backIp1" value="192.168.0.13"/>            <PARAM name="sshIp1" value="192.168.0.13"/>            <PARAM name="cmDir" value="/opt/huawei/install/data/cm" />        </DEVICE>    </DEVICELIST></ROOT>

安装过程与openGauss安装一致,如需请查看官网。

安装后集群状态确认

   部分出现名词的解析:


CMServer State :cm的状态信息。

node:节点号和节点名称。

instance:表示instanceId(此id为集群内的概念,每个集群中的实例都会拥有一个独一无二的instanceId,用来标识此实例)。

state:cm的角色信息,primary表示主,standby表示备,unknown表示无法获取到cm的角色信息(一般故障场景才会出现unknown)。

Cluster State:集群相关状态信息。

cluster_state:集群状态,一共有三种状态:Normal,表示数据库正常;Degraded,表示数据库可用,但有某个数据节点存在异常;Unavailable,表示数据库不可用。

Datanode State:数据库各个实例的信息。

node:数据库实例所在节点的节点号和节点名称。

instance:表示instanceId(此id为集群内的概念,每个集群中的实例都会拥有一个独一无二的instanceId,用来标识此实例)。

state:数据库实例的状态信息,由三个具体的信息注册:第一个字段P/S表示初始的角色信息,P为主,S为备;第二个字段为角色信息;第三个字段为数据库具体的状态。

至此,一个由CM管理的一主两备openGauss集群就部署好了,后续就可以用过CM提供的工具对集群做一些基本的运维操作。

CM客户端工具cm_ctl

cm_ctl客户端工具提供了丰富的集群操作和管理接口,使集群管理变得更加便捷和可靠。

功能概览

启停集群

停止整个集群:

任意机器,普通用户下执行命令:

cm_ctl stop

执行结果:

任意机器上查询状态:

cm_ctl query -Cv

查询结果:

启动整个集群

任意机器上执行命令:

cm_ctl start

执行结果:

任意机器上查询状态:

cm_ctl query -Cv

查询结果:

启停节点

任意机器上执行停止命令:

#停止节点1上的数据库实例,-n后面指定节点号,-D后面指定数据库实例的数据目录。cm_ctl stop -n 1 -D /home/omm/cluster/data/dn1

任意机器上执行启动命令:

#启动节点1上的数据库实例,-n后面跟节点号,-D后面跟数据库实例的数据目录。cm_ctl start -n 1 -D /home/omm/cluster/data/dn1

openGauss数据库主备切换

指定数据库切换为主

任意机器执行命令:

#-n参数后面跟的是需要升主的数据节点的节点id,-D后面跟的是数据目录(可参考前面步骤获得数据目录)cm_ctl switchover -n 3 -D /home/omm/cluster/data/dn3

结果:

任意机器上查询状态:

cm_ctl query -Cv

查询结果:

恢复成初始主备关系

任意节点执行命令:

cm_ctl switchover -a

结果:

任意机器上查询状态:

cm_ctl query -Cv

代码片段:可切换语言,无法单独设置文字格式


查询结果:

CM集群部分高可用能力

CM支持数据库进程保活,备机故障后自动主备切换,备机日志损坏后的自动重建等高可用能力。

自动恢复数据库实例演示

在节点1(node1)上,故障注入

#查看数据库进程id,并kill掉数据库进程ps -uxkill -9 [pid]

查看进程示例:

查看进程信息,发现数据库进程已经被拉起

ps -ux

查看进程示例:

其他高可用场景能力大家可以实际安装体验。

CM集群管理的加入,使openGauss的高可用能力得到了巨大的提升,其强大的故障检测和自动恢复能力使数据库在应对各种故障场景的运维变得更加简单可靠。

欢迎访问openGauss官方网站

openGauss开源社区官方网站:

https://opengauss.org

openGauss组织仓库:

https://gitee.com/opengauss

openGauss镜像仓库:

https://github.com/opengauss-mirror

扫码关注我们

微信公众号|openGauss

微信社群小助手|openGauss-bot

本文分享自微信公众号 - openGauss(openGauss)。
如有侵权,请联系 [email protected] 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/5059795/blog/5515466