From ace5f006b19fa079f60b78ba976ee35c62abd2f4 Mon Sep 17 00:00:00 2001 From: LINxiansheng Date: Wed, 21 Feb 2024 02:15:46 +0000 Subject: [PATCH] [CP] add ip and port set in systemd --- deps/init/oceanbase.el7.aarch64.deps | 2 +- deps/init/oceanbase.el7.x86_64.deps | 2 +- deps/init/oceanbase.el8.aarch64.deps | 2 +- deps/init/oceanbase.el8.x86_64.deps | 2 +- tools/rpm/systemd/README-CN.md | 4 +++ tools/rpm/systemd/README.md | 4 +++ tools/rpm/systemd/profile/oceanbase-pre.json | 4 +-- .../profile/oceanbase-service.sh.template | 34 ++++++++++++------- tools/rpm/systemd/profile/oceanbase.cnf | 5 +++ .../systemd/profile/post_install.sh.template | 2 +- .../systemd/profile/pre_uninstall.sh.template | 2 +- 11 files changed, 42 insertions(+), 21 deletions(-) diff --git a/deps/init/oceanbase.el7.aarch64.deps b/deps/init/oceanbase.el7.aarch64.deps index 464205099f..aa80bc293c 100644 --- a/deps/init/oceanbase.el7.aarch64.deps +++ b/deps/init/oceanbase.el7.aarch64.deps @@ -43,7 +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-102024011512.el7.aarch64.rpm target=community +obshell-4.2.2.0-112024013121.el7.aarch64.rpm target=community [test-utils] ob-deploy-2.3.0-4.el7.aarch64.rpm target=community diff --git a/deps/init/oceanbase.el7.x86_64.deps b/deps/init/oceanbase.el7.x86_64.deps index 382b6afc8c..15bc907b96 100644 --- a/deps/init/oceanbase.el7.x86_64.deps +++ b/deps/init/oceanbase.el7.x86_64.deps @@ -46,7 +46,7 @@ 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-102024011512.el7.x86_64.rpm target=community +obshell-4.2.2.0-112024013121.el7.x86_64.rpm target=community [test-utils] ob-deploy-2.3.0-4.el7.x86_64.rpm target=community diff --git a/deps/init/oceanbase.el8.aarch64.deps b/deps/init/oceanbase.el8.aarch64.deps index 5060f7bc3d..3b5fb9594c 100644 --- a/deps/init/oceanbase.el8.aarch64.deps +++ b/deps/init/oceanbase.el8.aarch64.deps @@ -43,7 +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-102024011512.el8.aarch64.rpm target=community +obshell-4.2.2.0-112024013121.el8.aarch64.rpm target=community [test-utils] ob-deploy-2.3.0-4.el8.aarch64.rpm target=community diff --git a/deps/init/oceanbase.el8.x86_64.deps b/deps/init/oceanbase.el8.x86_64.deps index ca15973bb6..370910ff0a 100644 --- a/deps/init/oceanbase.el8.x86_64.deps +++ b/deps/init/oceanbase.el8.x86_64.deps @@ -45,7 +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-102024011512.el8.x86_64.rpm target=community +obshell-4.2.2.0-112024013121.el8.x86_64.rpm target=community [test-utils] ob-deploy-2.3.0-4.el8.x86_64.rpm target=community diff --git a/tools/rpm/systemd/README-CN.md b/tools/rpm/systemd/README-CN.md index de072ca4f8..2af52a9d96 100644 --- a/tools/rpm/systemd/README-CN.md +++ b/tools/rpm/systemd/README-CN.md @@ -12,6 +12,10 @@ yum install oceanbase-ce systemctl start oceanbase ``` +可以通过以下指令将oceanbase服务设置为开机自启动: +```bash +systemctl enable oceanbase +``` ## systemd介绍 Systemd提供了自动化管理oceanbase的启动和停止,可以通过systemctl指令对oceanbase进行管理控制,例如: diff --git a/tools/rpm/systemd/README.md b/tools/rpm/systemd/README.md index e679dd1e72..89bb3998d9 100644 --- a/tools/rpm/systemd/README.md +++ b/tools/rpm/systemd/README.md @@ -12,6 +12,10 @@ Now systemd only support RPM platform and you can install and run oceanbase serv yum install oceanbase-ce systemctl start oceanbase ``` +You can set the OceanBase service to start automatically on boot using the following command: +```bash +systemctl enable oceanbase +``` ## Overview of systemd Systemd provides automatic oceanbase startup and shutdown. It also enables manual server management using the systemctl command. For example: diff --git a/tools/rpm/systemd/profile/oceanbase-pre.json b/tools/rpm/systemd/profile/oceanbase-pre.json index 042219604b..9472bb5b0d 100644 --- a/tools/rpm/systemd/profile/oceanbase-pre.json +++ b/tools/rpm/systemd/profile/oceanbase-pre.json @@ -1,7 +1,7 @@ { "obshell": { "agentInfo": { - "ip": "127.0.0.1", + "ip": "HOSTIP", "port": 2886 }, "zoneName": "zone1" @@ -16,7 +16,7 @@ "scope": { "type": "server", "target": [ - "127.0.0.1:2886" + "HOSTIP:2886" ] }, "observerConfig": {} diff --git a/tools/rpm/systemd/profile/oceanbase-service.sh.template b/tools/rpm/systemd/profile/oceanbase-service.sh.template index da690239b0..c726e6d01a 100644 --- a/tools/rpm/systemd/profile/oceanbase-service.sh.template +++ b/tools/rpm/systemd/profile/oceanbase-service.sh.template @@ -1,16 +1,16 @@ #!/bin/bash DATE=`date '+%Y-%m-%d %H:%M:%S'` -ip='127.0.0.1' +cnf_file='/etc/oceanbase.cnf' +ip=`hostname -i` port=2886 -url="http://$ip:$port" -unix_socket="/tmp/obshell/$port.sock" +url="http://localhost" prefix=@CPACK_PACKAGING_INSTALL_PREFIX@ +unix_socket="$prefix/run/obshell.sock" obshell="$prefix/bin/obshell" report=3 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 @@ -18,11 +18,19 @@ function prepare_config_json { local temp_file=$(mktemp) while IFS='=' read -r key value; do + # delete empty and comment line + if [[ ! $key || $key =~ ^[[:space:]]*# ]]; then + continue + fi 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 + if [[ $key == *"ip"* ]]; then + ip=$value + elif [[ $key == *"obshellPort"* ]]; then + port=$value + elif [[ $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 @@ -31,6 +39,8 @@ function prepare_config_json { fi fi done < "$cnf_file" + sed -i "s|2886|${port}|g" $json_file + sed -i "s|HOSTIP|${ip}|g" $json_file } function do_reload_observer { @@ -89,7 +99,7 @@ function check_trace { 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) + response=$(curl --silent -XGET --unix-socket $unix_socket $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 @@ -167,12 +177,10 @@ function deploy_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" @@ -192,7 +200,7 @@ function start_observer { trace=$(echo "$response" | jq -r '.data.id') check_trace $trace "start observer" 20 6 if [ $? -eq 0 ]; then - /bin/bash $prefix/profile/telemetry.sh $report "12" + /bin/bash $prefix/profile/telemetry.sh $report "12" >/dev/null 2>&1 fi elif [ "x$identity" = "xSINGLE" ]; then # do config observer first @@ -207,7 +215,7 @@ function start_observer { trace=$(echo "$response" | jq -r '.data.id') check_trace $trace "start observer" 40 6 if [ $? -eq 0 ]; then - /bin/bash $prefix/profile/telemetry.sh $report "11" + /bin/bash $prefix/profile/telemetry.sh $report "11" >/dev/null 2>&1 fi else # status is UNIDENTIFIED @@ -239,7 +247,7 @@ function start_observer { 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" + echo "3. Restart the agent process: $prefix/bin/obshell admin start --ip $ip --port $port" fi sleep 30 done @@ -277,8 +285,8 @@ function reload_observer { if [ "x$1" = "xstart" ]; then echo "oceanbase service started at ${DATE}" - # telemetry - /bin/bash $prefix/profile/telemetry.sh $report "10" + /bin/bash $prefix/profile/telemetry.sh $report "10" >/dev/null 2>&1 + prepare_config_json if check_daemon_process; then echo "The agent service is exist" else diff --git a/tools/rpm/systemd/profile/oceanbase.cnf b/tools/rpm/systemd/profile/oceanbase.cnf index 372c494999..f5dd0221c7 100644 --- a/tools/rpm/systemd/profile/oceanbase.cnf +++ b/tools/rpm/systemd/profile/oceanbase.cnf @@ -1,5 +1,10 @@ +# The ip only can be set when first start up. +# If you want to change ip you have to uninstall oceanbase and delete the data folder. +# And then install and start the oceanbase with the new ip +ip=127.0.0.1 mysqlPort=2881 rpcPort=2882 +obshellPort=2886 rootPwd="" redoDir=/var/lib/oceanbase/redo dataDir=/var/lib/oceanbase/data diff --git a/tools/rpm/systemd/profile/post_install.sh.template b/tools/rpm/systemd/profile/post_install.sh.template index 2661a1a6d3..94df4dcd2b 100644 --- a/tools/rpm/systemd/profile/post_install.sh.template +++ b/tools/rpm/systemd/profile/post_install.sh.template @@ -11,4 +11,4 @@ cp -f $prefix/profile/oceanbase.cnf /etc/oceanbase.cnf systemctl daemon-reload # telemetry -/bin/bash $prefix/profile/telemetry.sh $1 \ No newline at end of file +/bin/bash $prefix/profile/telemetry.sh $1 >/dev/null 2>&1 \ No newline at end of file diff --git a/tools/rpm/systemd/profile/pre_uninstall.sh.template b/tools/rpm/systemd/profile/pre_uninstall.sh.template index 0a56121bb9..23c699de51 100644 --- a/tools/rpm/systemd/profile/pre_uninstall.sh.template +++ b/tools/rpm/systemd/profile/pre_uninstall.sh.template @@ -11,4 +11,4 @@ rm -f /etc/systemd/system/oceanbase.service /etc/oceanbase.cnf systemctl daemon-reload # telemetry -/bin/bash $prefix/profile/telemetry.sh $1 \ No newline at end of file +/bin/bash $prefix/profile/telemetry.sh $1 >/dev/null 2>&1 \ No newline at end of file