[CP] add ip and port set in systemd
This commit is contained in:
@ -12,6 +12,10 @@
|
||||
yum install oceanbase-ce
|
||||
systemctl start oceanbase
|
||||
```
|
||||
可以通过以下指令将oceanbase服务设置为开机自启动:
|
||||
```bash
|
||||
systemctl enable oceanbase
|
||||
```
|
||||
|
||||
## systemd介绍
|
||||
Systemd提供了自动化管理oceanbase的启动和停止,可以通过systemctl指令对oceanbase进行管理控制,例如:
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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": {}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -11,4 +11,4 @@ cp -f $prefix/profile/oceanbase.cnf /etc/oceanbase.cnf
|
||||
systemctl daemon-reload
|
||||
|
||||
# telemetry
|
||||
/bin/bash $prefix/profile/telemetry.sh $1
|
||||
/bin/bash $prefix/profile/telemetry.sh $1 >/dev/null 2>&1
|
||||
@ -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
|
||||
/bin/bash $prefix/profile/telemetry.sh $1 >/dev/null 2>&1
|
||||
Reference in New Issue
Block a user