文档章节

ubuntu 15.10 mongodb.service 起不起来解决方案

pantrick
 pantrick
发布于 2016/03/08 20:18
字数 1146
阅读 423
收藏 0

In this article I shall go through the steps for installing MongoDB ( a open source, very popular NoSQL database, widely used in web-applications) in Ubuntu 15.04 and also some common issues.

First to note that Mongoddb’s official Ubuntu installation page says that currently it only provides packages for 64-bit long-term Ubuntu releases. That is 12.04 LTS (Precise Pangolin) and 14.04 LTS (Trusty Tahr). There is currently no build available for Ubuntu 15.04. Check this page for all builds

Hence, when installing on Ubuntu 15.04 (Vivid) following the exact process and commands of the above MongoDB’s official page will not work. Hence the below steps that worked in my Ubuntu 15.04

##First to completely remove an existing Mongodb from your machine if you have that in already

If you have already followed Mongoddb’s official Ubuntu installation page and installed it, and then post installation its not working in your machine; e.g. the commands sudo service mongod start OR sudo mongod is not starting the service - then first remove this existing version completely before installing a new one. Run the below commands in sequence.

sudo apt-get purge mongodb-org

sudo apt-get autoremove

And now delete the old mongodb.list that was created.

sudo rm /etc/apt/sources.list.d/mongodb.list

##Installing a fresh MongoDB into Ubuntu 15.04 from debian wheezy repository

Step-A

First Issue the following command to import the MongoDB public GPG Key:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

Now as advised in this jira issue page create the /etc/apt/sources.list.d/mongodb-org-3.0.list list-file to get the package from debian wheezy repository

echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

Reload the local package database

sudo apt-get update

