centos7 下设置 mongodb 开机启动
centos 7的开机启动跟之前版本的centos有很大不同。现在用 systemctl命令代替了之前的chkconfig 和 service 命令
注册到开机启动的方法如下:
在系统服务目录下新建mongodb的启动服务
|
1
2
|
cd /lib/systemd/systemvi mongodb.service |
内容如下
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[Unit] Description=mongodbAfter=network.target remote-fs.target nss-lookup.target [Service]Type=forkingExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/mongodb.confPrivateTmp=true [Install]WantedBy=multi-user.target |
路径必须要写绝对路径
并给与754的权限
|
1
|
chmod 754 mongodb.service |
操作
|
1
2
3
4
5
6
|
启动systemctl start mongodb.service关闭systemctl stop mongodb.service注册到开机启动systemctl enable mongodb.service |
重启机器验证
|
1
|
reboot |
浙公网安备 33010602011771号