1. 基本步骤
- 进入 /etc/init.d
- 建立一个脚本mongodb文件,并赋予755权限
chmod 775 mongodb
#!/bin/bash
### BEGIN INIT INFO
# Provides: mongod
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start mongod at boot time
# Description: Enable service provided by mongod.
### END INIT INFO
start()
{
/usr/bin/mongod --config /etc/mongod.conf &
exit 0;
}
stop()
{
/usr/bin/mongod --config /etc/mongod.conf --shutdown
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 0
;;
esac
exit 0
- 加入到系统启动中
// 添加到系统启动
update-rc.d mongodb defaults
// 从系统启动中删除
update-rc.d mongodb remove
- 启动命令
service mongodb start
service mongodb stop
设置服务开启启动
systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态