本記事では、OBServerノードがインターネット環境に接続できるかどうかに基づいて、オンライン設定とオフライン設定の2種類の方法で、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