Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CouchDB 2.* on Ubuntu 16.04
# See also: http://docs.couchdb.org/en/latest/cluster/index.html
# Before you can add nodes to form a cluster, you have to have them listen on a public ip address
# and set up an admin user (use same admin:password for all nodes).
# Do this, once per node:
# If you have installed couchdb in /opt (else change the Path)
cd /opt/couchdb/etc
cp local.ini local.ini.orig
cp vm.args vm.args.orig
nano local.ini
# Make the following changes to local.ini
# Choose one of the ports for each node: 15984 or 25984 or 35984
# --- local.ini ---
[chttpd]
bind_address = 0.0.0.0
port = 15984
[admins]
admin = password
# --- end local.ini ---
nano vm.args
# Change the line -name couchdb: use the relevant individual IP address of CouchDB node
# Let all user names be the same e.g.: couchdb (actually I am not sure about this, perhaps they may have different names)
# --- vm.args ---
-name couchdb@<your-ip-address>
# --- end ---
# Restart couchdb: Refer to the install file below
service couchdb stop
service couchdb start
# Now follow: http://docs.couchdb.org/en/latest/cluster/setup.html#the-cluster-setup-api
# See also: http://docs.couchdb.org/en/latest/cluster/nodes.html
# Note here: to delete a doc you need the revision number of the document, thus
#
# curl -X GET "http://admin:password@localhost:5986/_nodes/_all_docs"
#
# That returns something like: {...{"id":"couchdb@<one_of_your-ip-addresses>","key":"couchdb@<one_of_your-ip-addresses>","value":{"rev":"1-967a00dff5e02add41819138abb3284d"}}
#
# curl -X DELETE "http://admin:password@localhost:5986/_nodes/couchdb@<one_of_your-ip-addresses>?rev=1-967a00dff5e02add41819138abb3284d" -d {}
# When this works you can setup load balancer and SSL
# There is now a much easier way to install couchdb on Ubuntu 16.04 than using the below, just use the pre-packaged apt packages, refer to the official couchdb for how to install. Hints and configuration in this gist is still relevant though.
# Installed and tested on updated Ubuntu 16.04 Desktop and on updated server
# CouchDB 2.0 version: "Commits on Dec 20, 2016" on https://github.com/apache/couchdb
# Cluster i.e. more than one CouchDB node (server, instance): Install CouchDB on each node
# Warning: run all the below as sudo or as root (I may not have written sudo everywhere needed)
## *** Ensure nodejs and npm are installed. These are used for Fauxton ***
# Possibly update these
# run this command and if it says “install” in the right column - “node” is on your system:
sudo pkg --get-selections | grep node
# to remove eventual old node package, run:
sudo apt-get remove --purge nodejs npm
# https://github.com/nodesource/distributions#debinstall
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
# This installs both npm and nodejs (node), and creates symbolic link from node to nodejs
sudo apt-get install nodejs
# check versions of nodejs and npm
nodejs -v
which nodejs
npm -v
which npm
# Possibly install to ensure updated versions: for Fauxton
sudo npm install graceful-fs minimatch uuid coffee-script jshint node-gyp node-ninja tough-cookie babel-cli -g
# *** Refer to: ***
# http://docs.couchdb.org/en/latest/install/unix.html
# https://github.com/apache/couchdb/blob/master/INSTALL.Unix.md
sudo apt-get update
sudo apt-get -y install build-essential pkg-config erlang libicu-dev libmozjs185-dev libcurl4-openssl-dev rebar
# Remove old files (assumed in /usr/local/src), if any
cd /usr/local/src
rm -fR couchdb
# get latest version of couchdb
git clone https://github.com/apache/couchdb.git
cd couchdb
# For all configuration options.
./configure --help
# If help2man, python and python sphinx are not installed then disable documentation build
# configure takes a while but when final ends with the text: "You have configured Apache CouchDB, time to relax. Relax."
./configure --disable-docs
# First try: make release
# If problems e.g. try the below, and then again: make release
touch THANKS
touch /usr/lib/erlang/man/man1/x86_64-linux-gnu-gcov-tool.1.gz
touch /usr/lib/erlang/man/man1/gcov-tool.1.gz
# This takes a while, please be patient. This ends with text:
# "You can now copy the rel/couchdb directory anywhere on your system.
# Start CouchDB with ./bin/couchdb from within that directory."
# If problems see above, and also: http://docs.couchdb.org/en/latest/install/troubleshooting.html
make release
# *** user-registration-and-security ***
adduser --disabled-login --disabled-password --no-create-home --gecos "" couchdb
# Copy the built couchdb release to /opt
# Note: if you prefer another couchdb install location than /opt then that is fine, just adjust where relevant below
cp -R /usr/local/src/couchdb/rel/couchdb /opt
chown -R couchdb:couchdb /opt/couchdb
# Change the permission of the CouchDB directories by running
find /opt/couchdb -type d -exec chmod 0770 {} \;
# Update the permissions for your .ini files => 640 => -rw-r-----
chmod 640 /opt/couchdb/etc/*
# *** You can start the CouchDB server by running ***
# Note: Ctrl-C to stop the couchdb
# Warning: After a short trial run stop couchdb and ensure that couchdb runs as: user couchdb, when doing setup, whether single-node or cluster
cd /opt/couchdb/bin
./couchdb
# Also be sure that couchdb can run by User couchdb
# If not, e.g., make sure all files in /opt/couchdb belong to couchdb:couchdb i.e. => chown -R couchdb:couchdb /opt/couchdb
sudo -i -u couchdb /opt/couchdb/bin/couchdb
# Try the installation
#
# Ubuntu server: use curl through another terminal window to the server: curl http://localhost:5984
#
# Ubuntu Desktop: directly in browser on the Desktop:
# http://127.0.0.1:5984/_utils/index.html
# http://localhost:5984/_utils/index.html#verifyinstall
# *** setup the system via Fauxton: single-node or cluster
# See also: http://docs.couchdb.org/en/latest/cluster/index.html
# Cluster setup can be quite teasing, but does not have to be, I will give a few hints in this Gist
# *** systemd startup script ***
# Alternative: runit startup script, see: http://docs.couchdb.org/en/latest/install/unix.html#running-as-a-daemon
# From: https://wiki.ubuntu.com/systemd
# This results in systemd being installed alongside upstart
apt-get -y install systemd libpam-systemd systemd-ui
# From: https://www.jamescoyle.net/how-to/2527-add-systemd-startup-script-for-couchdb ([Install] section is missing!)
# couchdb.service is a new file. Make it:
nano /lib/systemd/system/couchdb.service
--- file start (do not include this line) ---
[Unit]
Description=Couchdb service
After=network.target
[Service]
Type=simple
User=couchdb
ExecStart=/opt/couchdb/bin/couchdb -o /dev/stdout -e /dev/stderr
Restart=always
[Install]
WantedBy=multi-user.target
--- file end (do not include this line) ---
# This enables CouchDB automatically after reboot
systemctl daemon-reload
systemctl start couchdb.service
systemctl enable couchdb.service
systemctl status couchdb.service
# Also check that not much memory and cpu is used, an empty couchdb consumes in the range of 25 MB of memory
ps aux
# Logging: see more about journalctl elsewhere. This shows the latest 500 logs.
journalctl -u couchdb.service | tail -n 500
# *** update the configuration file, see above example of a configuration of local.ini ***
service couchdb stop
# update local.ini
service couchdb start
# Final note: If you run into a lot of trouble, you may want to start over again, simply delete the couchdb installation
# and make a new a copy, this only takes a few minutes. To delete do:
# To delete couchdb
systemctl stop couchdb.service
sudo apt-get remove couchdb
sudo apt-get purge couchdb
cd /opt
rm -fR couchdb
ls
# Then start from here again, see above: cp -R /usr/local/src/couchdb/rel/couchdb /opt
; Update to the below text: There are now also configuration files in /opt/couchdb/etc/default.d and in /opt/couchdb/etc/local.d
; Thus there are the two mentioned configuration folders plus the default.ini and local.ini files placed in /opt/couchdb/etc/ folder.
; (a) Update the file: /opt/couchdb/etc/local.ini (or where it is placed on your installation of choice, here it is /opt)
; $ cp local.ini local.ini.orig" make the changes to the local.ini (copy) file
;
; (b) Remember to restart couchdb after changing the configuration file (unless it is done automatically via Fauxton):
; $ service couchdb stop
; $ service couchdb start
; (c) The below configuration is good for e.g. going through nginx load balancer with ssl
; (d) It also works with: https://github.com/nolanlawson/pouchdb-authentication
; To use couchdb
; $ curl http://your_admin_username:your_admin_password@localhost:5984/_utils
; CouchDB Configuration Settings
; Custom settings should be made in this file. They will override settings
; in default.ini, but unlike changes made to default.ini, this file won't be
; overwritten on server upgrade.
[couchdb]
max_dbs_open = 1024
; WARNING: use your own uuid number from the default local.ini (not this one!!!)
uuid = d8d71e73f8fe69c821b848d5f4c685af
;[couch_peruser]
;enable = true
[chttpd]
; Single-node: use e.g. 5984
; Cluster: use e.g. 15984 for the first node, 25984 for the second node, 35984 for the third node
port = 5984
; IMPORTANT: bind_address settings see: http://docs.couchdb.org/en/latest/config/http.html
bind_address = 0.0.0.0
server_options = [{backlog, 128}, {acceptor_pool_size, 16}]
socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]
[httpd]
WWW-Authenticate = Basic realm="administrator"
server_options = [{backlog, 128}, {acceptor_pool_size, 16}]
socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]
enable_cors = true
; 3 minutes = 3 * 60 * 1000 = 180000
changes_timeout = 180000
x_forwarded_host = X-Forwarded-Host
x_forwarded_proto = X-Forwarded-Proto
x_forwarded_ssl = X-Forwarded-Ssl
[log]
;level = debug
writer = stderr
level = warning
[couch_httpd_auth]
require_valid_user = true
; WARNING: use your own secret number from the default local.ini (not this one!!!)
secret = f52f991eb7dd2033544cd8a9cc9e58e1
allow_persistent_cookies = true
; 14 days = 14 * 24 * 60 * 60 = 1209600 seconds
timeout = 1209600
auth_cache_size = 1000
[admins]
; WARNING: UPDATE THIS!!!
; Cluster: use the same admin user and password on all Cluster nodes
admin1 = mysecretpassword1
admin2 = mysecretpassword2
[replicator]
; adjust this to your situation
; 3 minutes = 3 * 60 * 1000 = 180000
connection_timeout = 180000
use_checkpoints = true
worker_batch_size = 2000
[compactions]
_default = [{db_fragmentation,"70%"},{view_fragmentation,"60%"},{from,"00:00"},{to,"06:00"}]
[cors]
; See also https://github.com/pouchdb/add-cors-to-couchdb
; Note: the Fauxton cors settings are slightly different
origins = *
credentials = true
headers = accept, authorization, content-type, origin, cookie, referer, x-csrf-token
methods = GET, OPTIONS, HEAD, PUT, POST, DELETE, TRACE
(1) Install couchdb (as explained in this Gist)
(2) Configure couchdb (as explained in this Gist)
(3) Follow: http://docs.couchdb.org/en/latest/install/setup.html#single-node-setup
(4) From within the single-node instance (use a Linux terminal) do:
curl -X PUT http://admin:password@127.0.0.1:5984/_users
curl -X PUT http://admin:password@127.0.0.1:5984/_replicator
curl -X PUT http://admin:password@127.0.0.1:5984/_global_changes
That should be it!
@peanutpi

This comment has been minimized.

Copy link

peanutpi commented Feb 3, 2017

After installing using your script I am having some issue, my couchdb instance in not running

following is the error.

Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [error] 2017-02-03T16:55:30.432974Z couchdb@localhost <0.250.0> -------- CRASH REPORT Process  (<0.250.0>) with 1 neighbors exited with reason: no match of right hand value {error,eacces} at couch_file:init/1(line:384) <= gen_server:init_it/6(line:328) <= proc_lib:init_p_do_apply/3(line:240) at gen_server:init_it/6(line:352) <= proc_lib:init_p_do_apply/3(line:240); initial_call: {couch_file,init,['Argument__1']}, ancestors: [<0.249.0>], messages: [], links: [#Port<0.4013>,<0.249.0>], dictionary: [], trap_exit: false, status: running, heap_size: 610, stack_size: 27, reductions: 508
Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [info] 2017-02-03T16:55:30.439016Z couchdb@localhost <0.209.0> -------- db _users died with reason {{badmatch,{error,eacces}},[{couch_file,init,1,[{file,"src/couch_file.erl"},{line,384}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,328}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]}
Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [error] 2017-02-03T16:55:30.440295Z couchdb@localhost <0.251.0> -------- Could not open file ./data/_users.couch: permission denied
Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [info] 2017-02-03T16:55:30.440380Z couchdb@localhost <0.209.0> -------- open_result error {error,eacces} for _users
Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [error] 2017-02-03T16:55:30.440952Z couchdb@localhost <0.246.0> -------- CRASH REPORT Process  (<0.246.0>) with 1 neighbors exited with reason: no match of right hand value {error,eacces} at couch_auth_cache:ensure_users_db_exists/2(line:456) <= couch_auth_cache:open_auth_db/0(line:428) <= couch_auth_cache:reinit_cache/1(line:290) <= couch_auth_cache:init/1(line:166) <= gen_server:init_it/6(line:328) <= proc_lib:init_p_do_apply/3(line:240) at gen_server:init_it/6(line:352) <= proc_lib:init_p_do_apply/3(line:240); initial_call: {couch_auth_cache,init,['Argument__1']}, ancestors: [couch_secondary_services,couch_sup,<0.203.0>], messages: [], links: [<0.212.0>,<0.248.0>], dictionary: [], trap_exit: true, status: running, heap_size: 987, stack_size: 27, reductions: 376
Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [error] 2017-02-03T16:55:30.443040Z couchdb@localhost <0.203.0> -------- Error starting Apache CouchDB:
Feb 03 16:55:30 hisab-couchdb couchdb[2003]:     {error,{shutdown,{failed_to_start_child,couch_secondary_services,{shutdown,{failed_to_start_child,auth_cache,{{badmatch,{error,eacces}},[{couch_auth_cache,ensure_users_db_exists,2,[{file,"src/couch_auth_cache.erl"},{line,456}]},{couch_auth_cache,open_auth_db,0,[{file,"src/couch_auth_cache.erl"},{line,428}]},{couch_auth_cache,reinit_cache,1,[{file,"src/couch_auth_cache.erl"},{line,290}]},{couch_auth_cache,init,1,[{file,"src/couch_auth_cache.erl"},{line,166}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,328}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]}}}}}}
Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [error] 2017-02-03T16:55:30.445063Z couchdb@localhost <0.212.0> -------- Supervisor couch_secondary_services had child auth_cache started with couch_auth_cache:start_link() at undefined exit with reason no match of right hand value {error,eacces} at couch_auth_cache:ensure_users_db_exists/2(line:456) <= couch_auth_cache:open_auth_db/0(line:428) <= couch_auth_cache:reinit_cache/1(line:290) <= couch_auth_cache:init/1(line:166) <= gen_server:init_it/6(line:328) <= proc_lib:init_p_do_apply/3(line:240) in context start_error
Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [error] 2017-02-03T16:55:30.446328Z couchdb@localhost <0.204.0> -------- Supervisor couch_sup had child couch_secondary_services started with couch_secondary_sup:start_link() at undefined exit with reason {shutdown,{failed_to_start_child,auth_cache,{{badmatch,{error,eacces}},[{couch_auth_cache,ensure_users_db_exists,2,[{file,"src/couch_auth_cache.erl"},{line,456}]},{couch_auth_cache,open_auth_db,0,[{file,"src/couch_auth_cache.erl"},{line,428}]},{couch_auth_cache,reinit_cache,1,[{file,"src/couch_auth_cache.erl"},{line,290}]},{couch_auth_cache,init,1,[{file,"src/couch_auth_cache.erl"},{line,166}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,328}]},{proc_lib,init_p_do_apply,3,[{file,"p..."},...]}]}}} in context start_error
Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [error] 2017-02-03T16:55:30.446614Z couchdb@localhost <0.202.0> -------- CRASH REPORT Process  (<0.202.0>) with 0 neighbors exited with reason: {{shutdown,{failed_to_start_child,couch_secondary_services,{shutdown,{failed_to_start_child,auth_cache,{{badmatch,{error,eacces}},[{couch_auth_cache,ensure_users_db_exists,2,[{file,"src/couch_auth_cache.erl"},{line,456}]},{couch_auth_cache,open_auth_db,0,[{file,"src/couch_auth_cache.erl"},{line,428}]},{couch_auth_cache,reinit_cache,1,[{file,"src/couch_auth_cache.erl"},{line,290}]},{couch_auth_cache,init,1,[{file,"src/couch_auth_cache.erl"},{line,166}]},{gen_server,init_it,6,[{file,"gen_ser..."},...]},...]}}}}},...} at application_master:init/4(line:134) <= proc_lib:init_p_do_apply/3(line:240); initial_call: {application_master,init,['Argument__1','Argument__2',...]}, ancestors: [<0.201.0>], messages: [{'EXIT',<0.203.0>,normal}], links: [<0.201.0>,<0.7.0>], dictionary: [], trap_exit: true, status: running, heap_size: 987, stack_size: 27, reductions: 152
Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [info] 2017-02-03T16:55:30.446851Z couchdb@localhost <0.7.0> -------- Application couch exited with reason: {{shutdown,{failed_to_start_child,couch_secondary_services,{shutdown,{failed_to_start_child,auth_cache,{{badmatch,{error,eacces}},[{couch_auth_cache,ensure_users_db_exists,2,[{file,"src/couch_auth_cache.erl"},{line,456}]},{couch_auth_cache,open_auth_db,0,[{file,"src/couch_auth_cache.erl"},{line,428}]},{couch_auth_cache,reinit_cache,1,[{file,"src/couch_auth_cache.erl"},{line,290}]},{couch_auth_cache,init,1,[{file,"src/couch_auth_cache.erl"},{line,166}]},{gen_server,init_it,6,[{file,"gen_ser..."},...]},...]}}}}},...}
Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [os_mon] memory supervisor port (memsup): Erlang has closed
Feb 03 16:55:30 hisab-couchdb couchdb[2003]: [os_mon] cpu supervisor port (cpu_sup): Erlang has closed

Can you help me ?

@peanutpi

This comment has been minimized.

Copy link

peanutpi commented Feb 6, 2017

Found the issue, CouchDB was not starting because for user CouchDB home directory is specified i.e. /home/couchdb which was not created.

I don't know how to remove that. so I've created a new home directory with permissions to couchdb user.

/opt/couchdb/bin/../erts-7.3/bin/beam.smp -K true -A 16 -Bd -- -root /opt/couchdb/bin/.. -progname couchdb -- -home /home/couchdb ...

P.S. Sorry the issue was CouchDB user doesn't have the correct permission to the data directory.

@SinanGabel

This comment has been minimized.

Copy link
Owner Author

SinanGabel commented Feb 15, 2017

@peanutpi
It is fine to start couchdb with a home directory but it is not required (but of course depends on your specific installation).

@sendittokeith

This comment has been minimized.

Copy link

sendittokeith commented Jul 1, 2017

Very straight forward and helpful. Thank you for providing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.