1.2.24. 配置

CouchDB 服务器配置 API 提供了一个接口,用于查询和更新正在运行的 CouchDB 实例中的各种配置值。

1.2.24.1. 访问本地节点的配置

文字字符串 _local 用作本地节点名称的别名,因此对于所有配置 URL,{node-name} 可以替换为 _local,以与本地节点的配置进行交互。

1.2.24.2. /_node/{node-name}/_config

GET /_node/{node-name}/_config

将整个 CouchDB 服务器配置作为 JSON 结构返回。该结构按不同的配置部分组织,并包含各个值。

请求头:
  • Accept

    • application/json

    • text/plain

响应头:
  • Content-Type

    • application/json

    • text/plain; charset=utf-8

状态码:

请求

GET /_node/nonode@nohost/_config HTTP/1.1
Accept: application/json
Host: localhost:5984

响应:

HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 4148
Content-Type: application/json
Date: Sat, 10 Aug 2013 12:01:42 GMT
Server: CouchDB (Erlang/OTP)

{
    "attachments": {
        "compressible_types": "text/*, application/javascript, application/json,  application/xml",
        "compression_level": "8"
    },
    "couchdb": {
        "users_db_suffix": "_users",
        "database_dir": "/var/lib/couchdb",
        "max_attachment_chunk_size": "4294967296",
        "max_dbs_open": "100",
        "os_process_timeout": "5000",
        "uri_file": "/var/lib/couchdb/couch.uri",
        "util_driver_dir": "/usr/lib64/couchdb/erlang/lib/couch-1.5.0/priv/lib",
        "view_index_dir": "/var/lib/couchdb"
    },
    "chttpd": {
        "allow_jsonp": "false",
        "backlog": "512",
        "bind_address": "0.0.0.0",
        "port": "5984",
        "require_valid_user": "false",
        "socket_options": "[{sndbuf, 262144}, {nodelay, true}]",
        "server_options": "[{recbuf, undefined}]",
        "secure_rewrites": "true"
    },
    "httpd": {
        "authentication_handlers": "{couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}",
        "bind_address": "192.168.0.2",
        "max_connections": "2048",
        "port": "5984",
    },
    "log": {
        "writer": "file",
        "file": "/var/log/couchdb/couch.log",
        "include_sasl": "true",
        "level": "info"
    },
    "query_server_config": {
        "reduce_limit": "true"
    },
    "replicator": {
        "max_http_pipeline_size": "10",
        "max_http_sessions": "10"
    },
    "stats": {
        "interval": "10"
    },
    "uuids": {
        "algorithm": "utc_random"
    }
}

1.2.24.3. /_node/{node-name}/_config/{section}

GET /_node/{node-name}/_config/{section}

获取单个部分的配置结构。

参数:
  • section – 配置部分名称

请求头:
  • Accept

    • application/json

    • text/plain

响应头:
  • Content-Type

    • application/json

    • text/plain; charset=utf-8

状态码:

请求:

GET /_node/nonode@nohost/_config/httpd HTTP/1.1
Accept: application/json
Host: localhost:5984

响应:

HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 444
Content-Type: application/json
Date: Sat, 10 Aug 2013 12:10:40 GMT
Server: CouchDB (Erlang/OTP)

{
    "authentication_handlers": "{couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}",
    "bind_address": "127.0.0.1",
    "default_handler": "{couch_httpd_db, handle_request}",
    "port": "5984"
}

1.2.24.4. /_node/{node-name}/_config/{section}/{key}

GET /_node/{node-name}/_config/{section}/{key}

从特定配置部分中获取单个配置值。

参数:
  • section – 配置部分名称

  • key – 配置选项名称

请求头:
  • Accept

    • application/json

    • text/plain

响应头:
  • Content-Type

    • application/json

    • text/plain; charset=utf-8

状态码:

请求:

GET /_node/nonode@nohost/_config/log/level HTTP/1.1
Accept: application/json
Host: localhost:5984

响应:

HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 8
Content-Type: application/json
Date: Sat, 10 Aug 2013 12:12:59 GMT
Server: CouchDB (Erlang/OTP)

"debug"

注意

返回值将是值的 JSON,它可能是字符串或数字值,或者数组或对象。某些客户端环境可能不会将简单的字符串或数字值解析为有效的 JSON。

PUT /_node/{node-name}/_config/{section}/{key}

更新配置值。新值应以相应的 JSON 格式在请求正文中提供。如果要设置字符串值,则必须提供有效的 JSON 字符串。响应中,CouchDB 会发送目标部分键的旧值。

参数:
  • section – 配置部分名称

  • key – 配置选项名称

请求头:
响应头:
  • Content-Type

    • application/json

    • text/plain; charset=utf-8

状态码:

请求:

PUT /_node/nonode@nohost/_config/log/level HTTP/1.1
Accept: application/json
Content-Length: 7
Content-Type: application/json
Host: localhost:5984

"info"

响应:

HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 8
Content-Type: application/json
Date: Sat, 10 Aug 2013 12:12:59 GMT
Server: CouchDB (Erlang/OTP)

"debug"
DELETE /_node/{node-name}/_config/{section}/{key}

删除配置值。返回的 JSON 将是配置参数在删除之前的值。

参数:
  • section – 配置部分名称

  • key – 配置选项名称

请求头:
  • Accept

    • application/json

    • text/plain

响应头:
  • Content-Type

    • application/json

    • text/plain; charset=utf-8

状态码:

请求:

DELETE /_node/nonode@nohost/_config/log/level HTTP/1.1
Accept: application/json
Host: localhost:5984

响应:

HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 7
Content-Type: application/json
Date: Sat, 10 Aug 2013 12:29:03 GMT
Server: CouchDB (Erlang/OTP)

"info"

1.2.24.5. /_node/{node-name}/_config/_reload

版本 3.0 中的新增功能。

POST /_node/{node-name}/_config/_reload

从磁盘重新加载配置。这会产生副作用,即刷新任何尚未提交到磁盘的内存中配置更改。

请求:

POST /_node/nonode@nohost/_config/_reload HTTP/1.1
Host: localhost:5984

响应:

HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 12
Content-Type: application/json
Date: Tues, 21 Jan 2020 11:09:35
Server: CouchDB/3.0.0 (Erlang OTP)

{"ok":true}