GBase 8a的V95版本,不再依赖操作系统root用户运行,增强了系统的安全性,但同时一些功能也缺失了,比如开机自启动。本文提供几种用户需要达到开机自启动的几个方法。
所有方法,都需要直接或间接的依赖操作系统root用户权限。
目录导航
/etc/rc.local
该方案最简单,将启动数据库服务的命令放到这里,实现开机自启动。
su - gbase -c 'gcluster_services all start'
如下是手工运行该命令的效果
[root@gbase_rh7_001 ~]# su - gbase -c'gcluster_services all start'
Starting gcware : [ OK ]
Starting gcluster : [ OK ]
Starting gcrecover : [ OK ]
Starting gbase : [ OK ]
Starting syncserver : [ OK ]
Starting GCMonit success!
[root@gbase_rh7_001 ~]# ps -ef|grep gbase
avahi 601 1 0 09:57 ? 00:00:00 avahi-daemon: running [gbaserh7001.local]
gbase 3020 1 3 10:00 ? 00:00:00 /opt/gbase/gcware/sbin/gcware
gbase 3025 1 24 10:00 ? 00:00:01 /opt/gbase/gcluster/server/bin/gclusterd
gbase 3048 1 11 10:00 ? 00:00:00 /opt/gbase/gcluster/server/bin/gcrecover
gbase 3071 1 22 10:00 ? 00:00:01 /opt/gbase/gnode/server/bin/gbased
gbase 3614 1 0 10:00 ? 00:00:00 /opt/gbase/gnode/server/bin/gc_sync_server
gbase 3623 1 1 10:00 ? 00:00:00 /opt/gbase/gcluster/server/bin/gcmonit --start
gbase 3625 1 0 10:00 ? 00:00:00 /opt/gbase/gcluster/server/bin/gcmmonit --start
root 3640 2911 0 10:00 pts/0 00:00:00 grep --color=auto gbase
[root@gbase_rh7_001 ~]#
/etc/init.d 启动服务
完全参考GBase V8的版本实现V9的服务启动
一、编写服务文件,并放到/etc/init.d目录下
注意文件加上可执行权限,比如chmod a+x GBaseBoot
[root@localhost system]# cat /etc/init.d/GBaseBoot
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: GBase
# Required-Start: $network
# Should-Start: $syslog
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: GBase 8a Cluster MPP.
# Description: Provide MPP Database service
### END INIT INFO
#
function is_OK()
{
if [ $RETVAL -eq 0 ] ;then
echo "OK"
else
echo "FAIL"
fi
}
RETVAL=0
# See how we were called.
case "$1" in
start)
date >> /var/log/GBaseBoot.log
echo -n "Starting gbase: "
su - gbase -c"gcluster_services all start" >> /var/log/GBaseBoot.log
RETVAL=$?
echo `is_OK`
;;
stop)
date >> /var/log/GBaseBoot.log
echo -n "Stopping gbase: "
su - gbase -c"gcluster_services all stop" >> /var/log/GBaseBoot.log
RETVAL=$?
echo `is_OK`
;;
restart)
date >> /var/log/GBaseBoot.log
echo -n "Restarting gbase: "
su - gbase -c"gcluster_services all restart" >> /var/log/GBaseBoot.log
RETVAL=$?
echo `is_OK`
;;
status)
su - gbase -c"gcluster_services all info"
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $RETVAL
通过如下命令,看服务是否正常
[root@gbase_rh7_001 init.d]# service GBaseBoot status
gcware is stopped
gcluster is stopped
gcrecover is stopped
gbase is stopped
syncserver is stopped
2、加入自启动
chkconfig --add GBaseBoot
检查
[root@localhost system]# chkconfig --list| grep GBaseBoot
GBaseBoot 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3、重启测试
┌────────────────────────────────────────────────────────────────────┐
│ • MobaXterm 10.4 • │
│ (SSH client, X-server and networking tools) │
│ │
│ ➤ SSH session to root@192.168.56.1 │
│ • SSH compression : ✔ │
│ • SSH-browser : ✔ │
│ • X11-forwarding : ✔ (remote display is forwarded through SSH) │
│ • DISPLAY : ✔ (automatically set on remote server) │
│ │
│ ➤ For more info, ctrl+click on help or visit our website │
└────────────────────────────────────────────────────────────────────┘
Last login: Mon Dec 6 10:10:11 2021 from 192.168.56.1
[root@gbase_rh7_001 ~]# ps -ef|grep gbase
avahi 557 1 0 10:19 ? 00:00:00 avahi-daemon: running [gbaserh7001.local]
gbase 1539 1 0 10:19 ? 00:00:00 /opt/gbase/gcware/sbin/gcware
gbase 2143 1 17 10:19 ? 00:00:22 /opt/gbase/gcluster/server/bin/gclusterd
gbase 2249 1 18 10:19 ? 00:00:23 /opt/gbase/gcluster/server/bin/gcrecover
gbase 2374 1 0 10:19 ? 00:00:00 /opt/gbase/gnode/server/bin/gbased
gbase 2417 1 0 10:19 ? 00:00:00 /opt/gbase/gnode/server/bin/gc_sync_server
gbase 3061 1 0 10:19 ? 00:00:01 /opt/gbase/gcluster/server/bin/gcmonit --start
gbase 3065 1 0 10:19 ? 00:00:00 /opt/gbase/gcluster/server/bin/gcmmonit --start
root 3508 3466 0 10:21 pts/0 00:00:00 grep --color=auto gbase
[root@gbase_rh7_001 ~]#
monit等看门狗服务
前面的几个方案,如果出现启动失败,不会自动重试,特别是网络挂载数据盘的情况,全部物理级本地硬件的没这个问题。
此时部署一个看门狗就有必要了。监控核心进程,如果超过限制,则尝试拉起。当然,如果停服务,要记得停下monit,否则也会被其拉起,着也算个【注意事项】
/etc/monit.d/monit_gbase.conf
里面检测的是gcmmonit进程, 该进程是数据库内置的看门狗程序,其如果发现其它进程消失,或自动拉起的,所以外面的进程,只需要检测这个就可以了。
拉起服务的部分是全部,没有单独拉起gcmmonit.
检测和拉起周期,请自行修改,建议不要拉起太久时间,除非用户希望这样。
该文件格式,参考的GBase V8的样例。
###############################################################################
## gcluster Services
###############################################################################
check process gcmmonit with pidfile /tmp/fake.pid
start program = "/bin/su - gbase -c 'gcluster_services all start'"
if does not exist then start
# cycles means how many intervals which is set in monitrc(set daemon 5)
if 1000 restarts within 60000 cycles then timeout
group gcluster
该功能由monit提供,所以需要确保monit是开机自启动状态即可。
运行样例
[root@gbase_rh7_001 monit.d]# su - gbase -c"gcluster_services all info"
gcware is stopped
gcluster is stopped
gcrecover is stopped
gbase is stopped
syncserver is stopped
[root@gbase_rh7_001 monit.d]#
[root@gbase_rh7_001 monit.d]# service monit status
monit is stopped
[root@gbase_rh7_001 monit.d]# ps -ef|grep gbase
avahi 557 1 0 10:19 ? 00:00:00 avahi-daemon: running [gbaserh7001.local]
root 5805 3466 0 10:45 pts/0 00:00:00 grep --color=auto gbase
[root@gbase_rh7_001 monit.d]# service monit start
Starting monit: Starting monit daemon with http interface at [localhost:2812]
[root@gbase_rh7_001 monit.d]# ps -ef|grep gbase
avahi 557 1 0 10:19 ? 00:00:00 avahi-daemon: running [gbaserh7001.local]
root 5832 1 0 10:45 ? 00:00:00 /bin/su - gbase -c gcluster_services all start
gbase 5833 5832 0 10:45 ? 00:00:00 /bin/bash /opt/gbase/gcluster/server/bin/gcluster_services all start
gbase 5853 1 6 10:45 ? 00:00:00 /opt/gbase/gcware/sbin/gcware
gbase 5858 5833 34 10:45 ? 00:00:00 /opt/gbase/gcluster/server/bin/gclusterd
gbase 5882 5833 11 10:45 ? 00:00:00 /opt/gbase/gcluster/server/bin/gcrecover
gbase 5904 5833 0 10:45 ? 00:00:00 /opt/gbase/gnode/server/bin/gbased
gbase 5905 5833 0 10:45 ? 00:00:00 sleep 1
root 6443 3466 0 10:45 pts/0 00:00:00 grep --color=auto gbase
[root@gbase_rh7_001 monit.d]# ps -ef|grep gbase
avahi 557 1 0 10:19 ? 00:00:00 avahi-daemon: running [gbaserh7001.local]
gbase 5853 1 1 10:45 ? 00:00:00 /opt/gbase/gcware/sbin/gcware
gbase 5858 1 16 10:45 ? 00:00:02 /opt/gbase/gcluster/server/bin/gclusterd
gbase 5882 1 16 10:45 ? 00:00:02 /opt/gbase/gcluster/server/bin/gcrecover
gbase 5904 1 5 10:45 ? 00:00:00 /opt/gbase/gnode/server/bin/gbased
gbase 6449 1 0 10:45 ? 00:00:00 /opt/gbase/gnode/server/bin/gc_sync_server
gbase 6454 1 0 10:45 ? 00:00:00 /opt/gbase/gcluster/server/bin/gcmonit --start
gbase 6456 1 0 10:45 ? 00:00:00 /opt/gbase/gcluster/server/bin/gcmmonit --start
root 6473 3466 0 10:46 pts/0 00:00:00 grep --color=auto gbase
[root@gbase_rh7_001 monit.d]# ps -ef|grep gbase
avahi 557 1 0 10:19 ? 00:00:00 avahi-daemon: running [gbaserh7001.local]
gbase 5853 1 0 10:45 ? 00:00:00 /opt/gbase/gcware/sbin/gcware
gbase 5858 1 14 10:45 ? 00:00:03 /opt/gbase/gcluster/server/bin/gclusterd
gbase 5882 1 14 10:45 ? 00:00:02 /opt/gbase/gcluster/server/bin/gcrecover
gbase 5904 1 4 10:45 ? 00:00:00 /opt/gbase/gnode/server/bin/gbased
gbase 6449 1 0 10:45 ? 00:00:00 /opt/gbase/gnode/server/bin/gc_sync_server
gbase 6454 1 1 10:45 ? 00:00:00 /opt/gbase/gcluster/server/bin/gcmonit --start
gbase 6456 1 0 10:45 ? 00:00:00 /opt/gbase/gcluster/server/bin/gcmmonit --start
root 6483 3466 0 10:46 pts/0 00:00:00 grep --color=auto gbase
[root@gbase_rh7_001 monit.d]#
第三方看门狗
应用开发商的业务系统,一般都有自己的看门狗程序,可以部署到数据库上,实现的数据库服务的开启启动和服务进程监控。