CouchDB

From GeilThings

Jump to: navigation, search
CouchDB
Couchdb-logo.png
General
Version 1.2.1
Stable 1.3.1
Function Database
SQL NoSQL
Port 5984
Files
Config File /usr/local/etc/couchdb/local.ini, /usr/local/etc/couchdb/default.ini
Data File /usr/local/var/lib/couchdb/dbname.couch
Log File /usr/local/var/log/couchdb/couch.log
Scripts
Start su - couchdb -c "/usr/local/etc/rc.d/couchdb start"
Stop su - couchdb -c "/usr/local/etc/rc.d/couchdb stop"

Contents


General

CouchDB: Cluster of unreliable Commodity Hardware Database. Implemented in Erlang. Stores JSON documents.

http://couchdb.apache.org/docs/overview.html

http://www.ibm.com/developerworks/opensource/library/os-couchdb/index.html

Views: CouchDB's query tool. http://wiki.apache.org/couchdb/HTTP_view_API?action=show&redirect=HttpViewApi

CouchDB - The Definitive Guide: http://guide.couchdb.org/index.html

Permissions: http://blog.couchbase.com/whats-new-in-couchdb-1-0-part-4-securityn-stuff

Version: couchdb -V

Installation

# Following their readme file INSTALL.Unix in the root of the uncompressed file
# Following the CouchDB wiki: http://wiki.apache.org/couchdb/Installing_on_RHEL5
 
# Install required Software
yum install icu libicu-devel js-devel
 
# CouchDB 1.2.0 and up: To be able to regenerate man pages.
yum install help2man
 
# These were already installed
yum install libtool which make gcc openssl-devel
 
# Erlang was already installed (from source)
 
# Since CouchDB 1.1.0, and curl 7.15.5 in CentOS 5.6, download and install curl from source.
# CentOS 6.2 comes with curl 7.19.7. It does not work either:
# Error in configure:
# configure: error: Library requirements (curl) not met.
# Curl cannot be simply removed with yum remove curl; yum and rpm depend on curl.
 
# Install curl:
cd /opt
CURLVERSION=7.24.0
# Worked also for 7.21.7.
# Check.
curl -V
yum install libssh2-devel
wget wget http://curl.haxx.se/download/curl-${CURLVERSION}.tar.gz
tar -xzvf  curl-${CURLVERSION}.tar.gz
cd  curl-${CURLVERSION}
# For ssh support in curl, --with-libssh2.
./configure --prefix=/usr/local --with-libssh2
make
make test
make install
# Recheck.
curl -V
# It still shows curl 7.19.7, however CouchDB's configure will not fail
# with the error: Library requirements (curl) not met.
# ???
 
# Now I can install CouchDB; see under Upgrade for differences with 1.1.1.
cd /opt
wget http://mirror.softaculous.com/apache//couchdb/1.1.0/apache-couchdb-1.1.0.tar.gz
tar -zxvf apache-couchdb-1.1.0.tar.gz
cd /opt/apache-couchdb-1.1.0
./configure
make
make install
 
# Create the couchdb user:
adduser -r --home /usr/local/var/lib/couchdb -M --shell /bin/bash --comment "CouchDB Administrator" couchdb
passwd couchdb
# mycouchdbpassword
chown -R couchdb: /usr/local/var/lib/couchdb /usr/local/var/log/couchdb /usr/local/etc/couchdb/ /usr/local/var/run/couchdb/
 
# Activate logrotate. See http://wiki.apache.org/couchdb/Installing_on_Ubuntu
# Is this necessary???
ln -s /usr/local/etc/logrotate.d/couchdb /etc/logrotate.d/couchdb

Configuration

vi /usr/local/etc/couchdb/local.ini
# Modifiy and uncomment
## admin = myadminpassword
## WWW-Authenticate = Basic realm="administrator"
## require_valid_user = true
 
# Add
[stats]
rate = 300000
 
