[CP] add ip and port set in systemd

This commit is contained in:
LINxiansheng
2024-02-21 02:15:46 +00:00
committed by ob-robot
parent a9d18eadb8
commit ace5f006b1
11 changed files with 42 additions and 21 deletions

View File

@ -43,7 +43,7 @@ obdevtools-llvm-11.0.1-312022092921.el7.aarch64.rpm
[tools-deps] [tools-deps]
devdeps-oblogmsg-1.0-52022113019.el7.aarch64.rpm devdeps-oblogmsg-1.0-52022113019.el7.aarch64.rpm
devdeps-rocksdb-6.22.1.1-52022100420.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] [test-utils]
ob-deploy-2.3.0-4.el7.aarch64.rpm target=community ob-deploy-2.3.0-4.el7.aarch64.rpm target=community

View File

@ -46,7 +46,7 @@ obdevtools-llvm-11.0.1-312022092921.el7.x86_64.rpm
[tools-deps] [tools-deps]
devdeps-oblogmsg-1.0-52022113019.el7.x86_64.rpm devdeps-oblogmsg-1.0-52022113019.el7.x86_64.rpm
devdeps-rocksdb-6.22.1.1-52022100420.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] [test-utils]
ob-deploy-2.3.0-4.el7.x86_64.rpm target=community ob-deploy-2.3.0-4.el7.x86_64.rpm target=community

View File

@ -43,7 +43,7 @@ obdevtools-llvm-11.0.1-312022092921.el8.aarch64.rpm
[tools-deps] [tools-deps]
devdeps-oblogmsg-1.0-52022113019.el8.aarch64.rpm devdeps-oblogmsg-1.0-52022113019.el8.aarch64.rpm
devdeps-rocksdb-6.22.1.1-52022100420.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] [test-utils]
ob-deploy-2.3.0-4.el8.aarch64.rpm target=community ob-deploy-2.3.0-4.el8.aarch64.rpm target=community

View File

@ -45,7 +45,7 @@ obdevtools-llvm-11.0.1-312022092921.el8.x86_64.rpm
[tools-deps] [tools-deps]
devdeps-oblogmsg-1.0-52022113019.el8.x86_64.rpm devdeps-oblogmsg-1.0-52022113019.el8.x86_64.rpm
devdeps-rocksdb-6.22.1.1-52022100420.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] [test-utils]
ob-deploy-2.3.0-4.el8.x86_64.rpm target=community ob-deploy-2.3.0-4.el8.x86_64.rpm target=community

View File

@ -12,6 +12,10 @@
yum install oceanbase-ce yum install oceanbase-ce
systemctl start oceanbase systemctl start oceanbase
``` ```
可以通过以下指令将oceanbase服务设置为开机自启动:
```bash
systemctl enable oceanbase
```
## systemd介绍 ## systemd介绍
Systemd提供了自动化管理oceanbase的启动和停止,可以通过systemctl指令对oceanbase进行管理控制,例如: Systemd提供了自动化管理oceanbase的启动和停止,可以通过systemctl指令对oceanbase进行管理控制,例如:

View File

@ -12,6 +12,10 @@ Now systemd only support RPM platform and you can install and run oceanbase serv
yum install oceanbase-ce yum install oceanbase-ce
systemctl start oceanbase 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 ## Overview of systemd
Systemd provides automatic oceanbase startup and shutdown. It also enables manual server management using the systemctl command. For example: Systemd provides automatic oceanbase startup and shutdown. It also enables manual server management using the systemctl command. For example:

View File

