0

My mongo.conf:

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

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

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile

# network interfaces
net:
  port: 27017
  bindIp: [127.0.0.1, 172.24.16.25]  # Listen to local interface only, comment to listen on all interfaces.


security:
  authorization: enabled
  keyFile: '~/rsKeyFile'

Issue: When i perform service mongod restart after adding keyFile in mongo.conf as shown above

keyFile: '~/rsKeyFile'

My service fails when i check service mongod status it says:

"/etc/mongod.conf" 47L, 851C written
[root@788978-APP06 ~]# service mongod restart
Redirecting to /bin/systemctl restart  mongod.service
[root@788978-APP06 ~]# service mongod status
Redirecting to /bin/systemctl status  mongod.service
â mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2017-05-18 06:19:43 PDT; 2s ago
     Docs: https://docs.mongodb.org/manual
  Process: 24066 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=1/FAILURE)
  Process: 24064 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 24060 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 24056 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 24066 (code=exited, status=1/FAILURE)

May 18 06:19:43 788978-APP06.dgsworld.com systemd[1]: Starting High-performance, schema-free document-oriented database...
May 18 06:19:43 788978-APP06.dgsworld.com systemd[1]: Started High-performance, schema-free document-oriented database.
May 18 06:19:43 788978-APP06.dgsworld.com mongod[24066]: about to fork child process, waiting until server is ready for connections.
May 18 06:19:43 788978-APP06.dgsworld.com mongod[24066]: forked process: 24069
May 18 06:19:43 788978-APP06.dgsworld.com mongod[24066]: ERROR: child process failed, exited with error number 1
May 18 06:19:43 788978-APP06.dgsworld.com systemd[1]: mongod.service: main process exited, code=exited, status=1/FAILURE
May 18 06:19:43 788978-APP06.dgsworld.com systemd[1]: Unit mongod.service entered failed state.
May 18 06:19:43 788978-APP06.dgsworld.com systemd[1]: mongod.service failed.

I have 777 permissions on my rsKeyFile but still its not working, when i comment key fine in mongo.conf like given below and try restarting mongod service it works perfectly fine and show this Active: active (running) since Thu 2017-05-18 06:23:51 PDT; 2s ago status.

#keyFile: '~/rsKeyFile'

I am following this https://docs.mongodb.com/manual/tutorial/deploy-replica-set/

Please help, thanks in advance!!

  • 1
    Have you checked the mongod log? – Vince Bowdren May 19 '17 at 7:25
  • In case this is a replica set, did you copy the keyfile to each replica set member? – SqlWorldWide May 19 '17 at 11:15
  • @Vince: No i didn't. Thanks this is a good point may be there i find some details whats causing this issue. – Abdul Moiz May 19 '17 at 11:18
  • Yes i had copied the file to all members but did not add it in mongo.conf because when i added its path in the conf of first replica set member and restarted the service so its said service failed. That is why i didn't add its path into the conf file of other two members of replica set – Abdul Moiz May 19 '17 at 11:22
1

Use full path for keyfile. Don't use ~ -character there. Your mongod is started (probably) with user 'mongod' and that user don't have home directory.

Additionally keyfile must be have chmod 0400 and ownership same than user who run mongod process (mongod).

  • I think thats not the issue because i have tried placing my keyFile in various location but thay did not work. Like previously it was in /var/tmp – Abdul Moiz May 19 '17 at 9:10
  • And size of your keyfile is? Chmod should be 400 and owner same than running user (mongod) – JJussi May 19 '17 at 9:50
  • for now i am using root user. So it has all the permissions. And chmod is 777 now i have already tried 400 as mentioned in mongo docs and the size of keyfile is same as mentioned in mongo docs i followed all the instructions from there. – Abdul Moiz May 19 '17 at 9:56
  • And i have also tried mentioning path with and without single quotes. – Abdul Moiz May 19 '17 at 9:56
  • I newer had problems with keyFile. Please could you "test" and do next. set on your mongod.conf file: keyFile: "/tmp/keyfile.txt" and then run: echo "ThisISmySecret" > /tmp/keyfile.txt; chown mongod: /tmp/keyfile.txt; chmod 0400 /tmp/keyfile.txt; service mongod restart – JJussi May 19 '17 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.