Skip to content

Instantly share code, notes, and snippets.

@msmith
Created August 25, 2011 17:26
Show Gist options
  • Star 77 You must be signed in to star a gist
  • Fork 36 You must be signed in to fork a gist
  • Save msmith/1171217 to your computer and use it in GitHub Desktop.
Save msmith/1171217 to your computer and use it in GitHub Desktop.
Set up CouchDB on EC2
#!/bin/bash
#
# This script installs and configures couchdb on a fresh Amazon Linux AMI instance.
#
# Must be run with root privileges
# Tested with Amazon Linux AMI release 2011.02.1.1 (ami-8c1fece5)
#
export BUILD_DIR="$PWD"
# install gem dependencies
yum install gcc gcc-c++ libtool curl-devel ruby-rdoc zlib-devel openssl-devel make automake rubygems perl git-core
gem install rake --no-ri --no-rdoc
if [ ! -e "/usr/local/bin/couchdb" ]
then
if [ ! -d "$BUILD_DIR/build-couchdb" ]
then
# get build-couch code
git clone git://github.com/iriscouch/build-couchdb
cd $BUILD_DIR/build-couchdb/
git submodule init
git submodule update
fi
# run build-couch
cd $BUILD_DIR/build-couchdb/
rake git="git://git.apache.org/couchdb.git tags/1.1.0" install=/usr/local
fi
# install our .ini
cat << 'EOF' > /usr/local/etc/couchdb/local.ini
[couchdb]
delayed_commits = false
[httpd]
port = 80
bind_address = 0.0.0.0
socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]
WWW-Authenticate = Basic realm="administrator"
;WWW-Authenticate = bummer
[couch_httpd_auth]
require_valid_user = true
[log]
level = error
[admins]
EOF
# generate & set the initial password
export ADMIN_PASSWORD=`mkpasswd`
echo "admin = ${ADMIN_PASSWORD}" >> /usr/local/etc/couchdb/local.ini
# allow beam to bind to port 80 (not necessary if you make httpd.port >=1024)
setcap 'cap_net_bind_service=+ep' /usr/local/lib/erlang/erts-5.8.4/bin/beam
if [ ! -e "/etc/logrotate.d/couchdb" ]
then
# add couch.log to logrotate
ln -s /usr/local/etc/logrotate.d/couchdb /etc/logrotate.d/
# change to daily rotation
sed -e s/weekly/daily/g -i /usr/local/etc/logrotate.d/couchdb
#logrotate -v -f /etc/logrotate.d/couchdb
fi
# add couchdb user
adduser --system --home /usr/local/var/lib/couchdb -M --shell /bin/bash --comment "CouchDB" couchdb
# change file ownership
chown -R couchdb:couchdb /usr/local/etc/couchdb /usr/local/var/lib/couchdb /usr/local/var/log/couchdb /usr/local/var/run/couchdb
# run couchdb on startup
ln -s /usr/local/etc/rc.d/couchdb /etc/init.d/couchdb
chkconfig --add couchdb
chkconfig --level 345 couchdb on
# done!
echo
echo
echo "Installation complete!"
echo "Couchdb admin password was set to: ${ADMIN_PASSWORD}"
echo
echo "Couchdb is ready to start. Run:"
echo " sudo service couchdb start"
@kowsik
Copy link

kowsik commented Aug 25, 2011

This is awesome Mike! Very very handy.

@jhs
Copy link

jhs commented Feb 14, 2012

I just discovered this looking for something else. Very nice!