; rate in milliseconds
; CouchDB 1.1.1 comes with a runtime Statistics module
; http://wiki.apache.org/couchdb/Runtime_Statistics
; default = 1000
; rate = 1000: The process beam.smp appears on top every 3 secs or so and uses 0.3% CPU, 0.6% RAM
; rate = 300000: The process beam.smp appears on top every 30 secs or so and uses 0.3% CPU, 0.5% RAM

Running

# Interactive mode:
su - couchdb
couchdb
# Apache CouchDB 1.1.0 (LogLevel=info) is starting.
# Apache CouchDB has started. Time to relax.
# [info] [<0.31.0>] Apache CouchDB has started on http://127.0.0.1:5984/
 
# The program stays on the shell.
# Kill CouchDB:
Ctrl-C
# Daemon mode:
su - couchdb
/usr/local/etc/rc.d/couchdb start
/usr/local/etc/rc.d/couchdb stop
 
# Run as daemon on start-up:
 
ln -s /usr/local/etc/rc.d/couchdb /etc/init.d/couchdb
chkconfig --add couchdb
chkconfig --level 345 couchdb on

Data manipulation

# Using curl as cli.
 
#Without authentication. 
curl http://127.0.0.1:5984/
 
# Version.
curl -X GET http://adminuser:adminuserpassword@localhost:5984
# Response: {"couchdb":"Welcome","version":"1.1.1"}
 
# With authentication: Create database "mydatabase". 
curl -X PUT http://adminuser:adminuserpassword@localhost:5984/mydatabase
# Response: {"ok":true}
 
# List databases.
curl -X GET http://adminuser:adminuserpassword@localhost:5984/_all_dbs
# Response: ["_replicator","_users","mydatabase1"]
 
# Show database "mydatabase"
curl -X GET http://adminuser:adminuserpassword@localhost:5984/mydatabase
# Response: {"db_name":"mydatabase","doc_count":0,"doc_del_count":0,"update_seq":0,
# "purge_seq":0,"compact_running":false,"disk_size":79,"instance_start_time":"1333836475015623",
# "disk_format_version":5,"committed_update_seq":0}
 
# Delete database.
curl -X DELETE http://adminuser:adminuserpassword@127.0.0.1:5984/mydatabase
# Response: {"ok":true}
 
# Add document "helloworld_php" to database "mydatabase2".
# Create database first, otherwise error: {"error":"not_found","reason":"no_db_file"}
# "helloworld_php" is the id of the document.
curl -X PUT http://adminuser:adminuserpassword@127.0.0.1:5984/mydatabase2/helloworld_php -d \
'{"couchdbkey":"HelloWorld","language":"PHP","message_text":"Hello World from PHP and CouchDB"}'
# Response: {"ok":true,"id":"helloworld_php","rev":"1-46fffc31147af97e47aa77b8092d0c55"}
 
# Delete document.
curl -X DELETE http://adminuser:adminuserpassword@127.0.0.1:5984/mydatabase2/helloworld_php?rev=1-46fffc31147af97e47aa77b8092d0c55
# Response: {"ok":true,"id":"helloworld_php3","rev":"2-ba3e9a8598ad66765647c66d617e1d91"}
 
# List all documents in a database.
curl -X GET http://adminuser:adminuserpassword@127.0.0.1:5984/mydatabase2/_all_docs
# Response:
# {"total_rows":2,"offset":0,"rows":[
# {"id":"helloworld_php","key":"helloworld_php","value":{"rev":"1-46fffc31147af97e47aa77b8092d0c55"}},
# {"id":"helloworld_php2","key":"helloworld_php2","value":{"rev":"1-46fffc31147af97e47aa77b8092d0c55"}}
# ]}

Backup

# Backup configuration and data files.
# Configuration files: /usr/local/etc/couchdb/local.ini
# Data files: /usr/local/var/lib/couchdb/*
 
# Variables
 
APPNAME=couchdb
 
# As of CouchDB 1.1.0, CouchDB's version can be read using
RAWVERSION=`couchdb -V`
# Output Format:
# couchdb - Apache CouchDB 1.1.0
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use
# ...
 
