How to configure MongoDB 3.4 auto start with authentication when OS Ubuntu 16.04 reboot?

July 27, 2017 185 views
MongoDB Ubuntu

I can make this work without authentication but when I add "authorization: enabled" into /etc/mongod.conf, the mongod.service stops working. Please help.

1 comment
  • This problem is solved after changing all file owners to mongodb:mongodb. The files are mongodb.key and files under /var/lib/mongodb. Many thanks to hensen.

1 Answer
hansen July 27, 2017
Accepted Answer

Hi @linaizhong

Add the following to /etc/mongodb.conf (I'm expecting you're using MongoDB 3+)

   authorization: enabled

If you already have the security: section, then make sure the second line is indented.

  • Yes, it is indented.

    • @linaizhong

      Can you activate logging:
      And then post the log here after you try to start MongoDB again.

      • Thanks a lot, hansen.

        2017-07-28T08:24:30.445+1000 I CONTROL [main] ***** SERVER RESTARTED *****
        2017-07-28T08:24:30.464+1000 I CONTROL [initandlisten] MongoDB starting : pid=8663 port=27017 dbpath=/var/lib/mongodb 64-bit host=M4-MMS-ARBITER
        2017-07-28T08:24:30.464+1000 I CONTROL [initandlisten] db version v3.4.6
        2017-07-28T08:24:30.464+1000 I CONTROL [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
        2017-07-28T08:24:30.464+1000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
        2017-07-28T08:24:30.464+1000 I CONTROL [initandlisten] allocator: tcmalloc
        2017-07-28T08:24:30.464+1000 I CONTROL [initandlisten] modules: none
        2017-07-28T08:24:30.464+1000 I CONTROL [initandlisten] build environment:
        2017-07-28T08:24:30.464+1000 I CONTROL [initandlisten] distmod: ubuntu1604
        2017-07-28T08:24:30.464+1000 I CONTROL [initandlisten] distarch: x8664
        2017-07-28T08:24:30.465+1000 I CONTROL [initandlisten] target
        arch: x8664
        2017-07-28T08:24:30.465+1000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "", port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongod/" }, replication: { replSetName: "m4mmsTestRepl" }, security: { authorization: "enabled", keyFile: "/home/administrator/m4mms/mongodb.key" }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
        2017-07-28T08:24:30.504+1000 I - [initandlisten] Detected data files in /var/lib/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
        2017-07-28T08:24:30.504+1000 I STORAGE [initandlisten]
        2017-07-28T08:24:30.504+1000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
        2017-07-28T08:24:30.504+1000 I STORAGE [initandlisten] ** See
        2017-07-28T08:24:30.504+1000 I STORAGE [initandlisten] wiredtiger
        open config: create,cachesize=256M,sessionmax=20000,eviction=(threadsmin=4,threadsmax=4),configbase=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),filemanager=(closeidletime=100000),checkpoint=(wait=60,logsize=2GB),statisticslog=(wait=0),
        2017-07-28T08:24:30.510+1000 E STORAGE [initandlisten] WiredTiger error (13) [1501194270:510313][8663:0x7eff388fdd00], file:WiredTiger.wt, connection: /var/lib/mongodb/WiredTiger.turtle: handle-open: open: Permission denied
        2017-07-28T08:24:30.510+1000 I - [initandlisten] Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtigerkvengine.cpp 269
        2017-07-28T08:24:30.577+1000 I STORAGE [initandlisten] exception in initAndListen: 28595 13: Permission denied, terminating
        2017-07-28T08:24:30.577+1000 I NETWORK [initandlisten] shutdown: going to close listening sockets...
        2017-07-28T08:24:30.577+1000 I NETWORK [initandlisten] shutdown: going to flush diaglog...
        2017-07-28T08:24:30.577+1000 I CONTROL [initandlisten] now exiting
        2017-07-28T08:24:30.577+1000 I CONTROL [initandlisten] shutting down with code:100

        • @linaizhong

          Did you fix your problem, since you marked it as an accepted answer?
          If yes, then can you post the solution.

          If no, then it looks like your /var/lib/mongodb is not owned by the user/group that runs MongoDB. If your user/group is mongodb then run this to set the permissions for the path:

          sudo chown -R mongodb:mongodb /var/lib/mongodb
          • This problem is solved after changing all file owners to mongodb:mongodb. The files are mongodb.key and files under /var/lib/mongodb. Many thanks to hensen.

Have another answer? Share your knowledge.