sudo service mongodb restart gives “unrecognized s

2019-03-08 13:36发布

I just installed mongoDB on ubuntu 14.0.4. I tried to start the shell but I'm getting a connection refused error.

me@medev:/etc/init.d$ mongo
MongoDB shell version: 2.6.5
connecting to: test
2014-11-10T15:06:28.084-0500 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-11-10T15:06:28.085-0500 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed

So I decided to try to restart the service but that's failing too. I get the following error message:

me@medev:/etc/init.d$ sudo service mongodb restart
mongodb: unrecognized service
me@medev:/etc/init.d$ 

This is what I have in my /var/log/mongodb/mongod.log - http://pastebin.com/MrHt8tce

what i've tried so far:

I found another post here: can't start mongodb as sudo which made a comment about remove the mongo lock file.

I deleted the lock file and then retried my command but it still fails as you can see below:

me@medev:/var/lib/mongodb$ sudo rm mongod.lock 
me@medev:/var/lib/mongodb$ ls
journal  local.0  local.ns  _tmp

me@medev:/var/lib/mongodb$ sudo service mongodb start
mongodb: unrecognized service

But I can start it using /etc/init.d as you can see below:

me@medev:/var/lib/mongodb$ sudo /etc/init.d/mongod start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mongod start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mongod
mongod start/running, process 27469
me@medev:/var/lib/mongodb$ ls
journal  local.0  local.ns  mongod.lock

me@medev:/var/lib/mongodb$ mongo
MongoDB shell version: 2.6.5
connecting to: test
> db
test
> 

Any ideas on why I can't start it using the service command would be appreciated. From what I've read, i should be using sudo service mongodb

11条回答
该账号已被封号
2楼-- · 2019-03-08 13:40

This is a simple solution that worked for me with the same problem (I think): mv /var/lib/mongodb /var/lib/mongodb_backup mkdir /var/lib/mongodb chmod 700 /var/lib/mongodb chown mongodb:daemon /var/lib/mongodb systemctl restart mongodb or service mongod restart

查看更多
我只想做你的唯一
3楼-- · 2019-03-08 13:43

I got the same error one day You should use this:

1.Get the status of your mongo service:

 /etc/init.d/mongod status

or

 sudo service mongod status

2.If it's not started repair it like this:

sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start

And check again if the service is started again(1)

查看更多
Animai°情兽
4楼-- · 2019-03-08 13:45

For debian, from the 10gen repo, between 2.4.x and 2.6.x, they renamed the init script /etc/init.d/mongodb to /etc/init.d/mongod, and the default config file from /etc/mongodb.conf to /etc/mongod.conf, and the PID and lock files from "mongodb" to "mongod" too. This made upgrading a pain, and I don't see it mentioned in their docs anywhere. Anyway, the solution is to remove the old "mongodb" versions:

update-rc.d -f mongodb remove
rm /etc/init.d/mongodb
rm /var/run/mongodb.pid
diff -ur /etc/mongodb.conf /etc/mongod.conf

Now, look and see what config changes you need to keep, and put them in mongod.conf.

Then:

rm /etc/mongodb.conf

Now you can:

service mongod restart
查看更多
看我几分像从前
5楼-- · 2019-03-08 13:45

I installed mongo server on Debian Jessie using manual from official site.

It didn't started after recommended command sudo service mongod restart with the same error - mongodb: unrecognized service.

After looking into installed package contents, I noticed that it contains only Systemd service unit, but no SystemV init script:

# dpkg -L mongodb-org-server
/.
/usr
/usr/bin
/usr/bin/mongod
/usr/share
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/mongodb-org-server
/usr/share/doc
/usr/share/doc/mongodb-org-server
/usr/share/doc/mongodb-org-server/LICENSE-Community.txt
/usr/share/doc/mongodb-org-server/README
/usr/share/doc/mongodb-org-server/copyright
/usr/share/doc/mongodb-org-server/changelog.gz
/usr/share/doc/mongodb-org-server/GNU-AGPL-3.0.gz
/usr/share/doc/mongodb-org-server/THIRD-PARTY-NOTICES.gz
/usr/share/doc/mongodb-org-server/MPL-2.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/mongod.1.gz
/etc
/etc/mongod.conf
/lib
/lib/systemd
/lib/systemd/system
/lib/systemd/system/mongod.service

But my system was running on SysV init:

# stat /proc/1/exe
File: '/proc/1/exe' -> '/sbin/init'

So, there are 2 options now:

查看更多
神经病院院长
6楼-- · 2019-03-08 13:46

For me the solution was to replace

service mongod start

with

start mongod
查看更多
ら.Afraid
7楼-- · 2019-03-08 13:48

I think you may have installed the version of mongodb for the wrong system distro.

Take a look at how to install mongodb for ubuntu and debian:

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian/ http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

I had a similar problem, and what happened was that I was installing the ubuntu packages in debian

查看更多
登录 后发表回答