# Get Version as Substring.
RAWVERSION=${RAWVERSION:25}
# Description of the set command: http://linux.about.com/library/cmd/blcmdln_set.htm
# Solution to split strings using bash (rjt's): http://ask.metafilter.com/80862/how-split-a-string-in-bash
set -- $RAWVERSION
OLDVERSION=$1
# Check.
echo $OLDVERSION
 
DATE=`date +%Y-%m-%d`
 
# The script breaks if variable names are not enclosed with {}
BACKUPDIR=/home/backup/${APPNAME}/${APPNAME}_${OLDVERSION}_${DATE}
 
# Create backup directory if it does not exist.
if [ ! -d "${BACKUPDIR}" ]
then
    mkdir -m 755 -p ${BACKUPDIR}
fi
 
# Backup configuration files.
cp -p /usr/local/etc/couchdb/local.ini $BACKUPDIR/local.ini
 
# Stop the server before copying the data files.
su - couchdb
/usr/local/etc/rc.d/couchdb stop
# Password will be asked.
 
# Check that the server is not running.
ps aux | grep couchdb
# No couchdb daemons should be running.
 
# Backup data files.
su - root
# Password will be asked.
 
# Recreate variables lost after user changed (root to couchdb to root).
# +++ TODO: This can be written much simpler.
APPNAME=couchdb
RAWVERSION=`couchdb -V`
RAWVERSION=${RAWVERSION:25}
set -- $RAWVERSION
OLDVERSION=$1
DATE=`date +%Y-%m-%d`
# The script breaks if variable names are not enclosed with {}
BACKUPDIR=/home/backup/${APPNAME}/${APPNAME}_${OLDVERSION}_${DATE}
 
cp -pr /usr/local/var/lib/couchdb $BACKUPDIR/

Upgrade


######### START OF EDIT #########
 
APPNAME=couchdb
# The directory where I want to download the files to be installed.
DOWNLOADDIRECTORY=/opt
# If I want to backup, set it to TRUE.
ISBACKUP=TRUE
# BACKUPROOTDIR is only relevant if ISBACKUP=TRUE
BACKUPROOTDIR=/home/backup
DATE=`date +%Y-%m-%d`
# The script breaks if variable names are not enclosed with {}
BACKUPDIR=${BACKUPROOTDIR}/${APPNAME}/${APPNAME}_${OLDVERSION}_${DATE}
 
######### END OF EDIT #########
 
RAWVERSION=`couchdb -V`
RAWVERSION=${RAWVERSION:25}
set -- $RAWVERSION
OLDVERSION=$1
echo $OLDVERSION
 
RAWNEWVERSION=`curl -sd "action=ask&query=[[CouchDB]]|%3FStable&format=json" http://www.geilthings.com/api.php`
NEWVERSION=`echo "$RAWNEWVERSION" | grep -Po '^.*?\K(?<=Stable\":\[\").*?(?=\")'`  
echo $NEWVERSION
 
if [[ ${ISBACKUP} == "TRUE" ]]; then
  BACKUPDIR=${BACKUPROOTDIR}/${APPNAME}/${APPNAME}_${OLDVERSION}_${DATE}
  # Create backup directory if it does not exist.
  if [ ! -d "${BACKUPDIR}" ]; then
    mkdir -m 755 -p ${BACKUPDIR}
  fi
  # Backup configuration files.
  cp -p /usr/local/etc/couchdb/local.ini $BACKUPDIR/local.ini
  # Stop the server before copying the data files.
  su - couchdb -c "/usr/local/etc/rc.d/couchdb stop"
  # Password will be asked.
  sleep 5
  # Check that the server is not running.
  ps aux | grep couchdb
  # No couchdb daemons should be running.
  # Backup data files.
  cp -pr /usr/local/var/lib/couchdb $BACKUPDIR/
fi
 
# Rename/Delete /usr/local/lib/couchdb/erlang to /usr/local/lib/couchdb/erlang_old, 
# see the additional notes on
# http://wiki.apache.org/couchdb/Installing_on_Ubuntu
mv /usr/local/lib/couchdb/erlang /usr/local/lib/couchdb/erlang_${OLDVERSION}
 
