HiveBrain v1.2.0
Get Started
← Back to all entries
debugMinor

Service mongod fails after adding security.keyFile in config file

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
afterfailskeyfilefileaddingmongodservicesecurityconfig

Problem

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,

Solution

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).

Context

StackExchange Database Administrators Q#173937, answer score: 3

Revisions (0)

No revisions yet.