在Ubuntu 16.04 LTS上运行mongodb [英] Running mongodb on ubuntu 16.04 LTS

查看:147
本文介绍了在Ubuntu 16.04 LTS上运行mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Ubuntu 16.04 LTS上将Mongodb作为服务运行? 几天前,我已将服务器升级到Ubuntu 16.04.我注意到重启后我的MongoDB服务无法启动. 尝试使用

How can I run Mongodb, as a service, on Ubuntu 16.04 LTS? A few days ago I had upgrade my server to Ubuntu 16.04. I have noticed the my MongoDB service does not start when I reboot. Trying to use

sudo initctl start mongod

没有做到这一点. 有人知道如何解决这个问题吗?

Did not do the trick. Anyone has an idea how to solve this?

推荐答案

升级或安装Ubuntu 16.04(也称为Ubuntu Xenial xerus)的任何人都注意到某些旧服务停止运行. 从版本15.04开始知道此问题,但我将重点关注上述版本.

Anyone who upgrade or installed Ubuntu 16.04 ( also known as Ubuntu Xenial xerus ) noticed that some of the old services stopped running. This issue is known from version 15.04 but I will focus on the above version.

我在MongoDB上就是这种情况.简而言之,Ubuntu从新贵转向了systemd.解决这些问题的一种常见解决方案是切换回新贵.我不认为该选项是真正的解决方案,从长远来看,当然不是.

Such was my case with MongoDB. To make a long story, short, Ubuntu shifted from upstart to systemd. One common solution, to these problems, is to switch back to upstart. I do not consider that option as a real solution, certainly not for the long run.

解决此问题的一种真正解决方案(IMHO)是编写将启动MongodDB的systemd脚本.不幸的是,MongoDB的人还没有提供.

A real solution ( IMHO ) to the problem is to write systemd script that will start MongodDB. Unfortunately MongoDB guys had yet to supply one.

所以我不得不从头开始写一个.要创建自己的一个,请按照以下步骤操作:

So I had to write one from scratch. To create one of your own follow these steps:

  1. 使用切换到root
  1. switch to root using

sudo su

或将sudo用于以下所有步骤.

or use sudo for all the following steps.

  1. 创建服务脚本(在本示例中,服务名称为Mongodb)

  1. create a service script (in this example the name of the service is Mongodb)


nano /lib/systemd/system/mongodb.service

  • 文件内容应为

  • File content should be

    
    [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
    

  • 您也可以从此处下载文件: mongodb.service
    以下是重要字段的简要说明:
    ExecStart -是要运行的命令. Mongo将其自身安装在/usr/bin下,并且配置文件在/etc
    中编写 用户-mongod进程的uid.
    Group -mongod进程的向导.请注意,用户和组是由安装创建的.

    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:

    Now to start mongodb:

    sudo systemctl start mongodb
    

    要停止使用mongodb服务,请执行以下操作:

    To stop mongodb service use:

    sudo systemctl stop mongodb
    

    要在启动时启用mongodb

    To enable mongodb on startup

    sudo systemctl enable mongodb.service
    

    如果您需要刷新服务,请使用:

    If you need to refresh the services use:

     sudo systemctl daemon-reload
    

    这篇关于在Ubuntu 16.04 LTS上运行mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