直接上干货
tar包安装解压移动改名
mv /maycur/mongodb-linux-x86_64-rhel70-4.2.20 /maycur/mongodb
1、在/etc/systemd/system目录下创建一个mongodb.service文件
vim /etc/systemd/system/mongodb.service
2、配置文件添加以下内容
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/maycur/mongodb/bin/mongod --config /maycur/mongodb/conf/config.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/maycur/mongodb/bin/mongod --config /maycur/mongodb/conf/config.conf --shutdown
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3、重新加载配置文件
systemctl daemon-reload
4、启动并且设置开机自启动
启动
systemctl start mongodb
关闭
systemctl stop mongodb
查看启动状态
systemctl status mongodb
设置永久开机自启
systemctl enable mongodb