And now install the latest stable version of mongodb ( If you want to install a specific version see the official page.

sudo apt-get install -y mongodb-org

Now you can check the installation version by running mongod --version which at the time of this writing (3-Sep-2015) returned in my Terminal "db version v3.0.6" (i.e. the latest stable version)

Step-B

However, after all the steps above and mongodb installed in our machine, now if you try to start the mongodb service with sudo service mongod start it will fail. You may get various reasons for failure in the Terminal. For example I first got

"start: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused”

Then I also got

Failed to start mongod.service: Unit mongod.service failed to load: No such file or directory.

You probably will be able to manually start it with sudo mongod -f /etc/mongod.conf - but in this way MongoDB will remain connected as long as that terminal is opened.

So here is how we are going to resolve and startup mongodb normally

  • First we are going to change MongoDB’s default data store files from /var/lib/mongodb to/data/db

  • So, first create a folder /data/db in your machine. Run sudo mkdir -p /data/db

  • Now open the main mongo configuration file with sudo gedit /etc/mongod.conf and change the “dbpath” line as below

  • Replace dbpath=/var/lib/mongodb TO dbpath=/data/db and then save the file.

  • Then delete the old default /var/lib/mongodb

  • But the directory you created doesn’t have the correct permissions and ownership right after creation – it needs to be writable by the user who runs the MongoDB process. Hence we must make all the directories/files owned by mongod user

  • Run sudo chown -R mongodb:mongodb /data/db

And now finally you can start mongo with sudo service mongod start

And chcek that the service is running with sudo systemctl status mongod - It should show a message similar to below

Loaded: loaded (/etc/init.d/mongod)

Active: active (running) since Thu 2015-09-03 04:57:49 IST; 7s ago

Another way to verify that the mongod process has started successfully is by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading

[initandlisten] waiting for connections on port <port>

where port is the port configured in /etc/mongod.conf, 27017 by default. So for example, in my machine this line was the below one.

2015-09-02T08:53:15.156+0530 I NETWORK [initandlisten] waiting for connections on port 27017

And to stop or restart MongoDB run sudo service mongod stop and sudo service mongod restart respectively.

Other small issue that you might face (as it came up in my case)

Issue-A> After running sudo service mongod start it failed giving the below erroor.

couldn't unlink socket file /tmp/mongodb-27017.sockerrno:1 Operation not permitted skipping

Solution - Just delete the file .sock file with sudo rm /tmp/mongodb-27017.sock

This was probably because, I started things up before and didn’t shutdown correctly.

Update in Feb-2016: Installing Mongodb in Ubuntu 15.10

Step-A

From Ubuntu’s official package page install the mongodb version 2.6.10 (at this point, this is the latest MongoDB version for which Ubuntu 15.10 (wily) has an official Mongodb package) through Software Center.

Post installation, check the version number with mongod --version

Step-B

Create a systemd startup file in - /lib/systemd/system/mongodb.service with the following content -

[Unit]Description=High-performance, schema-free document-oriented databaseDocumentation=man:mongod(1)After=network.target[Service]Type=forkingUser=mongodbGroup=mongodbRuntimeDirectory=mongodPIDFile=/var/run/mongod/mongod.pidExecStart=/usr/bin/mongod -f /etc/mongod.conf --pidfilepath /var/run/mongod/mongod.pid --forkTimeoutStopSec=5KillMode=mixed[Install]WantedBy=multi-user.target

Now enable this mongodb.service file and start it with the following command

sudo systemctl enable mongodb.service

Step-C

Create a folder /data/db in your machine; i.e. run sudo mkdir -p /data/db

And then take ownership of the /data/db directory by running - sudo chown -R mongodb /data/db

Now open the mongodb configuration file with sudo gedit /etc/mongod.conf and change the “dbpath” line as below

Replace dbpath: /var/lib/mongodb TO dbpath: /data/db and then save the file.

Step-D

Now running sudo service mongodb start should start mongodb normally.

To check if mongodb started by open the log file at /var/log/mongodb/mongodb.log. The log file’s last line should show something like :-

“[initandlisten] waiting for connections on port 27017”

Other possible issues in installing Mongodb in Ubuntu 15.10

1. After doing all the above, if you still have some problem in starting mongodb with sudo service mongodb start try to understand some details on the source of the problem by running sudo systemctl status mongod.service in the terminal. If this gives some error with respect to starting the database then check if the file /data/db/mongod.lock exists. If it does, remove it and execute mongod --repair and then again run sudo service mongodb start


本文转载自:https://rohan-paul.github.io/mongodb_in_ubuntu/2015/09/03/How_to_Install_MongoDB_Iin_Ubuntu-15.04...

pantrick
粉丝 24
博文 24
码字总数 1078
作品 0
澳门
其他
私信 提问
Ubuntu 15.10 内建隐藏式滚动条

Ubuntu 15.10(威利狼人)操作系统一大特点是采用来自于上游 GNOME 的滚动条,这将让很多用户感到高兴。Ubuntu 开发者 Canonical 是做事我行我素的公司,不会过于依赖上游项目,就是为什么我...

oschina
2015/09/25
3.3K
13
Ubuntu 15.10 Beta 1 发布,10月22日发布最终版

Ubuntu 15.10 Beta 1 发布,这是 Ubuntu Wily Werewolf(15.10)的第一个 Beta 版本,提供了 Kubuntu,Lubuntu,Ubuntu GNOME,Ubuntu Kylin,Ubuntu MATE,Xubuntu 和 Ubuntu Cloud 镜像。 ......

oschina
2015/08/28
10K
28
Ubuntu 15.10内建隐藏式滚动条

Ubuntu 15.10(威利狼人)操作系统一大特点是采用来自于上游GNOME的滚动条,这将让很多用户感到高兴。Ubuntu开发者Canonical是做事我行我素的公司,不会过于依赖上游项目,就是为什么我们今天...

Foundation
2015/09/25
69
0
Ubuntu 15.10 Wily Werewolf 最终版发布

Ubuntu 15.10 代号 Wily Werewolf,这是最后一个“无聊”的版本更新,该版本仍然采用 Unity 7,这是一个饱受诟病的桌面环境,但很快,我们就要看到一个相当不同的Ubuntu了,尽管官方透露在 ...

oschina
2015/10/23
8.8K
48
Ubuntu MATE 15.10 Final 发布

Ubuntu MATE 15.10 Final 发布,更新内容如下: Fixed and to upgrade from Ubuntu MATE 15.04 to Ubuntu MATE 15.10. Fixed the openSUSE panel layout, GNOME Main Menu no longer crashes......

oschina
2015/10/23
5K
9

没有更多内容

加载失败,请刷新页面

加载更多

分布式场景下如何保证消息队列实现最终一致性

考虑一个分布式场景中一个常见的场景:服务A执行某个数据库操作成功后,会发送一条消息到消息队列,现在希望只有数据库操作执行成功才发送这条消息。下面是一些常见的作法: 1. 先执行数据库...

中关村的老男孩
25分钟前
4
0
招银网络面试题、考点、知识点总结(Java岗)

java基础 全是基础不用多说肯定考的多,尤其是招银 OOP特性/java语言特性:封装、继承、多态 多态具体的表现:多态应用举例、如何调用父类方法(super)、重写和重载(重写父类方法的规则、构...

戎码益深
30分钟前
2
0
Mybatis深入源码分析之SQLSession一级缓存原理分析

源码分析图

须臾之余
33分钟前
2
0
成年人社交中的10个潜规则

前阵子我建议大家有空的时候,一定要去看《红楼梦》这本书。 原因就是从这本书,可以学习到很多很多人情世故,人情世故在学校里,老师几乎都不会教,所以我们只能靠自己去学。 只有自己去学了...

ZhangLG
35分钟前
3
0
在PyCharm中使用Pylint

简介 pylint是一个用于检查python代码中的错误,尝试强制执行编码标准的工具。它还可以查找某些类型错误,可以建议如何重构特定块的建议,并可以向您提供有关代码复杂性的详细信息。 官网:w...

哼_哼
36分钟前
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部