CaribouCode
CaribouCode

Reputation: 14398

Mongo can't connect

I'm running Ubuntu 15 on an Azure VPS. I installed MongoDB and got it up and running fine. Then, I stopped the mongod service and I changed the db path and log path in mongod.conf to point to directories I've created on an attached disk:

# Where and how to store data.
storage:
  dbPath: /datadrive/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /datadrive/log/mongodb/mongod.log

I restarted the entire VPS to make double sure the new changes take effect. Now when I type mongo I get the following error:

2016-02-05T14:49:41.004+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-02-05T14:49:41.018+0000 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:224:14
@(connect):1:6

If I reverse my changes and use the original log and lib locations, it works. What can I do to make sure the new locations are used?

Edit

After keeping the old log location and trying the above steps, I get the following in the log:

2016-02-05T15:19:47.049+0000 I CONTROL  [main] ***** SERVER RESTARTED *****
2016-02-05T15:19:47.146+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1158 port=27017 dbpath=/datadrive/lib/mongodb 64-bit host=CLIENTPROJECTS
2016-02-05T15:19:47.146+0000 I CONTROL  [initandlisten] db version v3.2.1
2016-02-05T15:19:47.146+0000 I CONTROL  [initandlisten] git version: a14d55980c2cdc565d4704a7e3ad37e4e535c1b2
2016-02-05T15:19:47.146+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2d 9 Jul 2015
2016-02-05T15:19:47.146+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2016-02-05T15:19:47.146+0000 I CONTROL  [initandlisten] modules: none
2016-02-05T15:19:47.146+0000 I CONTROL  [initandlisten] build environment:
2016-02-05T15:19:47.146+0000 I CONTROL  [initandlisten]     distmod: ubuntu1404
2016-02-05T15:19:47.146+0000 I CONTROL  [initandlisten]     distarch: x86_64
2016-02-05T15:19:47.146+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2016-02-05T15:19:47.146+0000 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/datadrive/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-02-05T15:19:47.693+0000 I STORAGE  [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /datadrive/lib/mongodb/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-02-05T15:19:47.693+0000 I CONTROL  [initandlisten] dbexit:  rc: 100

Upvotes: 1

Views: 1454

Answers (1)

Alex Blex
Alex Blex

Reputation: 37048

First of all you can check if mongod started: sudo lsof -i | grep 27017 and then check what's in the log /datadrive/log/mongodb/mongod.log.

EDIT:

Stop all instances of mongod (ps aux | grep mongod should show nothing's running), remove lock file rm /datadrive/lib/mongodb/mongod.lock, and restart the service.

EDIT2:

Directories from the config /datadrive/lib/mongodb/ and /datadrive/log/mongodb/ should exist and belong to mongodb user. By default it is mongodb:mongodb, and is defined in /etc/init.d/mongodb as DAEMONUSER.

Upvotes: 1

Related Questions