Service mongod fails after adding security.keyFile in config file

Posted: edited May 19 at 11:25 - Source : stackoverflow

My mongo.conf:

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

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

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

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

  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
[[email protected] ~]# service mongod restart
Redirecting to /bin/systemctl restart  mongod.service
[[email protected] ~]# 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
  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 systemd[1]: Starting High-performance, schema-free document-oriented database...
May 18 06:19:43 systemd[1]: Started High-performance, schema-free document-oriented database.
May 18 06:19:43 mongod[24066]: about to fork child process, waiting until server is ready for connections.
May 18 06:19:43 mongod[24066]: forked process: 24069
May 18 06:19:43 mongod[24066]: ERROR: child process failed, exited with error number 1
May 18 06:19:43 systemd[1]: mongod.service: main process exited, code=exited, status=1/FAILURE
May 18 06:19:43 systemd[1]: Unit mongod.service entered failed state.
May 18 06:19:43 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

Please help, thanks in advance!!