任何升级或安装Ubuntu16.04(也被称为UbuntuXenial xerus)的人都注意到一些旧服务停止运行.
这就是我在MongoDB的情况.长话短说,Ubuntu从暴发户变成了systemd.对于这些问题,一个常见的解决方案是切换回upstart.我不认为这个选项是一个真正的解决方案,当然不是从长远来看.
解决这个问题的真正方法(IMHO)是编写systemd脚本,启动MongodDB.不幸的是,MongoDB的人还没有提供一个.
所以我不得不从头开始写.要创建自己的一个,请执行以下步骤:
或者使用sudo完成以下所有步骤.
创建服务脚本(在本例中,服务的名称为Mongodb)
nano /lib/systemd/system/mongodb.service
文件内容应该是
[Unit] Description=MongoDB Database Service Wants=network.target After=network.target [Service] ExecStart=/usr/bin/mongod --config /etc/mongod.conf ExecReload=/bin/kill -HUP $MAINPID Restart=always User=mongodb Group=mongodb StandardOutput=syslog StandardError=syslog [Install] WantedBy=multi-user.target
You can also download the file from here:
mongodb.service
Here is a quick description of the important fields:
ExecStart - Is the command to run. Mongo installs itself under /usr/bin and the configuration file is written at /etc
User - The uid of the mongod process.
Group - The gid of the mongod process. Note that the user and group are created by the installation.
现在开始mongodb:
sudo systemctl start mongodb
要停止mongodb服务,请使用:
sudo systemctl stop mongodb
在启动时启用mongodb
sudo systemctl enable mongodb.service
如果需要刷新服务,请使用:
sudo systemctl daemon-reload