首批通过分布式安全可靠测评,为关键业务系统打造
设置 OBServer 节点开机自启动
更新时间:2025-01-20 15:07:33
本文根据 OBServer 节点是否可以连接公网环境,分为 在线设置 和 离线设置 两种方法介绍如何设置 OBServer 节点开机自启动。
说明
设置 OBServer 节点开机自启动时,OceanBase 集群的每一个 OBServer 节点都需参考本文内容进行设置。
适用场景
该文档中介绍的设置方法仅适用于满足如下条件的场景:
当前 OceanBase 集群已部署完成,并且该集群不被 obshell 运维管理。
当前 OceanBase 数据库为 V4.2.1.4 或之后版本。
在线设置
当节点可以连接公网时,您可登录 OBServer 节点后直接执行如下命令设置 OBServer 节点开机自启动。
[admin@test001 ~]$ sudo bash -c "$(curl -s https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/obshell/service_installer.sh)"
离线设置
当节点无法连接公网时,您可登录 OBServer 节点后参照如下步骤设置 OBServer 节点开机自启动。
参考如下内容创建脚本文件
此处以脚本文件名为
self_start.sh为例,您可自定义脚本文件名。[admin@test001 ~]$ vim self_start.sh脚本内容如下:
#!/bin/bash # Prompt the user for input and retrieve it prompt_for_input() { local prompt_message="$1" local user_input read -p "$prompt_message" user_input echo "$user_input" } # Check if the homepath argument was provided via the command line expected_arg_name="homepath" if [ $# -gt 0 ]; then arg_value="$1" else # No arguments provided, ask the user for the homepath arg_value=$(prompt_for_input "Please enter the $expected_arg_name: ") fi echo "Using $expected_arg_name: $arg_value" # Check for the existence of the 'obshell' file in the provided homepath homepath=$arg_value obshell="$homepath/bin/obshell" if [ ! -f "$obshell" ]; then echo -e "\033[31m[ERROR]\033[0m Sorry, [$obshell] does not exist." echo "You may need to upgrade the obcluster. Please consult the developers for assistance." exit 1 else echo "[$obshell] has been found in the work directory." fi # Check if the oceanbase.service file exists system_dir="/etc/systemd/system" oceanbase=$system_dir/oceanbase.service # Check if the service file exists if [ -f "$oceanbase" ]; then echo -e "\033[33m[WARN]\033[0m oceanbase.service has been installed." echo "Please use 'systemctl status oceanbase.service' to check it." exit 0 else echo "Service file $oceanbase does not exist." fi # Retrieve the owner of the 'observer' process configuration files owner=$(stat -c '%U' $homepath/etc) echo "Owner of the observer configuration: $owner" # Construct and output the content for the systemd service unit file name=observer.service mkdir -p $homepath/tmp file=$homepath/tmp/$name start_cmd="${homepath}/bin/obshell cluster start" V4231="4.2.3.1" version=`${homepath}/bin/obshell version` if printf '%s\n' "$V4231" "$version" | sort -CV; then start_cmd="${homepath}/bin/obshell admin start --takeover 0 --ob" fi echo "Creating the service unit file at $file..." # Write the service content to the file cat << EOF > ${file} [Unit] Description=observer After=network.target [Service] User=${owner} Type=forking KillSignal=SIGKILL ExecStartPre=${homepath}/bin/obshell admin stop ExecStart=${start_cmd} ExecStartPost=${homepath}/bin/obshell admin stop ExecStop=${homepath}/bin/obshell admin stop PIDFile=${homepath}/run/observer.pid Restart=no SuccessExitStatus=SIGKILL [Install] WantedBy=multi-user.target EOF echo "The content of the Service unit file is:" sed 's/^/ /' "$file" # Deploy the unit configuration file to the system directory echo "Deploying the service unit file to the system directory" cp -f $file $system_dir/$name echo "Updating permissions for the service unit file..." chmod 644 $system_dir/$name echo "Reloading the systemd daemon to recognize the new service" systemctl daemon-reload systemctl enable observer.service echo -e "\033[32m[SUCCEED]\033[0m observer.service has been installed."执行如下命令启动脚本
此处以 OceanBase 集群的安装目录为
/home/admin/oceanbase为例,您需根据实际情况进行替换。[admin@test001 ~]$ sudo sh self_start.sh /home/admin/oceanbase