How to Install Apache CouchDB on CentOS 7
Apache CouchDB is an open source NoSQL database software that's focused on scalable architecture. CouchDB was released in 2005, and become an Apache Software Foundation project in 2008. Apache CouchDB is a document-oriented NoSQL database. Each database is a collection of independent documents, and does not store data and relationships in tables.
In this tutorial, we will discuss step-by-step installation and configuration of Apache CouchDB on a CentOS 7 server. We will learn in detail how to install the CouchDB server, configure the admin user, enable the Apache CouchDB HTTP server, as well as learn some basic usage of CouchDB through API using the curl command utility.
- CentOS 7 server
- Root privileges
What we will do
- Install EPEL repository
- Install Apache CouchDB
- Enable Apache CouchDB HTTP server
- Configure Admin Account CouchDB
- Basic Usage Apache CouchDB
Step 1 - Install EPEL repository
Before installing Apache CouchDB on a CentOS 7 server, we need to add a new EPEL repository (Extra Package for Enterprise Linux).
Add EPEL repository using the following yum command.
yum -y install epel-release
EPEL repository has been installed.
Step 2 - Install Apache CouchDB
Apache CouchDB provides rpm packages for installation on Redhat Linux. So in this step, we will install CouchDB from the Apache repository.
Go to the '/etc/yum.repos.d' directory and create a new repo file 'apache-couchdb.repo' using the vim editor.
Paste the following lines.
That's it. Save the change, and exit the editor.
Now install Apache CouchDB using the following command.
yum -y install couchdb
After the installation is complete, start the service and enable it to launch at system boot.
systemctl start couchdb
systemctl enable couchdb
Now check the service.
systemctl status couchdb
And you should get a result similar to the one shown below.
Now check the server port.
Apache CouchDB has been successfully installed on the CentOS 7 server, and is running under default port 5984.
Step 3 - Enable Apache CouchDB HTTP server
Apache CouchDB provides the HTTP server for admin access on default port 5984. And has an admin panel Web UI named 'Fauxton'.
In this step, we will enable the CouchDB HTTP server for admin panel access. So to begin with, go to the apache couchdb installation directory '/opt/couchdb', and edit the 'default.ini' configuration file under 'etc/' directory.
Now go to the '[chttpd]' configuration line and change the bind_address value with your IP address.
port = 5984
bind_address = 0.0.0.0
Save and exit.
Restart the couchdb service using the following systemctl command.
systemctl restart couchdb
Next, open your web browser and type your server IP address as shown below.
And you should get the following Fauxton web UI page.
If you have firewalld running on your server, open the couchdb port 5984 using the firewall-cmd command, as shown below.
firewall-cmd --add-port=5984/tcp --permanent
Step 4 - Configure admin account CouchDB
By default, the fresh Apache CouchDB installation has an 'Admin Party'. So anyone who connects to CouchDB server can do anything, including create, delete, add new user etc. In this step, we want to add new admin account for the CouchDB, and we will create that admin account from the admin panel.
Open your web browser and visit the following server IP address on port 5984.
Now click on the 'Admin Party' tab, type the admin user and password for couchdb, and then click the 'Create Admin' button.
New admin user for couchdb has been created.
Now, if you want to login to the admin panel Fauxton again, you will have to enter the login details.
Type your admin user and password to get access to the admin panel.
Step 5 - Basic usage Apache CouchDB
Apache CouchDB provides an API for managing the CouchDB system. And we will be using the 'curl' command utility for managing the CouchDB system.
In this step, we will discuss basic management. We will try to create the new database, show database list, delete the database etc using curl command.
- Hello CouchDB
To get information about the installed couchdb server, we can use the 'GET' parameter as shown below.
curl -X GET http://localhost:5984/
You will get a Welcome message result similar to the following.
The output reveals CouchDB 2.1.0 installed on our CentOS 7 server.
- Create new database
In order to create a new database, we need admin privileges. And for this action, we will be using the 'PUT' parameter.
We will create a new database named 'hakase_db'.
Run the following curl command without user and password.
curl -X PUT http://localhost:5984/hakase_db
And you will get the 'Unauthorized' message error.
Now try using the admin user password.
curl -X PUT http://hakase:aq[email protected]:5984/hakase_db
And you will see the command is successful.
New database 'hakase_db' has been created through the CouchDB API.
- List database and Info
To get information about the database, we must use the 'GET' parameter.
Run the command below to get the database list on the server.
curl -X GET http://hakase:[email protected]:5984/_all_dbs
And you should get the 'hakase_db' as part of the retrieved list.
Next, get 'hakase_db' info using the command below.
curl -X GET http://hakase:[email protected]:5984/hakase_db
And the output should contains information related to the database.
- Delete Database
We need the 'DELETE' parameter for deleting the database on the CouchDB server. Delete the 'hakase_db' database using the following command.
curl -X DELETE http://hakase:[email protected]:5984/hakase_db
Now check again the database list on the CouchDB server.
curl -X GET http://hakase:[email protected]:5984/_all_dbs
And you'll find that the 'hakase_db' database is deleted.
The installation and configuration for Apache CouchDB on CentOS 7 has been successful.