OSETC TECH

How to Install Apache CouchDB on CentOS or RHEL 6/7

This post will guide you how to install Apache CouchDB on CentOS or RHEL Linux 6/7. How do I Configure Apache CouchDB HTTP Server on your CentOS Linux system. How do I configure the admin user, create an CouchDB database on your CouchDB server in CentOS Linux. You also learn some basic usage of CouchDB through RESTful API using the Curl command utility.

What is Apache CouchDB?


CouchDB was first released in 2005 and later became an Apache Software Foundation project in 2008.

Apache CouchDB is an open source NoSQL database software, it means that it does not have any tables, rows or index, etc. And it uses JSON for data storage, JavaScript for MapReduce indexes, and regular HTTP for its API. You can also access and manage Apache CouchDB from a web browser via HTTP or API. or You can also read, create, edit and delete database documents through RESTful HTTP API.

CouchDB database management system can be work with all IT environments, distributed server clusters, the latest web browsers and mobile applications. And it is compatible with Couch Replication Protocol inlucdes PouchDB, Cloudant and Couchbase Lite.

CouchDB has a document that oriented NoSQL database architecture and is implemented in the concurrency that oriented language Erlang.

Enabling Apache CouchDB Repository


If you want to install Apache CouchDB package on your CentOS or RHEL distribution Linux, you need to install and enable EPEL (Extra Package for Enterprise Linux) repository and update your current system software packages to the latest version available. You can use the following command to do that, type:

$ sudo yum update -y
$ sudo yum install epel-release -y

Outputs:

[root@devops ~]# sudo yum update -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirror.premi.st
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
....

[root@devops ~]# sudo yum install epel-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================
Package Arch Version Repository Size
================================================================================================
Installing:
epel-release noarch 7-11 extras 15 k

Transaction Summary
================================================================================================
Install 1 Package

Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-11.noarch.rpm | 15 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : epel-release-7-11.noarch 1/1
Verifying : epel-release-7-11.noarch 1/1

Installed:
epel-release.noarch 0:7-11

Complete!

Once the EPEL repository has been installed, you can add Apache CouchDB repository to your repo file, just do the following steps:

#1 go to the /etc/yum.repos.d/ directory and create a new repo file named apache-couchdb.repo with the folllowing command:

$ sudo cd /etc/yum.repos.d
$ sudo vim apache-couchdb.repo

#2 add the following lines into the file.

[apache-couchdb-repo]
name=apache-couchdb-repo
baseurl=http://apache.bintray.com/couchdb-rpm/el$releasever/$basearch/
gpgcheck=0
repo_gpgcheck=0
enabled=1

#3 save and close the repo.
#4 checking if apache couchdb repo is added to the current repository by running the following command:

$ yum repolist

Outputs:

[devops@devops yum.repos.d]$ yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.aliyun.com
* epel: fedora.cs.nctu.edu.tw
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
apache-couchdb-repo 10/10
repo id repo name status
apache-couchdb-repo/7/x86_64 apache-couchdb-repo 10
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,019
docker-ce-stable/x86_64 Docker CE Stable - x86_64 41
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,068
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 386
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1,573
repolist: 25,097

From the above outputs, you would see that apache-couchdb-repo has been added into your current public yum repositories.

Installing Apache CouchDB


Once EPEL and Apache CouchDB repositories are enable, you can start to install the Apache CouchDB packages using the following yum command, and it will also install all dependencies on your CentOS system.

$ sudo yum install couchdb

Outputs:

