[CP] support ob rpm platform standalone systemd service

This commit is contained in:
LINxiansheng 2024-01-11 15:42:59 +00:00 committed by ob-robot
parent 340b70b41f
commit 4349bb8f9f
15 changed files with 474 additions and 1 deletions

4
.gitignore vendored
View File

@ -289,6 +289,10 @@ tools/deploy/single-with-proxy.yaml
tools/deploy/single.yaml
tools/docker/standalone/boot
tools/docker/standalone/init_store_for_fast_start.py
tools/rpm/systemd/profile/oceanbase-service.sh
tools/rpm/systemd/profile/post_install.sh
tools/rpm/systemd/profile/pre_uninstall.sh
tools/rpm/systemd/profile/post_uninstall.sh
############# unittest #############
unittest/**/test_*

View File

@ -44,18 +44,46 @@ set(CPACK_RPM_PACKAGE_DESCRIPTION "OceanBase is a distributed relational databas
set(CPACK_RPM_PACKAGE_LICENSE "Mulan PubL v2.")
set(CPACK_RPM_DEFAULT_USER "admin")
set(CPACK_RPM_DEFAULT_GROUP "admin")
if (OB_BUILD_OPENSOURCE)
set(DEBUG_INSTALL_POST "mv $RPM_BUILD_ROOT/../server/home/admin/oceanbase/bin/obshell %{_builddir}/obshell; %{_rpmconfigdir}/find-debuginfo.sh %{?_find_debuginfo_opts} %{_builddir}/%{?buildsubdir}; mv %{_builddir}/obshell $RPM_BUILD_ROOT/../server/home/admin/oceanbase/bin/obshell; %{nil}")
else()
set(DEBUG_INSTALL_POST "%{_rpmconfigdir}/find-debuginfo.sh %{?_find_debuginfo_opts} %{_builddir}/%{?buildsubdir};%{nil}")
endif()
set(CPACK_RPM_SPEC_MORE_DEFINE
"%global _missing_build_ids_terminate_build 0
%global _find_debuginfo_opts -g
%define __strip ${CMAKE_SOURCE_DIR}/deps/3rd/usr/local/oceanbase/devtools/bin/llvm-strip
%undefine __brp_mangle_shebangs
%global __requires_exclude ^\(/bin/bash\|/usr/bin/\.*\)$
%define __debug_install_post %{_rpmconfigdir}/find-debuginfo.sh %{?_find_debuginfo_opts} %{_builddir}/%{?buildsubdir};%{nil}
%define __debug_install_post ${DEBUG_INSTALL_POST}
%if \\\"%name\\\" != \\\"oceanbase-ce-sql-parser\\\" && \\\"%name\\\" != \\\"oceanbase-sql-parser\\\"
%debug_package
%endif
")
if (OB_BUILD_OPENSOURCE)
set(CPACK_RPM_PACKAGE_REQUIRES "jq, systemd")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/oceanbase-service.sh.template
${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/oceanbase-service.sh
@ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/post_install.sh.template
${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/post_install.sh
@ONLY)
set(CPACK_RPM_SERVER_POST_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/post_install.sh)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/pre_uninstall.sh.template
${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/pre_uninstall.sh
@ONLY)
set(CPACK_RPM_SERVER_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/pre_uninstall.sh)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/post_uninstall.sh.template
${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/post_uninstall.sh
@ONLY)
set(CPACK_RPM_SERVER_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/post_uninstall.sh)
endif()
## TIPS
#
# - PATH is relative to the **ROOT directory** of project other than the cmake directory.
@ -68,6 +96,7 @@ install(PROGRAMS
tools/import_time_zone_info.py
tools/import_srs_data.py
${CMAKE_BINARY_DIR}/src/observer/observer
deps/3rd/home/admin/oceanbase/bin/obshell
DESTINATION bin
COMPONENT server)
else()
@ -100,6 +129,17 @@ install(
DESTINATION admin
COMPONENT server)
install(FILES
tools/rpm/systemd/profile/oceanbase.cnf
tools/rpm/systemd/profile/oceanbase-pre.json
tools/rpm/systemd/profile/oceanbase.service
tools/rpm/systemd/profile/oceanbase-service.sh
tools/rpm/systemd/profile/post_install.sh
tools/rpm/systemd/profile/post_uninstall.sh
tools/rpm/systemd/profile/pre_uninstall.sh
DESTINATION profile
COMPONENT server)
## oceanbase-cdc
if (NOT OB_SO_CACHE AND OB_BUILD_CDC)
include(GNUInstallDirs)

View File

@ -8,6 +8,7 @@ os=7
arch=aarch64
repo=http://mirrors.aliyun.com/oceanbase/community/stable/el/7/aarch64/
[deps]
devdeps-gtest-1.8.0-132022101316.el7.aarch64.rpm
devdeps-isa-l-static-2.22.0-22022092915.el7.aarch64.rpm
@ -42,6 +43,7 @@ obdevtools-llvm-11.0.1-312022092921.el7.aarch64.rpm
[tools-deps]
devdeps-oblogmsg-1.0-52022113019.el7.aarch64.rpm
devdeps-rocksdb-6.22.1.1-52022100420.el7.aarch64.rpm
obshell-4.2.2.0-82024011102.el7.aarch64.rpm target=community
[test-utils]
ob-deploy-2.3.0-4.el7.aarch64.rpm target=community

View File

@ -9,6 +9,7 @@ os=7
arch=x86_64
repo=http://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/
[deps]
devdeps-gtest-1.8.0-132022101316.el7.x86_64.rpm
devdeps-isa-l-static-2.22.0-22022092915.el7.x86_64.rpm
@ -45,8 +46,10 @@ obdevtools-llvm-11.0.1-312022092921.el7.x86_64.rpm
[tools-deps]
devdeps-oblogmsg-1.0-52022113019.el7.x86_64.rpm
devdeps-rocksdb-6.22.1.1-52022100420.el7.x86_64.rpm
obshell-4.2.2.0-82024011102.el7.x86_64.rpm target=community
[test-utils]
ob-deploy-2.3.0-4.el7.x86_64.rpm target=community
obclient-2.2.2-1.el7.x86_64.rpm target=community
libobclient-2.2.2-3.el7.x86_64.rpm target=community
obshell-4.2.2.0-32024010810.el7.x86_64.rpm target=community

View File

@ -8,6 +8,7 @@ os=8
arch=aarch64
repo=http://mirrors.aliyun.com/oceanbase/community/stable/el/8/aarch64/
[deps]
devdeps-gtest-1.8.0-132022101316.el8.aarch64.rpm
devdeps-isa-l-static-2.22.0-22022092915.el8.aarch64.rpm
@ -42,6 +43,7 @@ obdevtools-llvm-11.0.1-312022092921.el8.aarch64.rpm
[tools-deps]
devdeps-oblogmsg-1.0-52022113019.el8.aarch64.rpm
devdeps-rocksdb-6.22.1.1-52022100420.el8.aarch64.rpm
obshell-4.2.2.0-82024011102.el8.aarch64.rpm target=community
[test-utils]
ob-deploy-2.3.0-4.el8.aarch64.rpm target=community

View File

@ -8,6 +8,7 @@ os=8
arch=x86_64
repo=http://mirrors.aliyun.com/oceanbase/community/stable/el/8/x86_64/
[deps]
devdeps-gtest-1.8.0-132022101316.el8.x86_64.rpm
devdeps-isa-l-static-2.22.0-22022092915.el8.x86_64.rpm
@ -44,6 +45,7 @@ obdevtools-llvm-11.0.1-312022092921.el8.x86_64.rpm
[tools-deps]
devdeps-oblogmsg-1.0-52022113019.el8.x86_64.rpm
devdeps-rocksdb-6.22.1.1-52022100420.el8.x86_64.rpm
obshell-4.2.2.0-82024011102.el8.x86_64.rpm target=community
[test-utils]
ob-deploy-2.3.0-4.el8.x86_64.rpm target=community

View File

@ -0,0 +1,23 @@
# 通过yum和systemd的方式安装OceanBase数据库
如果你想在linux rpm平台上部署oceanbase,可以使用yum进行单节点安装,并通过systemd进行简单管理
**注意**
- 该方法仅能用做学习研究或测试使用;
- 千万不要使用此方法用于带有重要数据的场景,比如生产环境。
## 安装方法
现在暂时只支持RPM平台系统,可以通过以下指令进行安装和启动:
```bash
yum install oceanbase-ce
systemctl start oceanbase
```
## systemd介绍
Systemd提供了自动化管理oceanbase的启动和停止,可以通过systemctl指令对oceanbase进行管理控制,例如:
```bash
systemctl {start|stop|restart|status} oceanbase
```
## 通过systemd配置oceanbase
systemd提供了配置文件`/etc/oceanbase.cnf`,可以在启动前修改配置进行带参启动

View File

@ -0,0 +1,23 @@
# Installing OceanBase Database via yum and systemd
If you want to deploy OceanBase on a Linux RPM platform, you can use yum for single-node installation and simple management with systemd.
**WARNING**
- The installation method is just used for study or test;
- You should not deploy it with important data as it is not used in production environment.
## Installation Method
Now systemd only support RPM platform and you can install and run oceanbase service using the following command:
```bash
yum install oceanbase-ce
systemctl start oceanbase
```
## Overview of systemd
Systemd provides automatic oceanbase startup and shutdown. It also enables manual server management using the systemctl command. For example:
```bash
systemctl {start|stop|restart|status} oceanbase
```
## Oceanbase configuration by systemd
Systemd provide `/etc/oceanbase.cnf` to config oceanbase before startup.

View File

@ -0,0 +1,25 @@
{
"obshell": {
"agentInfo": {
"ip": "127.0.0.1",
"port": 2886
},
"zoneName": "zone1"
},
"oceanbase_ce": {
"cluster": {
"clusterId": 1,
"clusterName": "ob"
},
"server": {
"restart": true,
"scope": {
"type": "server",
"target": [
"127.0.0.1:2886"
]
},
"observerConfig": {}
}
}
}

View File

@ -0,0 +1,296 @@
#!/bin/bash
DATE=`date '+%Y-%m-%d %H:%M:%S'`
ip='127.0.0.1'
port=2886
url="http://$ip:$port"
unix_socket="/tmp/obshell/$port.sock"
prefix=@CPACK_PACKAGING_INSTALL_PREFIX@
obshell="$prefix/bin/obshell"
function prepare_config_json {
cnf_file='/etc/oceanbase.cnf'
json_pre_file="$prefix/profile/oceanbase-pre.json"
json_file="$prefix/profile/oceanbase.json"
rm -rf $json_file
cp $json_pre_file $json_file
local temp_file=$(mktemp)
while IFS='=' read -r key value; do
key=$(echo "$key" | awk '{$1=$1};1')
value=$(echo "$value" | awk '{$1=$1};1')
value=$(echo "$value" | sed 's/^"//' | sed 's/"$//')
if [[ -n "$key" && ! "$key" =~ ^\; ]]; then
if [[ $key == *"rootPwd"* ]]; then
jq --arg parent "oceanbase_ce" --arg child "cluster" --arg key "$key" --arg value "$value" '.[$parent][$child][$key] = $value' "$json_file" > "$temp_file"
mv "$temp_file" "$json_file"
else
jq --arg parent "oceanbase_ce" --arg child "server" --arg grandchild "observerConfig" --arg key "$key" --arg value "$value" '.[$parent][$child][$grandchild][$key] = $value' "$json_file" > "$temp_file"
mv "$temp_file" "$json_file"
fi
fi
done < "$cnf_file"
}
function do_reload_observer {
echo "Not support reload now"
}
function check_daemon_process {
if [ -f $prefix/run/daemon.pid ]; then
pid=$(cat $prefix/run/daemon.pid)
if kill -0 $pid >/dev/null 2>&1; then
echo "daemon process with PID $pid is running."
return 0
else
echo "daemon process with PID $pid is not running."
return 1
fi
else
echo "daemon PID file not found."
return 1
fi
}
function check_obagent_process {
if [ -f $prefix/run/obshell.pid ]; then
pid=$(cat $prefix/run/obshell.pid)
if kill -0 $pid >/dev/null 2>&1; then
echo "obshell process with PID $pid is running."
else
echo "obshell process with PID $pid is not running."
$obshell admin start --ip $ip --port $port
if [ $? -ne 0 ]; then
echo "start ob_agent failed"
exit
fi
fi
else
echo "obshell PID file not found."
exit
fi
}
function check_response {
local response=$1
successful=$(echo "$response" | jq -r '.successful')
if [ "x$successful" = "xfalse" ]; then
echo "send request failed"
exit 1
fi
}
function check_trace {
local dag_trace=$1
local content=$2
local max_retries=$3
local delay=$4
local count=0
echo "the $content trace id is $dag_trace"
while true; do
response=$(curl --silent -XGET $url/api/v1/task/dag/$dag_trace)
state=$(echo "$response" | jq -r '.data.state')
echo "the response state is $state"
if [ "x$state" = "xSUCCEED" ]; then
echo "request successfully"
break
elif [ "x$state" = "xFAILED" ]; then
echo "request failed"
exit 1
else
count=$((count + 1))
if [ $count -eq $max_retries ]; then
echo "maximum retries reached and then exit"
exit 1
fi
echo "wait ${delay}s and the retry"
sleep $delay
fi
done
}
function start_obshell {
$obshell admin start --ip $ip --port $port > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "start ob_agent failed"
exit
fi
}
function do_config_observer {
# join agent
obagent_configuration=`jq '.obshell' $json_file`
obagent_cmd="curl --silent -H \"Content-Type: application/json\" -X POST -d '${obagent_configuration}' --unix-socket $unix_socket $url/api/v1/agent/join"
response=$(eval "$obagent_cmd")
echo $response
successful=$(echo "$response" | jq -r '.successful')
if [ "x$successful" = "xfalse" ]; then
echo "send request failed"
exit 1
fi
trace=$(echo "$response" | jq -r '.data.id')
check_trace $trace "join agent" 3 3
# config cluster
cluster_configuration=`jq '.oceanbase_ce.cluster' $json_file`
cluster_cmd="curl --silent -H \"Content-Type: application/json\" -X PUT -d '${cluster_configuration}' --unix-socket $unix_socket $url/api/v1/obcluster/config"
response=$(eval "$cluster_cmd")
echo $response
successful=$(echo "$response" | jq -r '.successful')
if [ "x$successful" = "xfalse" ]; then
echo "send request failed"
exit 1
fi
trace=$(echo "$response" | jq -r '.data.id')
check_trace $trace "config cluster" 3 3
# config observer
observer_configuration=`jq '.oceanbase_ce.server' $json_file`
observer_cmd="curl --silent -H \"Content-Type: application/json\" -X PUT -d '${observer_configuration}' --unix-socket $unix_socket $url/api/v1/observer/config"
response=$(eval "$observer_cmd")
echo $response
successful=$(echo "$response" | jq -r '.successful')
if [ "x$successful" = "xfalse" ]; then
echo "send request failed"
exit 1
fi
trace=$(echo "$response" | jq -r '.data.id')
check_trace $trace "config observer" 3 3
}
function deploy_observer {
echo "oceanbase service deployed at ${DATE}"
prepare_config_json
start_obshell
do_config_observer
}
function start_observer {
prepare_config_json
systemd-notify --ready
# check observer status
response=$(curl --silent -H "Content-Type: application/json" -X GET --unix-socket $unix_socket $url/api/v1/status)
identity=$(echo "$response" | jq -r '.data.agent.identity')
echo $identity
systemd-notify "STATUS=Service is running"
if [ "x$identity" = "xCLUSTER AGENT" ]; then
echo "The observer is already bootstrap, please start it immediately"
response=$(curl --silent -H "Content-Type: application/json" -X POST -d '{
"scope":
{
"type":"global",
"target":[]
},
"force": true
}' --unix-socket $unix_socket $url/api/v1/ob/start)
successful=$(echo "$response" | jq -r '.successful')
if [ "x$successful" = "xfalse" ]; then
echo "send request failed"
exit 1
fi
trace=$(echo "$response" | jq -r '.data.id')
check_trace $trace "start observer" 20 6
elif [ "x$identity" = "xSINGLE" ]; then
# do config observer first
do_config_observer
echo "The observer has not bootstrap, please init it firstly"
response=$(curl --silent -X POST --unix-socket $unix_socket $url/api/v1/ob/init)
successful=$(echo "$response" | jq -r '.successful')
if [ "x$successful" = "xfalse" ]; then
echo "send request failed"
exit 1
fi
trace=$(echo "$response" | jq -r '.data.id')
check_trace $trace "start observer" 40 6
else
# status is UNIDENTIFIED
echo "The observer has been installed before"
fi
systemd-notify --status="Service is ready"
if [ -f $prefix/run/observer.pid ]; then
pid=$(cat $prefix/run/observer.pid)
while true; do
if [ ! -d "/proc/$pid" ]; then
echo "Observer process with PID $pid has exited."
break
fi
echo "Observer process with PID $pid is still running."
# check observer state
response=$(curl --silent -H "Content-Type: application/json" -X GET -d '{
"scope":
{
"type":"global",
"target":[]
},
"force": true
}' --unix-socket $unix_socket $url/api/v1/status)
ob_state=$(echo "$response" | jq -r '.data.obState')
if [ "x$ob_state" = "x1" ]; then
echo "The agent dose not know the observer password"
echo "1. Please set environment: export OB_ROOT_PASSWORD={root_passowrd}"
echo "2. Kill all the obshell process"
echo "3. Restart the agent process: $prefix/bin/obshell admin start --ip 127.0.0.1 --port 2886"
fi
sleep 30
done
else
echo "observer PID file not found."
exit 1
fi
}
function stop_observer {
check_obagent_process
response=$(curl --silent -H "Content-Type: application/json" -X POST -d '{
"scope":
{
"type":"global",
"target":[]
},
"force": true
}' --unix-socket $unix_socket $url/api/v1/ob/stop)
successful=$(echo "$response" | jq -r '.successful')
if [ "x$successful" = "xfalse" ]; then
echo "send request failed"
exit 1
fi
trace=$(echo "$response" | jq -r '.data.id')
check_trace $trace "stop observer" 20 6
systemd-notify --status='STOPPING=1'
}
function reload_observer {
check_obagent_process
prepare_config_json
do_reload_observer
}
if [ "x$1" = "xstart" ]; then
echo "oceanbase service started at ${DATE}"
if check_daemon_process; then
echo "The agent service is exist"
else
start_obshell
fi
start_observer
elif [ "x$1" = "xstop" ]; then
echo "oceanbase service stopped at ${DATE}"
stop_observer
elif [ "x$1" = "xreload" ]; then
echo "oceanbase service reloaded at ${DATE}"
reload_observer
elif [ "x$1" = "xdestroy" ]; then
# rpm uninstall logic, run systemctl stop oceanbase firstly
echo "oceanbase service destroyed at ${DATE}"
$obshell admin stop > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "stop obshell failed"
exit
fi
fi
exit 0

View File

@ -0,0 +1,9 @@
mysqlPort=2881
rootPwd=""
redoDir=/var/lib/oceanbase/redo
dataDir=/var/lib/oceanbase/data
datafile_size=2G
cpu_count=16
memory_limit=6G
system_memory=1G
log_disk_size=13G

View File

@ -0,0 +1,13 @@
[Unit]
Description=oceanbase
[Service]
User=root
Type=notify
KillMode=none
ExecStart=/bin/bash /home/admin/oceanbase/profile/oceanbase-service.sh start
ExecStop=/bin/bash /home/admin/oceanbase/profile/oceanbase-service.sh stop
ExecReload=/bin/bash /home/admin/oceanbase/profile/oceanbase-service.sh reload
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,14 @@
#!/bin/bash
echo "execute post install script"
prefix=@CPACK_PACKAGING_INSTALL_PREFIX@
# prepare the systemd service unit
cp -f $prefix/profile/oceanbase.service /etc/systemd/system/oceanbase.service
chmod 644 /etc/systemd/system/oceanbase.service
chmod +x $prefix/profile/oceanbase-service.sh
cp -f $prefix/profile/oceanbase.cnf /etc/oceanbase.cnf
systemctl daemon-reload
# deploy local observer
/bin/bash $prefix/profile/oceanbase-service.sh deploy

View File

@ -0,0 +1,6 @@
#!/bin/bash
echo "execute post uninstall script"
prefix=@CPACK_PACKAGING_INSTALL_PREFIX@
rm -rf $prefix/.meta $prefix/log_obshell

View File

@ -0,0 +1,11 @@
#!/bin/bash
echo "execute pre uninstall script"
prefix=@CPACK_PACKAGING_INSTALL_PREFIX@
echo remove oceanbase service
systemctl stop oceanbase
systemctl disable oceanbase
/bin/bash $prefix/profile/oceanbase-service.sh destroy
rm -f /etc/systemd/system/oceanbase.service /etc/oceanbase.cnf
systemctl daemon-reload