I am making plans for build-couchb to recommend some techniques to get things working on your distro, and then eventually just do those for you. (That is a serious tar baby but somebody's gotta do it.)

@kowsik
Copy link

kowsik commented Feb 15, 2012

Yup, we use this in http://blitz.io to spin up new instances (especially with EC2 user-data) and it's super useful.

@jeisenlo
Copy link

Ran into an error using this script to install on a fresh Amazon Linux AMI. Any help would be greatly appreciated!

/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:309: warning: initialization from incompatible pointer type
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:318: warning: initialization from incompatible pointer type
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:323: warning: initialization from incompatible pointer type
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:323: warning: excess elements in struct initializer
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:323: warning: (near initialization for ‘CouchHTTPFunctions[0]’)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:324: warning: initialization from incompatible pointer type
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:324: warning: excess elements in struct initializer
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:324: warning: (near initialization for ‘CouchHTTPFunctions[1]’)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:325: warning: initialization from incompatible pointer type
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:325: warning: excess elements in struct initializer
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:325: warning: (near initialization for ‘CouchHTTPFunctions[2]’)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:326: warning: excess elements in struct initializer
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:326: warning: (near initialization for ‘CouchHTTPFunctions[3]’)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c: In function ‘install_http’:
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/http.c:346: warning: passing argument 5 of ‘JS_InitClass’ from incompatible pointer type
/usr/local/include/js/jsapi.h:2127: note: expected ‘JSNative’ but argument is of type ‘JSBool ()(struct JSContext *, struct JSObject *, uintN, jsval *, jsval *)’
mv -f .deps/couchjs-http.Tpo .deps/couchjs-http.Po
gcc -DHAVE_CONFIG_H -I. -I/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv -I../../.. -D_XOPEN_SOURCE -L/usr/local/lib -L/usr/local/lib -L/opt/local/lib -I/usr/local/lib/erlang/usr/include -I/usr/local/include/js -DXP_UNIX -I/usr/local/include -I/usr/local/include/js -D_BSD_SOURCE -I/usr/local/include -g -O2 -MT couchjs-main.o -MD -MP -MF .deps/couchjs-main.Tpo -c -o couchjs-main.o test -f 'couch_js/main.c' || echo '/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/'couch_js/main.c
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c: In function ‘evalcx’:
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:62: warning: assignment makes pointer from integer without a cast
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c: In function ‘execute_script’:
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:215: error: ‘JSScript’ undeclared (first use in this function)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:215: error: (Each undeclared identifier is reported only once
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:215: error: for each function it appears in.)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:215: error: ‘script’ undeclared (first use in this function)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c: At top level:
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:251: warning: initialization from incompatible pointer type
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:251: warning: excess elements in struct initializer
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:251: warning: (near initialization for ‘global_functions[0]’)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:252: warning: initialization from incompatible pointer type
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:252: warning: excess elements in struct initializer
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:252: warning: (near initialization for ‘global_functions[1]’)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:253: warning: initialization from incompatible pointer type
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:253: warning: excess elements in struct initializer
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:253: warning: (near initialization for ‘global_functions[2]’)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:254: warning: initialization from incompatible pointer type
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:254: warning: excess elements in struct initializer
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:254: warning: (near initialization for ‘global_functions[3]’)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:255: warning: initialization from incompatible pointer type
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:255: warning: excess elements in struct initializer
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:255: warning: (near initialization for ‘global_functions[4]’)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:256: warning: initialization from incompatible pointer type
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:256: warning: excess elements in struct initializer
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:256: warning: (near initialization for ‘global_functions[5]’)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:257: warning: excess elements in struct initializer
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:257: warning: (near initialization for ‘global_functions[6]’)
/home/ec2-user/build-couchdb/git-build/git%3A%2F%2Fgit.apache.org%2Fcouchdb.git%3Atags%2F1.1.0/src/couchdb/priv/couch_js/main.c:266: warning: initialization from incompatible pointer type
make[4]: *
* [couchjs-main.o] Error 1
make[4]: Leaving directory /tmp/couchdb-build20120426-30815-7iwl93/src/couchdb/priv' make[3]: Leaving directory/tmp/couchdb-build20120426-30815-7iwl93/src/couchdb'
make[2]: Leaving directory /tmp/couchdb-build20120426-30815-7iwl93/src' make[1]: Leaving directory/tmp/couchdb-build20120426-30815-7iwl93'
make[3]: *** [all-recursive] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
git checkout HEAD src/couchdb/priv/couch_js/utf8.h
git ls-files --others --ignored --exclude-standard | xargs rm -vf
removed INSTALL' removedMakefile.in'
removed acinclude.m4' removedaclocal.m4'
removed bin/Makefile.in' removedconfig.h.in'
removed configure' removedetc/Makefile.in'
removed etc/couchdb/Makefile.in' removedetc/default/Makefile.in'
removed etc/init/Makefile.in' removedetc/launchd/Makefile.in'
removed etc/logrotate.d/Makefile.in' removedetc/windows/Makefile.in'
removed m4/ac_check_curl.m4' removedm4/ac_check_icu.m4'
removed m4/libtool.m4' removedm4/ltoptions.m4'
removed m4/ltsugar.m4' removedm4/ltversion.m4'
removed m4/lt~obsolete.m4' removedshare/Makefile.in'
removed src/Makefile.in' removedsrc/couchdb/Makefile.in'
removed src/couchdb/priv/Makefile.in' removedsrc/erlang-oauth/Makefile.in'
removed src/etap/Makefile.in' removedsrc/ibrowse/Makefile.in'
removed src/mochiweb/Makefile.in' removedtest/Makefile.in'
removed test/bench/Makefile.in' removedtest/etap/Makefile.in'
removed test/javascript/Makefile.in' removedtest/view_server/Makefile.in'
removed utils/Makefile.in' removedvar/Makefile.in'
rake aborted!
Command failed with status (2): [make ...]

Tasks: TOP => default => couchdb:build => couchdb:couchdb => /usr/local/bin/couchdb
(See full trace by running task with --trace)
./couchdb-ec2-install.sh: line 34: /usr/local/etc/couchdb/local.ini: No such file or directory
./couchdb-ec2-install.sh: line 55: mkpasswd: command not found
./couchdb-ec2-install.sh: line 56: /usr/local/etc/couchdb/local.ini: No such file or directory
Failed to set capabilities on file `/usr/local/lib/erlang/erts-5.8.4/bin/beam' (No such file or directory)
usage: setcap [-q] -v [ ... (-r|-|) ]

Note must be a regular (non-symlink) file.
sed: can't read /usr/local/etc/logrotate.d/couchdb: No such file or directory
chown: cannot access /usr/local/etc/couchdb': No such file or directory chown: cannot access/usr/local/var/lib/couchdb': No such file or directory
chown: cannot access `/usr/local/var/log/couchdb': No such file or directory
error reading information on service couchdb: No such file or directory
error reading information on service couchdb: No such file or directory

Installation complete!
Couchdb admin password was set to:

Couchdb is ready to start. Run:
sudo service couchdb start
[ec2-user@ip-10-28-197-254 ~]$ sudo service couchdb start
couchdb: unrecognized service

@cesine
Copy link

cesine commented Jul 3, 2012

on my instance erts is v 5.9
changed line to read:

allow beam to bind to port 80 (not necessary if you make httpd.port >=1024)

setcap 'cap_net_bind_service=+ep' /usr/local/lib/erlang/erts-5.9/bin/beam

@cesine
Copy link

cesine commented Jul 3, 2012

i also changed
rake git="git://git.apache.org/couchdb.git tags/1.2.0" install=/usr/local

After these two changes it seemed to run.

@timmeade
Copy link

Installing on AWS 64 bit linux large instance.

Made the changes in the comments above and the script ran to completion. erts was 5.9.1.3 btw.

service couchdb start and it's running as checked with ps ax

service couchdb status returns blank line.

curl http://localhost:5984/
curl: (7) couldn't connect to host

I'm wondering if it's a 64 bit issue.

@johholl
Copy link

johholl commented Mar 31, 2013

hello people,
can someone please help me.
I am new to this stuff.
What do i have to type in the terminal in order to run the *sh script.
I am struggeling even with downloading the script :-/
I build up an aws linux ec2 and have access via ssh.
Please help :-)

@dch
Copy link

dch commented May 16, 2013

Great script! Maybe consider using 1.3.0 instead, and R14B04 as your erlang release. Nice to update it a bit :-). @cesine your changes are spot on, good work!

@skynet
Copy link

skynet commented Jun 8, 2013

503 Service Temporarily Unavailable while accessing https://git-wip-us.apache.org/repos/asf/couchdb.git

@simran66
Copy link

simran66 commented Feb 3, 2018

Successfully installed rake-12.3.0
1 gem installed
./couchDBScript.sh: line 30: rake: command not found

rake not found even after installation. why is that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment