使用couchdb和配置集群

Gao
### 配置docker.ini ```ini [admins] admin = <encrypted password> [chttpd] bind_address = 0.0.0.0 port = 5984 [cluster] n = 3 ``` ### 启动配置, 创建默认数据库 ```bash curl -u user:pass -XPUT localhost:5984/_users curl -u user:pass -XPUT localhost:5984/_replicator curl -u user:pass -XPUT localhost:5984/_global_changes ``` ### 集群配置 ```bash cluster_setup() { curl -X POST -u user:pass -H 'content-type: application/json' "http://${1}:5984/_cluster_setup" -d "$2" } cluster_setup 10.100.1.10 '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "cluster", "password":"connect", "port": 5984, "node_count": "3", "remote_node": "10.100.1.10:5984", "remote_current_user": "cluster", "remote_current_password": "connect" }' cluster_setup 10.100.1.10 '{"action": "add_node", "host":"10.100.21.10", "port": 5984, "username": "cluster", "password":"connect"}' cluster_setup 10.100.21.10 '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "cluster", "password":"connect", "port": 5984, "node_count": "3", "remote_node": "10.100.21.10:5984", "remote_current_user": "cluster", "remote_current_password": "connect" }' cluster_setup 10.100.21.10 '{"action": "add_node", "host":"10.100.1.10", "port": 5984, "username": "cluster", "password":"connect"}' cluster_setup 10.100.1.10 '{"action": "finish_cluster"}' cluster_setup 10.100.21.10 '{"action": "finish_cluster"}' ``` ### 检查状态 ```bash ## 检查安装 curl http://admin:password@<setup-coordination-node>:5984/_cluster_setup ## 检查成员 curl -s -u user:pass localhost:5984/_membership ``` ### 删除节点 ```bash ## 查看节点信息 curl -s -u couch:potato 10.100.21.10:5984/_node/_local/_nodes/couchdb@docker.gsmlg.net |jq ## 删除节点 curl -XDELETE -s -u couch:potato "http://10.100.21.10:5984/_node/_local/_nodes/couchdb@docker.gsmlg.net?rev=1-967a00dff5e02add41819138abb3284d" ``` # Test Performance of CouchDB 测试CouchDB写入性能, 数据为JSON文档, CouchDB文档限制最大为8MB ```bash #!/bin/bash NUM=10000 CONCURRENT=1000 TARGET="127.0.0.1:5984" DATA=$(cat <<EOF { "name": "Couch DB Test Document" } EOF ) gsmlg-cli httpbenchmark \ -c ${CONCURRENT} \ -n ${NUM} \ -m POST \ --header "Authorization:Basic <user pass encrypted>" \ -T 'application/json' \ --body="$DATA" \ "http://${TARGET}/perf" ```