首页 > 解决方案 > 以编程方式创建 CouchDB 集群失败

问题描述

我正在尝试以编程方式设置集群。为此,我遵循了文档(此处为https://docs.couchdb.org/en/stable/setup/cluster.html#the-cluster-setup-api),并创建了一个快速的 python 脚本来为我完成它。

然后我得到以下输出:{'error': 'setup_error', 'reason': 'Cluster setup unable to sync admin passwords'}. 所以我决定尝试 Fauxton 界面(它可以工作),看看有什么问题。

对 python 脚本进行了一些更改,以完全匹配 Fauxton 发送到集群的内容......但是如果手动界面(通过 Fauxton)工作,我仍然会在复制引擎盖下发生的事情时遇到这个“无法同步”错误......这让我现在快疯了......

使用以下启动脚本:

for i in {1..3}; \
  do echo "$i"5984:5984; \
  docker run -d --rm -p "$i"5984:5984 \
    -e NODENAME=box0$i.couch -e ERL_FLAGS='-setcookie "brumbrum"' \
    -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=admin \
    --name box0$i --network couch  \
    couchdb:3.1.1; \
done

它使用 3.1.1 版本的 couchdb 启动了三个新的 docker 容器。我用来集群化的脚本可以在这里找到:https ://github.com/wasperen/couchdb_clusterify/blob/main/clusterize.py

谢谢你的帮助。但无论如何:新年快乐!

只是一步一步地按照文档进行操作,结果相同:

root@75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin@box01.couch:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"admin", "node_count":"3"}'
{"error":"bad_request","reason":"Cluster is already enabled"}
root@75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin@box01.couch:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"admin", "port": 5984, "node_count": "3", "remote_node": "box02.couch", "remote_current_user": "admin", "remote_current_password": "admin" }'
{"ok":true}
root@75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin@box01.couch:5984/_cluster_setup -d '{"action": "add_node", "host":"box02.couch", "port": 5984, "username": "admin", "password":"admin"}'
{"ok":true}
root@75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin@box01.couch:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"admin", "port": 5984, "node_count": "3", "remote_node": "box03.couch", "remote_current_user": "admin", "remote_current_password": "admin" }'
{"ok":true}
root@75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin@box01.couch:5984/_cluster_setup -d '{"action": "add_node", "host":"box03.couch", "port": 5984, "username": "admin", "password":"admin"}'
{"ok":true}
root@75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin@box01.couch:5984/_cluster_setup -d '{"action": "finish_cluster"}'
{"error":"setup_error","reason":"Cluster setup unable to sync admin passwords"}

这来自浏览器日志,使用 Fauxton 用户界面(在 box01 上):

POST http://localhost:15984//_cluster_setup
DATA {"action":"enable_cluster","username":"admin","password":"admin","bind_address":"0.0.0.0","port":5984,"node_count":3,"singlenode":false}
RESPONSE 400 {"error":"bad_request","reason":"Cluster is already enabled"}

POST http://localhost:15984//_cluster_setup
DATA {"action":"enable_cluster","username":"admin","password":"admin","bind_address":"0.0.0.0","port":5984,"node_count":3,"remote_node":"box02.couch","remote_current_user":"admin","remote_current_password":"admin"}
RESPONSE 201 {"ok":true}

POST http://localhost:15984//_cluster_setup
DATA {"action":"add_node","username":"admin","password":"admin","host":"box02.couch","port":5984,"singlenode":false}
RESPONSE 201 {"ok":true}

POST http://localhost:15984//_cluster_setup
DATA {"action":"enable_cluster","username":"admin","password":"admin","bind_address":"0.0.0.0","port":5984,"node_count":3,"remote_node":"box03.couch","remote_current_user":"admin","remote_current_password":"admin"}
RESPONSE 201 {"ok":true}

POST http://localhost:15984//_cluster_setup
DATA {"action":"add_node","username":"admin","password":"admin","host":"box03.couch","port":5984,"singlenode":false}
RESPONSE 201 {"ok":true}

POST http://localhost:15984//_cluster_setup
DATA {"action":"finish_cluster"}
RESPONSE 201 {"ok":true}

GET http://localhost:15984/_membership
RESPONSE 200 {"all_nodes":["couchdb@box01.couch","couchdb@box02.couch","couchdb@box03.couch"],"cluster_nodes":["couchdb@box01.couch","couchdb@box02.couch","couchdb@box03.couch"]}

标签: pythondockercouchdb

解决方案


我认为 CouchDB 3.x 中可能存在一个错误,在使用基本身份验证时它不接受finish_cluster操作。如果您首先通过_session端点获取会话 cookie,然后将其用于身份验证,似乎它工作得非常好。


推荐阅读