centos7 下设置 mongodb 开机启动
centos 7的开机启动跟之前版本的centos有很大不同。现在用 systemctl命令代替了之前的chkconfig 和 service 命令
注册到开机启动的方法如下:
在系统服务目录下新建mongodb的启动服务
1
2
|
cd /lib/systemd/system vi mongodb.service |
内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[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的权限
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 |