安装篇
配置couchdb源:
vi /etc/yum.repos.d/bintray-apache-couchdb-rpm.repo
[bintray--apache-couchdb-rpm] name=bintray--apache-couchdb-rpm baseurl=http://apache.bintray.com/couchdb-rpm/el$releasever/$basearch/ gpgcheck=0 repo_gpgcheck=0 enabled=1
安装依赖包:
yum -y install vim
yum -y install epel-release && yum install couchdb -y
yum -y install autoconf autoconf-archive automake curl-devel erlang-asn1 erlang-erts erlang-eunit gcc-c++ erlang-os_mon erlang-x
merl erlang-erl_interface help2man js-devel-1.8.5 libicu-devel libtool perl-Test-Harness
yum install erlang-reltool -y
#修改配置文件:
#vim /opt/couchdb/etc/default.ini
#[chttpd] #修改127.0.0.1为0.0.0.0 #bind_address = 0.0.0.0
后台启动:
nohup /opt/couchdb/bin/couchdb &
访问CouchDB的主页
[root@localhost couchdb]# curl http://192.168.2.224:5984
{"couchdb":"Welcome","version":"2.3.1","git_sha":"c298091a4","uuid":"3ca731abd9136e363249e0546ae15a13","features":["pluggable-storage-engines","scheduler"],"vendor":{"name":"The Apache Software Foundation"}}
获取创建的所有数据库的列表
[root@localhost couchdb]# curl -X GET http://192.168.2.224:5984/_all_dbs
[]
创建数据库
[root@localhost couchdb]# curl -X PUT http://192.168.2.224:5984/db1
{"ok":true}
[root@localhost couchdb]# curl -X GET http://192.168.2.224:5984/_all_dbs
["db1"]
获取数据库信息
[root@localhost couchdb]# curl -X GET http://192.168.2.224:5984/db1
{"db_name":"db1","purge_seq":"0-g1AAAAFTeJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMeC5BkeACk_gNBViIDQbUHIGrvE6N2AUTtfmLUNkDUzsevNikBSCbVE3RrkgNIXTxhdQogdfYE1SUyJMlDFGUBAD9sXo4","update_seq":"0-g1AAAAFTeJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____sxIZ8ChKUgCSSfaE1TmA1MUTVpcAUldPUF0eC5BkaABSQKXziVG7AKJ2PzFqD0DU3idG7QOIWpB7swBegl6O","sizes":{"file":33992,"external":0,"active":0},"other":{"data_size":0},"doc_del_count":0,"doc_count":0,"disk_size":33992,"disk_format_version":7,"data_size":0,"compact_running":false,"cluster":{"q":8,"n":1,"w":1,"r":1},"instance_start_time":"0"}
Futon
Futon是CouchDB的内置的基于Web的管理界面。 它提供了一个简单的图形界面,您可以使用它与CouchDB进行交互。 它是一个朴素的接口,它提供对所有CouchDB功能的完全访问。 以下是这些功能的列表 -
数据库:
- 创建数据库。
- 销毁数据库。
文件:
- 创建文档。
- 更新文档。
- 编辑文档。
- 删除文档。
启动Futon
确保CouchDB正在运行,然后在浏览器中打开以下网址:http://192.168.2.224:5984/_utils/
集群篇
再找一台服务器安装同上,然后两台都执行下面操作:
vim /opt/couchdb/etc/local.ini
[chttpd] bind_address = 0.0.0.0 [admins] admin = password # 用户名和密码
注意:所有的集群节点设置为相同的用户名和密码。
vim /opt/couchdb/etc/vm.args
#假设本节点的ip为192.168.199.236,则修改为: -name [email protected]
vim /opt/couchdb/releases/2.3.1/sys.config
[ {lager, [ {error_logger_hwm, 1000}, {error_logger_redirect, true}, {handlers, [ {lager_console_backend, [debug, { lager_default_formatter, [ date, " ", time, " [", severity, "] ", node, " ", pid, " ", message, "\n" ] }]} ]}, {inet_dist_listen_min, 9100}, {inet_dist_listen_max, 9200} ]} ].
在192.168.2.224节点上添加192.168.2.238节点:
[root@localhost ~]# curl -X POST -H "Content-Type: application/json" http://admin:[email protected]:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"123456", "port": 5984, "remote_node": "192.168.2.238", "remote_current_user": "admin", "remote_current_password": "123456" }'
{"ok":true}
[root@localhost ~]# curl -X POST -H "Content-Type: application/json" http://admin:[email protected]:5984/_cluster_setup -d '{"action": "add_node", "host":"192.168.2.238", "port": "5984", "username": "admin", "password":"123456"}'
{"ok":true}
#{"error":"conflict","reason":"Document update conflict."}
[root@localhost ~]# curl -X POST -H "Content-Type: application/json" http://admin:[email protected]:5984/_cluster_setup -d '{"action": "finish_cluster"}'
{"ok":true}
#{"error":"setup_error","reason":"Cluster setup timed out waiting for nodes to connect"}
浏览器访问http:// 192.168.2.224:5984/_membership时能看到如下返回的数据:
{"all_nodes":["[email protected]","[email protected]"],"cluster_nodes":["[email protected]","[email protected]"]}
这表示集群搭建成功。或如果在192.168.2.224上的couchdb中添加一个数据库表,如果能在192.168.2.238上的couchdb中看到,表示安装成功。