Skip to content

Instantly share code, notes, and snippets.

@msmith
Created August 25, 2011 17:26
Show Gist options
  • 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"
@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