Replication

在配置文件中添加 security.keyFile 後服務 mongod 失敗

  • May 19, 2017

我的 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'

問題:當我在 mongo.conf 中添加 keyFile 後執行服務 mongod restart 時,如上所示

keyFile: '~/rsKeyFile'

當我檢查服務 mongod 狀態時,我的服務失敗,它說:

"/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.

我對我的 rsKeyFile 有 777 權限,但它仍然無法正常工作,當我在 mongo.conf 中像下面給出的那樣評論密鑰並嘗試重新啟動 mongod 服務時它工作得非常好並顯示這個 Active: active (running) since Thu 2017-05-18太平洋時間 06:23:51;2s 前狀態。

#keyFile: '~/rsKeyFile'

我正在關注這個https://docs.mongodb.com/manual/tutorial/deploy-replica-set/

請幫忙,提前謝謝!!

使用密鑰文件的完整路徑。不要在那裡使用 ~ 字元。您的 mongod 以使用者 ‘mongod’ 啟動(可能),並且該使用者沒有主目錄。

此外,密鑰文件的 chmod 0400 和所有權必須與執行 mongod 程序 (mongod) 的使用者相同。

引用自:https://dba.stackexchange.com/questions/173937