How to Install RethinkDB on Ubuntu

The RethinkDB is a free and open-source database for building realtime web applications. It's a distributed document-oriented database, easy to scale, high availability database with automatic failover and robust fault-tolerance.

This tutorial will show you how to install and configure RethinkDB on an Ubuntu 18.04 server.

Prerequisites

For this guide, we will install the RethinkDB with the latest Ubuntu server 18.04.3 with 2GB of RAM and 2CPUs.

What we will do:

  • Install RethinkDB
  • Configure RethinkDB
  • Install RethinkDB Client Driver
  • Access the RethinkDB Dashboard

Step 1 - Add the RethinkDB Repository

First, we will add the RethinkDB repository and GPG key to the Ubuntu system.

Load the environment variable on the '/etc/lsb-release' script using the command below.

source /etc/lsb-release

After that, add the RethinkDB repository and GPG key.

echo "deb https://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -

Now update the Ubuntu repository.

sudo apt update

Wait for the repository being updated.

Step 2 - Install and Configure RethinkDB

In this step, we will install and configure the RethinkDB.

Install RethinkDB using the apt command below.

sudo apt install rethinkdb

Once the installation is complete, go to the '/etc/rethinkdb' directory, copy the sample configuration 'default.conf.sample' to the 'instances.d/instance1.conf'.

cd /etc/rethinkdb/
cp default.conf.sample instances.d/instance1.conf

Edit the 'instances.d/instance1.conf' usng vim editor.

vim instances.d/instance1.conf

Uncomment the 'bind' configuration with your local IP address.

bind=10.5.5.15

On the bottom of the line, uncomment the 'server-name' option and change the value with 'instance1'.

server-name=instance1

Save and close.

Now restart the RethinkDB service and add it to the system boot.

systemctl restart rethinkdb
systemctl enable rethinkdb

The RethinkDB service is up and running, check it using the following commands.

systemctl status rethinkdb

And you will get the result as below.

As a result, the RethinkDB is running on the Ubuntu 18.04 server.

It's running three different ports, the port '28015' is used for client driver, port '8080' for the HTTP admin dashboard, and port '29015' for the cluster port.

Step 3 - Install RethinkDB Client Driver

The RethinkDB provides multiple client drivers for different programming languages such as Python, JavaScript, Ruby, etc.

In this step, we will install the RethinkDB client driver for Python3 and show you the basic usages of it.

First, install the python3 and python3-pip packages to the system.

sudo apt install python3 python3-pip

After that, install the RethinkDb client driver for Python 3 using the pip3 command below.

pip3 install rethinkdb

As a result, you've installed the RethinkDB client driver for Python3.

Next, run the python3 shell.

python3

Import the RethinkDB module.

from rethinkdb import r

- Connect to RethinkDB

Connect to the RethinkDB system on port '28015'.

conn = r.connect(host='localhost', port=28015)

- Create Database

Now create a new database 'dbtest'.

r.db_create('dbtest').run(conn)

- Check List Databases

After that, check the list of databases.

r.db_list().run(conn)

And you will get the result as below.

As a result, you've created a new database 'dbtest'.

- Create Table

Next, we will create a new table and insert the sample data to the 'users' database.

Create a new table 'users' on the database 'dbtest'.

r.db('dbtest').table_create('users').run(conn)

- Insert Data to RethinkDB

Insert new data to the table 'users'.

r.db('dbtest').table("users").insert({
"id": 1,
"name": "Hakase-Labs",
"site": "hakase-labs.local"
}).run(conn)

- Show Data

Now show all data on the 'users' table.

r.db('dbtest').table('users').run(conn)

And you will get the data that you just inserted on top.

As a result, you've successfully connected to the RethinkDB server, created a new database and insert data into it using the Python client driver.

Step 4 - Access the RethinkDB Dashboard

By default, the RethinkDB provides a dashboard for installation and configuration management. The dashboard is running on default port '8080'.

Open your web browser and type the RethinkDB server IP address with port '8080'.

http://10.5.5.15:8080/

Now you will get the RethinkDB dashboard as below.

Click the 'Tables' menu on top to get a list of databases and tables.

Now click on the table name to get data on it.

As a result, you get the data that just inserted on top.

Finally, the installation of RethinkDB on Ubuntu 18.04 has been completed successfully.

Share this page:

0 Comment(s)