How to Install and Configure Dgraph on Ubuntu Linux

Dgraph is a highly advanced NoSQL database system that offers multi-model compatibility and high availability across multiple domains to eradicate any single point of failure. This database platform is used widely by enterprises, small and large, for efficient data processing. The article presents a comprehensive step-by-step guide on how to install and configure Dgraph on…

This brief tutorial shows students and new users how to install Dgraph on Ubuntu 16.04 | 18.04 LTS servers.

Dgraph is probably the world’s most advanced graph, multi-model NoSQL database system with high availability across multiple systems, thus eliminating a single failure point.

If you need a database management system with a native multi-model and robust user interface, including high availability, you may want to look at Dgraph.

This database platform is used by small and large companies that process massive amounts of data. The system provides synchronous replication and automatic failover, so losing a hard disk or a server doesn’t affect services.

For more about Dgraph, please visit its homepage.

Install Required Packages

To install Dgraph, you may want to install some required packages and prepare your server.

First, run the commands below to install curl and apt-transport-https.

sudo apt update
sudo apt install curl apt-transport-https

After installing the package above, continue below to install Dgraph.

Install Dgraph

Now that some required packages have been installed follow the steps below to get Dgraph installed and configured. Dgraph has an official script that allows you to install and configure the server easily.

To get the script, run the commands below:

curl https://get.dgraph.io -sSf | bash

When you run the script above, you’re prompted to accept the license agreement and others.

After the steps above, run the commands below to install them.

/usr/local/bin/

You should see a similar message as shown below:

Latest release version is v1.0.11.
Downloading checksum file for v1.0.11 build.
######################################################################## 100.0%
Download complete.
Comparing checksums for dgraph binaries
Downloading https://github.com/dgraph-io/dgraph/releases/download/v1.0.11/dgraph-linux-amd64.tar.gz
######################################################################## 100.0%
Download complete.
Inflating binaries (password may be required).
Dgraph binaries v1.0.11 have been installed successfully in /usr/local/bin.
Please visit https://docs.dgraph.io/get-started for further instructions on usage.

Although Dgraph is installed and can function, there’s no way to control its services via Systemd. So with that, we’ll want to create these services so managing startups and shutdowns can be effortless.

To do that, run the commands below to create a system user called dgraph.

sudo groupadd --system dgraph
sudo useradd --system -d /var/run/dgraph -s /bin/false -g dgraph dgraph

After that, run the commands below to create directories for Dgraph logs and state files.

sudo mkdir -p /var/log/dgraph
sudo mkdir -p /var/run/dgraph/{p,w,zw}
sudo chown -R dgraph:dgraph /var/{run,log}/dgraph

After creating the directories above, you can begin creating each systemd service profile for each service.

There are three services we need to create: dgraph-zero.service, graph-ui. Service and dgraph.service

For the dgraph.service, run the commands below:

sudo nano /etc/systemd/system/dgraph.service

Then copy and paste the lines below into the file and save.

[Unit]
Description=dgraph.io data server
Wants=network.target
After=network.target dgraph-zero.service
Requires=dgraph-zero.service

[Service]
Type=simple
ExecStart=/usr/local/bin/dgraph alpha --lru_mb 2048 -p /var/run/dgraph/p -w /var/run/dgraph/w
StandardOutput=journal
StandardError=journal
User=dgraph
Group=dgraph

[Install]
WantedBy=multi-user.target

For dgraph-zero.service, run the commands below:

sudo nano /etc/systemd/system/dgraph-zero.service

Then copy and paste the lines below into the file and save.

[Unit]
Description=dgraph.io zero server
Wants=network.target
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/dgraph zero --wal /var/run/dgraph/zw
StandardOutput=journal
StandardError=journal
User=dgraph
Group=dgraph

[Install]
WantedBy=multi-user.target
RequiredBy=dgraph.service

For graph-ui. service. Run the commands below:

sudo nano /etc/systemd/system/dgraph-ui.service

Then copy and paste the lines below into the file and save.

[Unit]
Description=dgraph.io UI server
Wants=network.target
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/dgraph-ratel
StandardOutput=journal
StandardError=journal
User=dgraph
Group=dgraph

[Install]
WantedBy=multi-user.target

After the above,

sudo systemctl daemon-reload
sudo systemctl enable --now dgraph
sudo systemctl enable --now dgraph-ui

That should do it!

When you check the status of the service, you should see them all running and active.

systemctl status dgraph dgraph-zero dgraph-ui

See all services below:

● dgraph.service - dgraph.io data server
   Loaded: loaded (/etc/systemd/system/dgraph.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-02-27 11:05:50 CST; 24s ago
 Main PID: 22272 (dgraph)
    Tasks: 58 (limit: 4663)
   CGroup: /system.slice/dgraph.service
           └─22272 /usr/local/bin/dgraph alpha --lru_mb 2048 -p /var/run/dgraph/p -w /var/ru

Feb 27 11:05:54 ubuntu1804 dgraph[22272]: I0227 11:05:54.113076   22272 groups.go:388] Servi
Feb 27 11:05:54 ubuntu1804 dgraph[22272]: I0227 11:05:54.113488   22272 mutation.go:158] Don
Feb 27 11:05:54 ubuntu1804 dgraph[22272]: I0227 11:05:54.114168   22272 groups.go:388] Servi

● dgraph-zero.service - dgraph.io zero server
   Loaded: loaded (/etc/systemd/system/dgraph-zero.service; disabled; vendor preset: enabled
   Active: active (running) since Wed 2019-02-27 11:05:50 CST; 24s ago
 Main PID: 22271 (dgraph)
    Tasks: 13 (limit: 4663)
   CGroup: /system.slice/dgraph-zero.service
           └─22271 /usr/local/bin/dgraph zero --wal /var/run/dgraph/zw

Feb 27 11:05:53 ubuntu1804 dgraph[22271]: I0227 11:05:53.855906   22271 node.go:83] raft.nod
Feb 27 11:05:53 ubuntu1804 dgraph[22271]: I0227 11:05:53.856089   22271 raft.go:613] I've be
Feb 27 11:05:53 ubuntu1804 dgraph[22271]: I0227 11:05:53.856165   22271 

● dgraph-ui.service - dgraph.io UI server
   Loaded: loaded (/etc/systemd/system/dgraph-ui.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-02-27 11:06:00 CST; 14s ago
 Main PID: 22362 (dgraph-ratel)
    Tasks: 4 (limit: 4663)
   CGroup: /system.slice/dgraph-ui.service
           └─22362 /usr/local/bin/dgraph-ratel

Feb 27 11:06:00 ubuntu1804 systemd[1]: Started dgraph.io UI server.

Now, you can continue below to access its web interface.

Access Dgraph Web Interface

Dgraph also comes with a web interface for easy management in your web browser. To log in, go to the server hostname or IP address followed by port # 8000

http://localhost:8000

Log on with no passwords.

Enjoy!

Congratulations! You have successfully installed Dgraph on Ubuntu 16.04 and 18.05

You may also like the post below:

Richard Avatar

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *