centos7 下设置 mongodb 开机启动 (重点)

mac2022-06-30  18

centos 7的开机启动跟之前版本的centos有很大不同。现在用 systemctl命令代替了之前的chkconfig 和 service 命令

注册到开机启动的方法如下:

在系统服务目录下新建mongodb的启动服务

cd /lib/systemd/system vi mongodb.service

内容如下

[Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/mongodb.conf PrivateTmp=true [Install] WantedBy=multi-user.target

路径必须要写绝对路径

并给与754的权限

chmod 754 mongodb.service

操作

启动 systemctl start mongodb.service 关闭 systemctl stop mongodb.service 注册到开机启动 systemctl enable mongodb.service

重启机器验证

reboot

.

 

 

转载于:https://www.cnblogs.com/crazycode2/p/11178988.html

最新回复(0)