@ -1,7 +1,7 @@
{ {
"obshell": { "obshell": {
"agentInfo": { "agentInfo": {
"ip": "127.0.0.1", "ip": "HOSTIP",
"port": 2886 "port": 2886
}, },
"zoneName": "zone1" "zoneName": "zone1"
@ -16,7 +16,7 @@
"scope": { "scope": {
"type": "server", "type": "server",
"target": [ "target": [
"127.0.0.1:2886" "HOSTIP:2886"
] ]
}, },
"observerConfig": {} "observerConfig": {}

View File

@ -1,16 +1,16 @@
#!/bin/bash #!/bin/bash
DATE=`date '+%Y-%m-%d %H:%M:%S'` DATE=`date '+%Y-%m-%d %H:%M:%S'`
ip='127.0.0.1' cnf_file='/etc/oceanbase.cnf'
ip=`hostname -i`
port=2886 port=2886
url="http://$ip:$port" url="http://localhost"
unix_socket="/tmp/obshell/$port.sock"
prefix=@CPACK_PACKAGING_INSTALL_PREFIX@ prefix=@CPACK_PACKAGING_INSTALL_PREFIX@
unix_socket="$prefix/run/obshell.sock"
obshell="$prefix/bin/obshell" obshell="$prefix/bin/obshell"
report=3 report=3
function prepare_config_json { function prepare_config_json {
cnf_file='/etc/oceanbase.cnf'
json_pre_file="$prefix/profile/oceanbase-pre.json" json_pre_file="$prefix/profile/oceanbase-pre.json"
json_file="$prefix/profile/oceanbase.json" json_file="$prefix/profile/oceanbase.json"
rm -rf $json_file rm -rf $json_file
@ -18,11 +18,19 @@ function prepare_config_json {
local temp_file=$(mktemp) local temp_file=$(mktemp)
while IFS='=' read -r key value; do 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') key=$(echo "$key" | awk '{$1=$1};1')
value=$(echo "$value" | awk '{$1=$1};1') value=$(echo "$value" | awk '{$1=$1};1')
value=$(echo "$value" | sed 's/^"//' | sed 's/"$//') value=$(echo "$value" | sed 's/^"//' | sed 's/"$//')
if [[ -n "$key" && ! "$key" =~ ^\; ]]; then 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" 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" mv "$temp_file" "$json_file"
else else
@ -31,6 +39,8 @@ function prepare_config_json {
fi fi
fi fi
done < "$cnf_file" done < "$cnf_file"
sed -i "s|2886|${port}|g" $json_file
sed -i "s|HOSTIP|${ip}|g" $json_file
} }
function do_reload_observer { function do_reload_observer {
@ -89,7 +99,7 @@ function check_trace {
local count=0 local count=0
echo "the $content trace id is $dag_trace" echo "the $content trace id is $dag_trace"
while true; do 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') state=$(echo "$response" | jq -r '.data.state')
echo "the response state is $state" echo "the response state is $state"
if [ "x$state" = "xSUCCEED" ]; then if [ "x$state" = "xSUCCEED" ]; then
@ -167,12 +177,10 @@ function deploy_observer {
} }
function start_observer { function start_observer {
prepare_config_json
systemd-notify --ready systemd-notify --ready
# check observer status # check observer status
response=$(curl --silent -H "Content-Type: application/json" -X GET --unix-socket $unix_socket $url/api/v1/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') identity=$(echo "$response" | jq -r '.data.agent.identity')
echo $identity
systemd-notify "STATUS=Service is running" systemd-notify "STATUS=Service is running"
if [ "x$identity" = "xCLUSTER AGENT" ]; then if [ "x$identity" = "xCLUSTER AGENT" ]; then
echo "The observer is already bootstrap, please start it immediately" echo "The observer is already bootstrap, please start it immediately"
@ -192,7 +200,7 @@ function start_observer {
trace=$(echo "$response" | jq -r '.data.id') trace=$(echo "$response" | jq -r '.data.id')
check_trace $trace "start observer" 20 6 check_trace $trace "start observer" 20 6
if [ $? -eq 0 ]; then 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 fi
elif [ "x$identity" = "xSINGLE" ]; then elif [ "x$identity" = "xSINGLE" ]; then
# do config observer first # do config observer first
@ -207,7 +215,7 @@ function start_observer {
trace=$(echo "$response" | jq -r '.data.id') trace=$(echo "$response" | jq -r '.data.id')
check_trace $trace "start observer" 40 6 check_trace $trace "start observer" 40 6
if [ $? -eq 0 ]; then 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 fi
else else
# status is UNIDENTIFIED # status is UNIDENTIFIED
@ -239,7 +247,7 @@ function start_observer {
echo "The agent dose not know the observer password" echo "The agent dose not know the observer password"
echo "1. Please set environment: export OB_ROOT_PASSWORD={root_passowrd}" echo "1. Please set environment: export OB_ROOT_PASSWORD={root_passowrd}"
echo "2. Kill all the obshell process" 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 fi
sleep 30 sleep 30
done done
@ -277,8 +285,8 @@ function reload_observer {
if [ "x$1" = "xstart" ]; then if [ "x$1" = "xstart" ]; then
echo "oceanbase service started at ${DATE}" echo "oceanbase service started at ${DATE}"
# telemetry /bin/bash $prefix/profile/telemetry.sh $report "10" >/dev/null 2>&1
/bin/bash $prefix/profile/telemetry.sh $report "10" prepare_config_json
if check_daemon_process; then if check_daemon_process; then
echo "The agent service is exist" echo "The agent service is exist"
else else

View File

@ -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 mysqlPort=2881
rpcPort=2882 rpcPort=2882
obshellPort=2886
rootPwd="" rootPwd=""
redoDir=/var/lib/oceanbase/redo redoDir=/var/lib/oceanbase/redo
dataDir=/var/lib/oceanbase/data dataDir=/var/lib/oceanbase/data

View File

@ -11,4 +11,4 @@ cp -f $prefix/profile/oceanbase.cnf /etc/oceanbase.cnf
systemctl daemon-reload systemctl daemon-reload
# telemetry # telemetry
/bin/bash $prefix/profile/telemetry.sh $1 /bin/bash $prefix/profile/telemetry.sh $1 >/dev/null 2>&1

View File

@ -11,4 +11,4 @@ rm -f /etc/systemd/system/oceanbase.service /etc/oceanbase.cnf
systemctl daemon-reload systemctl daemon-reload
# telemetry # telemetry
/bin/bash $prefix/profile/telemetry.sh $1 /bin/bash $prefix/profile/telemetry.sh $1 >/dev/null 2>&1