[devops@devops yum.repos.d]$ sudo yum install couchdb
[sudo] password for devops:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirror.premi.st
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package couchdb.x86_64 0:2.3.1-1.el7 will be installed
--> Processing Dependency: couch-js = 1:1.8.5 for package: couchdb-2.3.1-1.el7.x86_64
--> Processing Dependency: python-requests for package: couchdb-2.3.1-1.el7.x86_64
--> Processing Dependency: python-progressbar for package: couchdb-2.3.1-1.el7.x86_64
--> Processing Dependency: libmozjs185.so.1.0()(64bit) for package: couchdb-2.3.1-1.el7.x86_64
--> Running transaction check
---> Package couch-js.x86_64 1:1.8.5-21.el7 will be installed
---> Package python-progressbar.noarch 0:2.3-4.el7 will be installed
---> Package python-requests.noarch 0:2.6.0-1.el7_1 will be installed
--> Processing Dependency: python-urllib3 >= 1.10.2-1 for package: python-requests-2.6.0-1.el7_1.noarch
--> Running transaction check
---> Package python-urllib3.noarch 0:1.10.2-5.el7 will be installed
--> Processing Dependency: python-six for package: python-urllib3-1.10.2-5.el7.noarch
--> Running transaction check
---> Package python-six.noarch 0:1.9.0-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================
Package Arch Version Repository Size
================================================================================================
Installing:
couchdb x86_64 2.3.1-1.el7 apache-couchdb-repo 19 M
Installing for dependencies:
couch-js x86_64 1:1.8.5-21.el7 apache-couchdb-repo 2.0 M
python-progressbar noarch 2.3-4.el7 epel 20 k
python-requests noarch 2.6.0-1.el7_1 base 94 k
python-six noarch 1.9.0-2.el7 base 29 k
python-urllib3 noarch 1.10.2-5.el7 base 102 k

Transaction Summary
================================================================================================
Install 1 Package (+5 Dependent packages)

Total download size: 21 M
Installed size: 48 M
Is this ok [y/d/N]: y
Downloading packages:
(1/6): python-six-1.9.0-2.el7.noarch.rpm | 29 kB 00:00:00
(2/6): python-progressbar-2.3-4.el7.noarch.rpm | 20 kB 00:00:00
(3/6): python-requests-2.6.0-1.el7_1.noarch.rpm | 94 kB 00:00:00
(4/6): python-urllib3-1.10.2-5.el7.noarch.rpm | 102 kB 00:00:00
(5/6): couch-js-1.8.5-21.el7.x86_64.rpm | 2.0 MB 00:00:03
(6/6): couchdb-2.3.1-1.el7.x86_64.rpm | 19 MB 00:00:10
------------------------------------------------------------------------------------------------
Total 2.0 MB/s | 21 MB 00:00:10
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:couch-js-1.8.5-21.el7.x86_64 1/6
Installing : python-progressbar-2.3-4.el7.noarch 2/6
Installing : python-six-1.9.0-2.el7.noarch 3/6
Installing : python-urllib3-1.10.2-5.el7.noarch 4/6
Installing : couchdb-2.3.1-1.el7.x86_64 6/6
Verifying : python-requests-2.6.0-1.el7_1.noarch 1/6
Verifying : couchdb-2.3.1-1.el7.x86_64 2/6
Verifying : python-six-1.9.0-2.el7.noarch 3/6
Verifying : python-progressbar-2.3-4.el7.noarch 4/6
Verifying : 1:couch-js-1.8.5-21.el7.x86_64 5/6
Verifying : python-urllib3-1.10.2-5.el7.noarch 6/6

Installed:
couchdb.x86_64 0:2.3.1-1.el7

Dependency Installed:
couch-js.x86_64 1:1.8.5-21.el7 python-progressbar.noarch 0:2.3-4.el7
python-requests.noarch 0:2.6.0-1.el7_1 python-six.noarch 0:1.9.0-2.el7
Complete!

After the installation of CouchDB is completed, you need to start the couchdb service and enable it to run at the system boot. Type:

$ sudo systemctl start couchdb
$ sudo systemctl enable couchdb

Outputs:

[devops@devops yum.repos.d]$ sudo systemctl start couchdb
[devops@devops yum.repos.d]$ sudo systemctl enable couchdb
Created symlink from /etc/systemd/system/multi-user.target.wants/couchdb.service to /usr/lib/systemd/system/couchdb.service.

