centos 7的开机启动跟之前版本的centos有很大不同。现在用 systemctl命令代替了之前的chkconfig 和 service 命令
注册到开机启动的方法如下:
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
.