mongodb4.2---Configuration File Options--外部源配置文件值

版本4.2中的新功能。

MongoDB支持在配置文件中使用扩展指令来加载外部源值。扩展指令可以加载特定配置文件选项的 值 或加载整个配置文件。扩展指令有助于隐藏安全证书和密码等机密信息。

storage:
  dbPath: "/var/lib/mongod"
systemLog:
  destination: file
  path: "/var/log/mongod/mongod.log"
net:
  bindIp:
    __exec: "python /home/user/getIPAddresses.py"
    type: "string"
    trim: "whitespace"
    digest: 85fed8997aac3f558e779625f2e51b4d142dff11184308dc6aca06cff26ee9ad
    digest_key: 68656c6c30303030307365637265746d796f6c64667269656e64
  tls:
    mode: requireTLS
    certificateKeyFile: "/etc/tls/mongod.pem"
    certificateKeyFilePassword:
      __rest: "https://myrestserver.example.net/api/config/myCertKeyFilePassword"
      type: "string"
      digest: b08519162ba332985ac18204851949611ef73835ec99067b85723e10113f5c26
      digest_key: 6d795365637265744b65795374756666
  • 如果配置文件包含__rest 扩展,则在Linux / macOS上,对配置文件的读访问权限必须仅限于运行mongodmongos process 的用户
  • 如果配置文件包含__exec 扩展,则在Linux / macOS上,对配置文件的写访问权限必须仅限于运行mongodmongos process 的用户 

要使用扩展指令,必须使用所使用的扩展指令--configExpand的完整列表指定 命令行选项:

mongod --config "/path/to/config/mongod.conf" --configExpand "rest,exec"

如果省略该  --configExpand选项,或者如果未指定配置文件中使用的扩展指令的完整列表,则mongod/会mongos返回错误并终止。您只能--configExpand在命令行上指定该 选项。

1.使用__rest扩展指令

__rest从扩展指令加载配置文件值REST的端点。__rest支持在配置文件中加载特定值加载整个配置文件。

以下配置文件使用 __rest扩展指令net.tls.certificateKeyFilePassword 从外部REST端点加载设置值:

Specific Value

storage:
  dbPath: "/var/lib/mongod/"
systemLog:
  destination: file
  path: "/var/log/mongod/mongod.log"
net:
  bindIp: 192.51.100.24,127.0.0.1
  tls:
    mode: requireTLS
    certificateKeyFile: "/etc/tls/mongod.pem"
    certificateKeyFilePassword:
      __rest: "https://myrestserver.example.net/api/config/myCertKeyFilePassword"
      type: "string"

Full Configuration File

__exec: "python /home/myUserName/getFullConfig.py"
type: "yaml"

文件权限

如果配置文件包含__rest 扩展,则在Linux / macOS上,对配置文件的读访问权限必须仅限于运行mongod/ mongos process 的用户。

扩展解析

要解析__rest块,请使用 选项启动mongod/ 。mongos--configExpand "rest"

该mongod/ mongos发出GET对指定URL请求。如果成功,mongod/ mongos替换 certificateKeyFilePassword返回值的值。如果网址无法解析或者如果REST端点返回无效值时,mongod/ mongos引发错误并终止。

重要:指定REST端点 返回的值不能包含任何其他扩展指令。在 mongod/ mongos不不返回的数据执行额外的处理,并且如果所返回的数据包括附加膨胀指令将一个错误代码终止。

2.使用__exec扩展指令

在__exec从一个外壳或终端命令扩展指令加载配置文件的值。__exec支持在配置文件中加载特定值或加载整个配置文件。

Specific Value

storage:
  dbPath: "/var/lib/mongod/"
systemLog:
  destination: file
  path: "/var/log/mongod/mongod.log"
net:
  bindIp: 192.51.100.24,127.0.0.1
  TLS:
    mode: requireTLS
    certificateKeyFile: "/etc/tls/mongod.pem"
    certificateKeyFilePassword:
      __exec: "python /home/myUserName/getPEMPassword.py"
      type: "string"

文件权限

如果配置文件包含__exec 扩展,则在Linux / macOS上,对配置文件的写访问权限必须仅限于运行mongod/ mongosprocess 的用户 。

扩展解析

要解析__exec块,请使用 选项启动mongod/ 。mongos--configExpand "exec"

mongod/ mongos试图执行指定的操作。如果命令成功执行,则mongod/ mongos 替换certificateKeyFilePassword返回值的值。如果命令失败或返回配置文件设置的无效值,则 mongod/ mongos抛出错误并终止。

重要:通过执行指定的__exec 字符串返回的数据 不能包含任何其他扩展指令。在mongod/ mongos不返回的数据执行额外的处理,并且如果所返回的数据包括附加膨胀指令将一个错误代码终止。

3.扩展指令参考

(1).__rest

在__rest从扩展指令加载配置文件值REST的端点。__rest 支持在配置文件中加载特定值或 加载整个配置文件。mongod/ mongos然后开始使用外部来源的值作为其配置的一部分。

该__rest扩展指令的语法如下:

  • REST为特定配置文件设置或设置指定端点:

<some configuration file setting>:
  __rest: "<string>"
  type: "string"
  trim: "none|whitespace"
  digest: "<string>"
  digest_key: "<string>"
  • REST为整个配置文件指定端点:

__rest: "<string>"
type: "yaml"
trim: "none|whitespace"

如果通过REST端点指定整个配置文件,则expand指令及其选项必须是配置文件中指定的唯一值。

__rest 采用以下字段:

参考资料:https://docs.mongodb.com/master/reference/expansion-directives/

猜你喜欢

转载自www.cnblogs.com/Yongzhouunknown/p/11320343.html