If you want to verify if CouchDB service is running or not, just using the following command:

$ sudo systemctl status couchdb

Outputs:

[devops@devops yum.repos.d]$ sudo systemctl status couchdb
● couchdb.service - Apache CouchDB
Loaded: loaded (/usr/lib/systemd/system/couchdb.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2019-04-21 06:36:57 EDT; 1min 5s ago
Main PID: 3847 (beam.smp)
CGroup: /system.slice/couchdb.service
├─3847 /opt/couchdb/bin/../erts-8.3.5/bin/beam.smp -K true -A 16 -Bd -- -root /opt...
├─3856 /opt/couchdb/bin/../erts-8.3.5/bin/epmd -daemon
├─3874 erl_child_setup 1024
├─3879 sh -s disksup
├─3880 /opt/couchdb/bin/../lib/os_mon-2.4.2/priv/bin/memsup
└─3881 /opt/couchdb/bin/../lib/os_mon-2.4.2/priv/bin/cpu_sup
Apr 21 06:36:57 devops systemd[1]: Started Apache CouchDB

If you get the Active state from the outputs, it indicates that Apache CouchDB service has been installed and started on your CentOS or RHEL Linux server.

You can also check on which server ports the Apache CouchDB communication is established on your system. To verify this, you need to use netstat tool to check it. To use this command, you need to install net-tools package firstly, type the following command:

$ sudo yum install net-tools

Then you can run the following command to check the default service port 5984 if it is listened. type:

$ sudo netstat -plntu

Outputs:

[devops@devops yum.repos.d]$ sudo netstat -plntu
[sudo] password for devops:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:40620 0.0.0.0:* LISTEN 3847/beam.smp
tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 3856/epmd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3010/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3100/master
tcp 0 0 127.0.0.1:5984 0.0.0.0:* LISTEN 3847/beam.smp
tcp 0 0 127.0.0.1:5986 0.0.0.0:* LISTEN 3847/beam.smp
tcp6 0 0 :::80 :::* LISTEN 3004/httpd
tcp6 0 0 :::4369 :::* LISTEN 3856/epmd
tcp6 0 0 :::22 :::* LISTEN 3010/sshd
tcp6 0 0 ::1:25 :::* LISTEN 3100/master
udp 0 0 0.0.0.0:68 0.0.0.0:* 2820/dhclient
udp 0 0 0.0.0.0:35445 0.0.0.0:* 2491/avahi-daemon:
udp 0 0 0.0.0.0:5353 0.0.0.0:* 2491/avahi-daemon:

From the above outputs, you would see that the port 5984 is being listened.

Configuring Apache CouchDB


Apache CouchDB has a web-based interface called Fauxton, if you want to enable this pane for administrator access with the default server port 5984, you need to go to the Apache CouchDB installation directory /opt/couchdb/etc/, and modify its configuration file called local.ini with vi or vim text editor. Type:

$ sudo vim /opt/couchdb/etc/local.ini

Then you need to navigate to chttpd section and change the bind_address value with your server’s IP address. so you need to change the settings under chttpd section as shown below:

[chttpd]
port = 5984
bind_address = 192.168.3.22

Then you stil need to go to the end of the file to find admins section, set the admin user and its password as shown:

[admins]
admin = test123456

Save and close the file. Restart the Apache CouchDB service using the following systemctl command:

$ sudo systemctl restart couchdb.service

To verify Apache CouchDB HTTP server, you need to check if your firewall service is running or not, if it is running, you need to enable the Apache CouchDB server port in your firewall policy by executing the following command:

$ sudo firewall-cmd --add-port=5984/tcp --permanent
$ sudo firewall-cmd --reload

Then you can go to a web browser and enter the following URL to access Apache CouchDB web pane.

http://192.168.3.22:5984/_utils/

You need to enter your username and password to log in to CouchDB server. Then click Log in button.

You can also execute the following curl command to verify whether the Apache CouchDB server runs normally. type:

$ curl http://192.168.3.22:5984/

Outputs:

[devops@devops yum.repos.d]$ curl http://192.168.3.22:5984/
{"couchdb":"Welcome","version":"2.3.1","git_sha":"c298091a4","uuid":"78d6b359ff0e26c6f86b0909665fe67e","features":["pluggable-storage-engines","scheduler"],"vendor":{"name":"The Apache Software Foundation"}}
[devops@devops yum.repos.d]$

Configuring Admin Account in Apache CouchDB


Before a server admin is configured, all clients have admin privileges. This is fine when HTTP access is restricted to trusted users. If end-users will be accessing this CouchDB, you must create an admin account to prevent accidental (or malicious) data loss.

Server admins can create and destroy databases, install and update _design documents, run the test suite, and edit all aspects of CouchDB configuration.

You can add an administrator user through Apache CouchDB web Gui, click Your Account menu, and then click Create Server Admin tab, type your username and password, then click Create Admin button.

Now new admin user(osetc) for CouchDB has been created.

Creating Database in CouchDB


To create a new database in your CouchDB server, you can use Curl command with PUT subcommand and –X option. Or you can directly go to Web GUI of CouchDB to create new database.

For example, you wish to create a new database called testdb, just type:

$ curl -X PUT http://osetc:123456@192.168.3.22:5984/testdb

Outputs:

[devops@devops yum.repos.d]$ curl -X PUT http://osetc:123456@192.168.3.22:5984/testdb
{"ok":true}

From GUI:

Listing All Databases in CouchDB


If you want to list all databases in your current CouchDB server, just use curl command with GET subcommand and -X option to get it, type:

$ curl -X GET http://osetc:123456@192.168.3.22:5984/_all_dbs

Outputs:

[devops@devops yum.repos.d]$ curl -X GET http://osetc:123456@192.168.3.22:5984/_all_dbs
["mydata","testdb"]

If you want to get information about a given database that have created already in your CouchDB server, For example, get all information about testdb database, just type the following command:

$ curl -X GET http://osetc:123456@192.168.3.22:5984/testdb

Outputs:

[devops@devops yum.repos.d]$ curl -X GET http://osetc:123456@192.168.3.22:5984/testdb
{"db_name":"testdb","purge_seq":"0-g1AAAAFTeJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMeC5BkeACk_gNBViIDQbUHIGrvE6N2AUTtfmLUNkDUzsevNikBSCbVE3RrkgNIXTxhdQogdfYE1SUyJMlDFGUBAD9sXo4","update_seq":"0-g1AAAAFTeJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____sxIZ8ChKUgCSSfaE1TmA1MUTVpcAUldPUF0eC5BkaABSQKXziVG7AKJ2PzFqD0DU3idG7QOIWpB7swBegl6O","sizes":{"file":33992,"external":0,"active":0},"other":{"data_size":0},"doc_del_count":0,"doc_count":0,"disk_size":33992,"disk_format_version":7,"data_size":0,"compact_running":false,"cluster":{"q":8,"n":1,"w":1,"r":1},"instance_start_time":"0"}

Deleting Database in CouchDB


If you want to delete a database in CouchDB server, you can directory delete it from CouchDB web Gui, or you can also delete it through CURL command line tool, just use Curl command with DELETE subcommand and -x option, type:

$ curl -X DELETE http://osetc:123456@192.168.3.22:5984/testdb

Outputs:

[devops@devops yum.repos.d]$ curl -X DELETE http://osetc:123456@192.168.3.22:5984/testdb
{"ok":true}

[devops@devops yum.repos.d]$ curl -X GET http://osetc:123456@192.168.3.22:5984/_all_dbs
["mydata"]

Conclusion


You should know that how to install and Configure Apache CouchDB on your CentOS or RHEL Linux 6/7. If you want to see more information about CouchDB, you can go the official web page of Apache CouchDB directly.