Monday, March 26, 2012

CouchDB on RHEL6 (Red Hat Enterprise Linux)


Had to install a Couch DB instance on a fresh Red Hat Enterprise 6 Linux Box and it required some time before I got the whole thing up. Better have it documented here for future reference:


1. Get the Prerequisites
First you will have to add the RPM Forge YUM Repository if not already available. Add the new repo:

sudo vi /etc/yum.repos.d/rpmforge.repo


# Name: RPMforge RPM Repository for Red Hat Enterprise 6 - dag
# URL: http://rpmforge.net/
# (Put "x86_64" instead of "i386" if appropriate.)
[rpmforge]
name = Red Hat Enterprise $releasever - RPMforge.net - dag
baseurl = ftp://ftp.pbone.net/mirror/atrpms.net/el6-i386/atrpms/stable
enabled = 1
protect = 0
gpgcheck = 0

Save the file and get the prerequisites:

sudo yum clean all
sudo yum groupinstall 'Development Tools' 'Development Libraries' 'GNOME Software Development'
sudo yum install \
  cvs zip gcc-c++ glib2-devel gtk2-devel fontconfig-devel libnotify-devel \
  libIDL-devel alsa-lib-devel libXt-devel freetype-devel pkgconfig \
  dbus-glib-devel curl-devel autoconf213 xorg-x11-proto-devel libX11-devel \
  libXau-devel libXext-devel wireless-tools-devel glibc-static libstdc++-static \
  yasm mesa-libGL-devel esound-libs esound-devel ccache mercurial glibc-devel \
  ncurses-devel openssl-devel libicu-devel erlang js-devel libtool which make

If Mercurial is not found, you can install a RPM package from RPMForge using the below commands
(replace VERSION with your version/architecture):

sudo wget http://packages.sw.be/mercurial/mercurial-VERSION.rpm
sudo rpm -Uhv mercurial-VERSION.rpm

If curl was not found, install from sources

sudo wget http://curl.haxx.se/download/curl-7.20.1.tar.gz
sudo tar -xzf curl-7.20.1.tar.gz
cd curl-7.20.1
sudo ./configure --prefix=/usr/local
sudo make
sudo make test
sudo make install

If Erlang was not found, download, build and install Erlang:
sudo wget http://erlang.org/download/otp_src_R14B03.tar.gz
sudo tar zxvf otp_src_R14B03.tar.gz
sudo cd otp_src_R14B03
sudo ./configure && sudo make && sudo make install

If js-dev (SpiderMonkey) was not found, build from the source files
sudo mkdir mozilla
sudo cd mozilla
sudo wget http://ftp.mozilla.org/pub/mozilla.org/js/js185-1.0.0.tar.gz
sudo tar xzf js185-1.0.0.tar.gz
cd js/src
sudo autoconf-2.13
sudo ./configure
sudo make
sudo make install

2. Install CouchDB
Now you are ready to install CouchDB from sources. The configure line below is for 64-bit, adjust for your arch (or leave out --with-erlang if configure can find out for itself). You can use a release tarball instead of a checkout, in that case skip right to the ./confgure line.

sudo svn checkout http://svn.apache.org/repos/asf/couchdb/trunk couchdb
cd couchdb
sudo ./bootstrap
sudo ./configure --with-erlang=/usr/lib64/erlang/usr/include --with-js-lib=/usr/local/lib/ --with-js-include=/usr/local/include/js/
sudo make
sudo make install

3. Configure CouchDB
a. Edit config file to your need, change the port etc
sudo vi /usr/local/etc/couchdb/local.ini

b. Create user, modify ownership and permissions
sudo groupadd -r couchdb
sudo adduser -r -d /usr/local/var/lib/couchdb -M \
  -s /bin/bash -g couchdb couchdb

c. fix permission
sudo chown -R couchdb: /usr/local/var/lib/couchdb /usr/local/var/log/couchdb

4. Launch CouchDB


sudo -u couchdb couchdb

Or as daemon:
sudo /usr/local/etc/rc.d/couchdb start

Or at startup as a daemon:
sudo ln -s /usr/local/etc/rc.d/couchdb /etc/init.d/couchdb
sudo chkconfig --add couchdb
sudo chkconfig --level 345 couchdb on

5. Test Install:

Now you should see something meaningful when you click
http://127.0.0.1:5984/_utils/index.html