ubuntu 版本 18.04
在另一篇中已经把mongodb的一些配置说明了,这里只介绍 nbuntu 的开机自启 sh文件
centos基本一次性就配置好了,但是ubuntu 配置试验了好长时间(主要是自己水平低),写这个作为以后的参考。
在 /ect/systemd/system/ 创建 mymongodb.service 如下:
# SPDX-License-Identifier: LGPL-2.1+
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/start_mongodb.sh
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
[Install]
WantedBy=multi-user.target
sh文件添加权限
sudo chmod +x
更新配置
sudo systemctl daemon-reload service文件改动后要重新转载一下
sudo systemctl enable my.service 这句是为了设置开机启动
立刻使用这个脚本
sudo systemctl start my.service 启动服务
参考:https://blog.csdn.net/qq570437459/article/details/87094870
参考:https://www.yuanmas.com/info/9ezZkJ2Ba6.html
参考: https://blog.csdn.net/dahuzix/article/details/80785691
参考:http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html