./bin/mongod --config /home/data/mongodb4.0/config/mongo.conf
这样启动mongo太麻烦来哦
把mongo加入systemctl进行管理服务,可以通过以下命令管理mongo
systemctl restart mongod 重启
systemctl stop mongod 暂停
systemctl start mongod 启动
systemctl status mongod 查看状态
cd /usr/lib/systemd/system
touch mongo.service 【必须以 .service 结尾】
写入以下文件
- [Unit]
- Description=mongo
- After=network.target remote-fs.target nss-lookup.target
-
- [Service]
- Type=forking
- User=root
- Group=root
- ExecStart=/home/data/mongodb4.0/bin/mongod --config /home/data/mongodb4.0/config/mongo.conf
- ExecReload=/bin/kill -s HUP $MAINPID
- ExecStop=/home/data/mongodb4.0/bin/mongod --shutdown /home/data/mongodb4.0/config/mongo.conf
- PrivateTmp=true
[Service]
Type=forking
User=root 【使用root用户】
Group=root 【使用root用户】
ExecStart=/home/data/mongodb4.0/bin/mongod --config /home/data/mongodb4.0/config/mongo.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/home/data/mongodb4.0/bin/mongod --shutdown /home/data/mongodb4.0/config/mongo.conf
/home/data/mongodb4.0/bin/mongod : 是mongo安装目录
/home/data/mongodb4.0/config/mongo.conf : 是mongo配置文件目录
安装目录和配置目录记得修改
systemctl daemon-reload
#启动mongo
systemctl start mongod 启动