OpenGauss 启动集群竟靠删文件?这是什么「逆向操作」
集群管理软件介绍
OM
运维管理模块(OperationManager)提供openGauss日常运维、配置管理的管理接口和工具.使用python语言编写,底层调用cm相关命令
CM
(Cluster Manager)是一款集群资源管理软件。支持自定义资源监控,提供了数据库主备的状态监控、网络通信故障监控、文件系统故障监控、故障自动主备切换等能力。
CM由cm_server,cm_agent,cm_ctl组成。
- cm_agent是部署在数据库每个主机上,用来启停和监控各个数据库实例进程的数据库管理组件。
- cm_server是用来进行数据库实例管理和实例仲裁的组件。
- cm_ctl是openGauss提供的用来控制数据库实例服务的工具。该工具主要供OM调用,及数据库实例服务自恢复时使用。
- om_monitor 是OpenGauss 后台守护进程,由crontab 管理,可以自动启动
集群启动原理
启动命令
在gs_om -t start 启动集群中,实际最后调用的是cm_ctl start
cm_ctl start 源码函数调用
调用do_start()
调用StartWholeCluster() 启动集群
if (g_commandOperationInstanceId == 0 && g_command_operation_azName == NULL && g_commandOperationNodeId == 0)
...
CM_RETURN_IFERR(StartWholeCluster());
- 检查 集群的状态 CheckClusterRunningStatus()
检查状态的核心命令是通过pssh 读取hosts($GAUSSHOME/bin/hosts文件)列表,并发在所有节点执行 cm_ctl check -B cm_agent -T /opt/huawei/install/app/bin/cm_agent 命令
-
启动集群 ,调用 start_cluster()函数
start_cluster() 函数的核心原理是通过pssh 在集群每个节点执行rm 命令删除cluster_manual_start 等文件
pssh 执行的远程命令 source /etc/profile pssh -i \ -t 60 \ -O ConnectTimeout=5 \ -O ConnectionAttempts=3 \ -O ServerAliveInterval=15 \ -O ServerAliveCountMax=3 \ -h /opt/huawei/install/app/bin/hosts \ "rm -f /opt/huawei/install/app/bin/cluster_manual_start /opt/huawei/install/app/bin/instance_manual_start_*; if [ -f /opt/huawei/install/app/bin/cluster_manual_pause ]; then touch /opt/huawei/install/app/bin/cluster_manual_starting; fi" > /opt/huawei/install/app/bin/pssh.out if [ $? -ne 0 ]; then cat /opt/huawei/install/app/bin/pssh.out fi rm -f /opt/huawei/install/app/bin/pssh.out
删除文件触发启动集群
启动集群是通过删除$GAUSSHOME/bin下的cluster_manual_start文件来实现的
- 这些文件的删除会被集群监控进程(om_monitor)检测到
- 监控进程检测到文件被删除后,会触发实际的集群启动流程
om_monitor 接收信号启动集群
om_monitor进程在后台通过server_loop()函数一直监测请求,check_start_request()来检查是否需要启动集群.当cluster_manual_start文件被cm_ctl 删除后,触发启动集群.
通过系统函数access 检查$GAUSSHOME/bin/cluster_manual_start 文件是否存在,同时满足几个条件后,集群集群的变量startRequest 为True
检查条件 :
- disableManualStart : 检查 cluster_manual_start 文件是否存在
- isConfigExist : 检查CM Agent配置文件是否可读
- isBinaryExist : 检查CM Agent二进制文件是否可执行
- isConfigChange : 检查 cluster_dilatation_status 配置文件变更标志是否存在
check_start_request代码:
/* If the cluster manual start file exist, the CM Agent will not be started. */
const bool disableManualStart = (access(g_cmManualStartPath, F_OK) == 0);
/* If the config file can not be read, the CM Agent will not be started. */
const bool isConfigExist = (access(agentConfigFile, R_OK) == 0);
/* If the binary file can not be execute, the CM Agent will not be started. */
const bool isBinaryExist = (access(g_cmAgentBinPath, X_OK) == 0);
/* If the config change file exist, the CM Agent will not be started. */
const bool isConfigChange = (access(g_cmStaticConfigChangeFlagFilePath, F_OK) == 0);
/* Normal Scenario. */
if (!disableManualStart && isBinaryExist && isConfigExist && !isConfigChange) {
startRequest = true;
agentRestartCount = 0;
}
启动集群时om_monitor 日志会打印出cluster_manual_start=0的信息
集群启动步骤
每一个节点单独启动本节点的cm_agent,cm_server,gaussdb 进程
首先启动cm_agent
om_monitor 调用start_cm_agent()函数启动cm_agent 进程 。
接着启动 cm_server
cm_agent 是一个多线程的监控程序,它通过agentStartAndStopMain线程启动cm_server
然后启动data node
小结
OpenGauss 集群的启动流程如下:执行 cm_ctl start
命令时,会删除各节点 $GAUSSHOME/bin
目录下的 cluster_manual_start
文件。删除操作完成后,om_monitor
进程将触发 cm_agent
进程启动。随后,cm_agent
进程会依次启动 cm_server
进程和数据节点进程(gaussdb
)。当所有节点的相关进程均启动完成后,整个集群即完成启动