KingbaseES 配置root.sh实现数据库服务开机自启动
案例说明:
KingbaseES数据库在部署完成后,支持数据库服务开机自启动,部署完成后,root用户(Linux)执行安装软件目录下的root.sh脚本后,可以实现数据库服务开机自启动。
适用版本:
KingbaseES V8R3/R6
操作系统:
Linux
一、脚本存储目录
[kingbase@node102 script]$ pwd
/opt/Kingbase/ES/V8R6_C7/install/script
[kingbase@node102 script]$ ls -lh
total 52K
-rwxr-xr-x 1 kingbase kingbase 321 Oct 29 14:47 consoleCloud-uninstall.sh
-rwxr-x--- 1 kingbase kingbase 2.2K Oct 29 14:47 initcluster.sh
-rwxr-x--- 1 kingbase kingbase 289 Oct 29 14:47 javatools.sh
-rwxr-x--- 1 kingbase kingbase 21K Oct 29 14:47 mkln.sh
-rwxr-xr-x 1 kingbase kingbase 542 Oct 29 14:47 rootDeployClusterware.sh
-rwxr-x--- 1 kingbase kingbase 712 Mar 3 15:11 root.sh
-rwxr-x--- 1 kingbase kingbase 690 Oct 29 14:47 rootuninstall.sh
-rwxrwxrwx 1 kingbase kingbase 3.7K Oct 29 14:47 startupcfg.sh
二、编辑脚本
Tips:
脚本在安装完数据库软件后,默认不需要修改其配置,可以由root用户直接执行;但是在做了静默安装或者后期运行一段时间后,需要再部署数据库服务自启动,可以通过修改脚本(通用机环境)后执行root.sh。如下所示,可以修改相应的脚本参数。
[kingbase@node102 script]$ cat root.sh
#!/bin/bash
ROOT_UID=0
#INSTALLDIR=@@INSTALL_DIR@@ #数据库软件安装路径
INSTALLDIR='/opt/Kingbase/ES/V8R6_C7'
#USERNAME=@@USER_NAME@@ #数据库部署用户
USERNAME=kingbase
#DATADIR=@@DATA_DIR@@ #数据库data目录存储路径
DATADIR='/data/kingbase/v8r6_c7/data'
VERSION=V8
SERVICENAME=kingbase8d
# Run as root, of course.
if [ x"$UID" != x"$ROOT_UID" ]
then
echo "Must be root to run this script, and root.sh should be executed in the '$0' way, not 'sh $0'."
exit 1
fi
if [ -d $INSTALLDIR/Scripts ]; then
$INSTALLDIR/Scripts/startupcfg.sh $VERSION $USERNAME $INSTALLDIR $DATADIR $SERVICENAME
elif [ -d $INSTALLDIR/install/script ]; then
$INSTALLDIR/install/script/startupcfg.sh $VERSION $USERNAME $INSTALLDIR $DATADIR $SERVICENAME
else
"can not find startupcfg.sh"
fi
三、执行脚本
[root@node102 script]# sh root.sh
Starting KingbaseES V8:
waiting for server to start.... done
server started
KingbaseES V8 started successfully
四、数据库自启动服务管理
1、服务启动脚本
#在系统/etc/init.d下生成kingbase8d的启动脚本
[root@node102 ~]# cd /etc/init.d/
[root@node102 init.d]# ls -lh
total 56K
-rw-r--r-- 1 root root 18K May 22 2020 functions
-rwxr-xr-x 1 root root 3.2K Mar 7 10:57 kingbase8d
-rwxr-xr-x 1 root root 11K Jan 6 16:18 mysqld
-rwxr-xr-x 1 root root 4.5K May 22 2020 netconsole
-rwxr-xr-x 1 root root 7.8K May 22 2020 network
-rw-r--r-- 1 root root 1.2K Jan 14 2022 README
如下图所示脚本内容(禁止修改):
2、查看服务状态
[root@node102 init.d]# service kingbase8d status
sys_ctl: server is running (PID: 1435)
/opt/Kingbase/ES/V8R6_C7/KESRealPro/V008R006C007B0012/Server/bin/kingbase "-D" "/data/kingbase/v8r6_c7/data"
[root@node102 init.d]# systemctl status kingbase8d
● kingbase8d.service - LSB: Start and stop the kingbase server
Loaded: loaded (/etc/rc.d/init.d/kingbase8d; bad; vendor preset: disabled)
Active: active (exited) since Mon 2023-03-06 09:46:21 CST; 33min ago
.....
[root@node102 init.d]# chkconfig --list kingbase8d
......
kingbase8d 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3、修改数据库服务自启动配置
#在系统多用户和图形化多用户级别,禁止kingbase8d系统自启动
[root@node102 init.d]# chkconfig --level 3 kingbase8d off
[root@node102 init.d]# chkconfig --level 5 kingbase8d off
[root@node102 init.d]# chkconfig --list kingbase8d
kingbase8d 0:off 1:off 2:on 3:off 4:on 5:off 6:off
4、启动和停止数据库服务
#启动数据库服务
[root@node102 init.d]# service kingbase8d start
Starting KingbaseES V8:
waiting for server to start.... done
server started
KingbaseES V8 started successfully
#停止数据库服务
[root@node102 init.d]# service kingbase8d stop
Stopping KingbaseES V8:
waiting for server to shut down....... done
server stopped
KINGBASE研究院