Apache CouchDB 是一個開源資料庫,主要功能使用 Erlang 撰寫。 專注於易用性和成為"完全擁抱web的資料庫"。 它是一個使用 JSON 作為儲存格式,JavaScript 作為查詢語言,MapReduce 和 HTTP 作為 API 的文件導向 NoSQL 資料庫。 其中一個顯著的功能就是多主複製。Apache CouchDB 在 CAP Theorem 中屬於 Eventual Consistency 類型。
使用從 source code 編譯,下面是設定的指令(如果 JavaScript engine 想要使用 QuickJS):
./configure --spidermonkey-version 115 --js-engine=quickjs --disable-spidermonkey
而後將 rel/couchdb 目錄複製到 /opt/couchdb。
建立 couchdb 使用者。
sudo useradd -r -c 'CouchDB Administrator' -d/opt/couchdb -U -M -s/bin/bash couchdb
設定 couchdb 目錄的使用者。
sudo chown -R couchdb:couchdb /opt/couchdb
設定 couchdb 目錄的權限。
sudo find /opt/couchdb -type d -exec chmod 0770 {} \;
sudo chmod 0644 /opt/couchdb/etc/*
第一次執行
sudo -i -u couchdb /opt/couchdb/bin/couchdb
你會發現無法執行,修改 /opt/couchdb/etc/local.ini,加入 admin 帳號。
[admins]
admin = admin
再次啟動 server。如果成功,連線到 http://127.0.0.1:5984/_utils/index.html 並且使用 username = admin, password = admin 登入。 可以建立一個資料庫 my_database,然後使用 http://localhost:5984/_utils/index.html#verifyinstall 檢查目前的情況。
下面是 /opt/couchdb/etc/local.ini 關於使用者認證的部份,加入 cookie authentication 的設定。
[chttpd]
require_valid_user = true
authentication_handlers = {couch_httpd_auth, cookie_authentication_handler}, {chttpd_auth, default_authentication_handler}
[chttpd_auth]
secret = your_long_secure_shared_secret
SSL
建立 ssl.conf 設定檔
[req]
prompt = no
default_md = sha256
default_bits = 2048
distinguished_name = dn
x509_extensions = v3_req
[dn]
C = TW
ST = Taiwan
L = Taipei
O = Orange Inc.
OU = IT Department
emailAddress = admin@example.com
CN = localhost
[v3_req]
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.localhost
DNS.2 = localhost
IP.1 = 127.0.0.1
透過指令建立開發測試用途的自簽憑證
openssl req -x509 -new -nodes -sha256 -utf8 -days 3650 -newkey rsa:2048 \
-keyout couchdb.key -out couchdb.crt -config ssl.conf
將 couchdb.key 與 couchdb.crt 複製到 /opt/couchdb/etc 目錄(需要使用 su 切換到 root 身份或者使用 sudo)。
修改 /opt/couchdb/etc/local.ini
[ssl]
enable = true
port = 6984
cert_file = /opt/couchdb/etc/couchdb.crt
key_file = /opt/couchdb/etc/couchdb.key
;password = somepassword