#openGauss #入门 #安装 #数据库 #开源
知识来源:docs-opengauss.osinfra.cn/zh/
配置方法
安装好自定义资源后,若要使用自定义资源监控功能,需要配置两个文件:
1. 资源脚本
主要用于指定资源的启停、状态检查等指令,一个样例如下:
#!/bin/bash
#set -ex #取消该行注释可帮助调试脚本
#资源名称
resName=sharding
#资源binpath
shardingPath=/home/test/home/apache-shardingsphere-5.1.1-shardingsphere-proxy-bin/bin
#用于过滤资源实例的命令关键词
cmdKey=org.apache.shardingsphere.proxy.Bootstrap
#用于保存首次检测到资源僵死时间的文件
phony_dead_time_file=.sharding_phony_dead_time
#最长僵死时间,单位为s
PHONY_MAX_TIME=20
function exec_start
{
#资源启动命令
sh ${shardingPath}/start.sh; exit $?
}
function exec_stop
{
#资源停止命令
sh ${shardingPath}/stop.sh; exit $?
}
function exec_check
{
#查询资源实例pid
pid=`ps x | grep "$cmdKey" | grep -v grep | awk '{print $1}'`
if [ "${pid}" == "" ]; then
echo "$resName is not running."
exit 1
fi
#查询资源实例进程状态
state=`cat /proc/$pid/status | grep "State" | awk '{print $2}'`
if [ "$state" == "T" ]; then
#僵死检查和处理
if [ ! -f $phony_dead_time_file ]; then
touch ./${phony_dead_time_file}
echo "export firstphonytime=''" > ./${phony_dead_time_file}
fi
source ./$phony_dead_time_file;
curtime=$(date +%s);
if [ "$firstphonytime" == "" ]; then
#首次检测到资源僵死,将首次检测到僵死的时间写入僵死时间存储文件
#firstphonytime为用于保存当前资源实例僵死时间的变量名称,
#若当前节点存在多个自定义资源实例,该名称需要指定为不同的名称
echo "export firstphonytime=$curtime" > ./$phony_dead_time_file;
exit 0;
fi
dead_time=$(( $curtime - $firstphonytime ));
#若僵死时间大于等于用户设定的最大僵死时间,则立即杀死资源实例,否则不做处理正常退出
if [ $dead_time -ge $PHONY_MAX_TIME ]; then
echo "$resName is detected in a state of phony dead(T) and will be forcibly killed!"
kill -9 $pid
rm ./${phony_dead_time_file} -f
sh ${shardingPath}/start.sh; exit $?
else
exit 0
fi
elif [ "$state" == "S" ]; then
#未处于僵死状态清理环境后正常退出
rm ./${phony_dead_time_file} -f
exit 0
fi
}
#以下为固定接口无需更改,必须实现
if [ $1 == '-start' ]; then
exec_start $2
elif [ $1 == '-stop' ]; then
exec_stop $2
elif [ $1 == '-check' ]; then
exec_check $2
elif [ $1 == '-clean' ]; then
exec_stop $2
elif [ $1 == '-reg' ]; then
exit 0
elif [ $1 == '-unreg' ]; then
exit 0
elif [ $1 == '-isreg' ]; then
exit 11
else
echo "Please confirm the input parameters."
exit 1
fi
以上样例可以作为模板使用,用户主要需要修改的地方包括: 资源名称、资源binPath、用于过滤资源实例的命令关键词、用于保存首次检测到资源僵死时间的文件(可选)、最长僵死时间、记录首次僵死时间的变量名(如果同一节点存在多个不同的自定义资源实例)
#openGauss #入门 #安装 #数据库 #开源