# Rename /usr/local/etc/couchdb to be sure that configuration files are updated.
mv /usr/local/etc/couchdb /usr/local/etc/couchdb_${OLDVERSION}
 
# Now I can install CouchDB
cd /opt
wget http://mirror.netcologne.de/apache.org/couchdb/source/${NEWVERSION}/apache-couchdb-${NEWVERSION}.tar.gz
tar -zxvf apache-couchdb-${NEWVERSION}.tar.gz
cd /opt/apache-couchdb-${NEWVERSION}
 
./configure
make
make install
 
chown -R couchdb: /usr/local/var/lib/couchdb /usr/local/var/log/couchdb /usr/local/etc/couchdb/
 
# Add all changes in the configuration file /usr/local/etc/couchdb/local.ini
 
# Run couchdb.
su - couchdb
/usr/local/etc/rc.d/couchdb start
# Password will be asked.
 
# Check that daemons are running.
ps aux | grep couchdb
 
# Check version.
couchdb -V
 
# Check the log file.
vi /usr/local/var/log/couchdb/couch.log
:q
 
# Test applications.

Cloud

CouchDB hosted on the cloud:

Name Website Wikipedia
Cloudant https://cloudant.com/ http://en.wikipedia.org/wiki/Cloudant
Couchbase http://www.couchbase.com/ http://en.wikipedia.org/wiki/Couchbase
Iris Couch http://www.iriscouch.com/

Programming


Versions

Software name Version number Version date
CouchDB 1.2.1
1.1.1
1.1.0
12 January 2013
23 December 2011
28 July 2011

Issues

CouchDB 1.3.0 does not compile with Erlang R16B

/configure fails with the message "checking Erlang version compatibility... configure: error: The installed Erlang version must be >= R13B04 (erts-5.7.4) and < R16A (erts-5.10)"

Solution: As of April 27, 2013, haven't found any.

Deprecated

CouchDB 1.2.2 does not compile with Erlang R16B

No solution found as of April 4, 2013.

etap_request.erl:26: parameterized modules are no longer supported
etap_request.erl:49: variable 'OutBody' is unbound
etap_request.erl:56: variable 'Method' is unbound
etap_request.erl:59: variable 'Url' is unbound
etap_request.erl:62: variable 'Status' is unbound
etap_request.erl:66: variable 'Status' is unbound
etap_request.erl:71: variable 'Status' is unbound
etap_request.erl:75: variable 'OutHeaders' is unbound
etap_request.erl:79: variable 'OutHeaders' is unbound
etap_request.erl:83: variable 'OutHeaders' is unbound
etap_request.erl:89: variable 'OutBody' is unbound
make[3]: *** [etap_request.beam] Error 1
make[3]: Leaving directory `/opt/apache-couchdb-1.2.2/src/etap'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/opt/apache-couchdb-1.2.2/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/opt/apache-couchdb-1.2.2'
make: *** [all] Error 2

configure: error: Your SpiderMonkey library is too new

Valid for CouchDB 1.1.1. Running ./configure without options throws the error below (CentOS 5.7), however my js installation (yum info js) is x86_64, 1.70, Release 8.el5. ???.

   Error:
   configure: error: Your SpiderMonkey library is too new.

Versions of SpiderMonkey after the js185-1.0.0 release remove the optional enforcement of preventing anonymous functions in a statement context. This will most likely break your existing JavaScript code as well as render all example code invalid. If you wish to ignore this error pass --enable-js-trunk to ./configure.

   ./configure --enable-js-trunk

couch_js/utf8.h:19:7: error: no newline at end of file

Valid for CouchDB 1.1.1 and CentOS 5.7: Running "make" throws the error:

   couch_js/utf8.h:19:7: error: no newline at end of file

Solution: Add a new line at the end of /opt/apache-couchdb-1.1.1/src/couchdb/priv/couch_js/utf8.h, see https://issues.apache.org/jira/browse/COUCHDB-1331. Update March 2012, CentOS 6.2: Still 1.1.1, however the newline error does not appear. ???

Comments

blog comments powered by Disqus