(Last Updated On: February 25, 2019)

Question: How to install Dgraph on CentOS 7?, How to install Dgraph on Ubuntu 18.04. Dgraph is an open source distributed graph database built from ground up for a rich set of queries.

Features of Dgraph

  • DISTRIBUTED: Dgraph shards the data to horizontally scale to hundreds of servers. It is designed to minimize the number of disk seeks and network calls.
  • FAST: Dgraph is built like a search engine. Queries are broken into sub-queries, which run concurrently to achieve low-latency and high throughput.
  • TRANSACTIONAL: With distributed ACID transactions, you can focus on your application logic, instead of worrying about data integrity.
  • HIGHLY AVAILABLE: Dgraph automatically runs synchronous replication, so losing a hard disk or a server doesn’t affect your services.
  • SHARD REBALANCING: Dgraph ensures that data is evenly balanced across servers by automatically moving shards, improving resource utilization for high performance.
  • FLEXIBLE SCHEMA: Quick iteration is important to keep your users happy. An adaptable flexible schema works with you as your application design evolves.
  • USER INTERFACE: Dgraph provides a user interface, so you can browse and manage your data, making it easier to stay on top of things.

Dgraph automatically optimizes query performance and throughput by closely controlling how the data is placed on disk to reduce disk seeks and network calls in a cluster. Dgraph supports GraphQL-like query syntax, and responds in JSON and Protocol Buffers over GRPC and HTTP.

Install Dgraph on CentOS 7 / Ubuntu 18.04

In this section, we will download Dgraph binaries and configure systemd service units. The first step is downloading the binary files.

Step 1: Download Dgraph binaries on CentOS 7 / Ubuntu 18.04

Download the latest binaries of Dgraph to your OS.

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

Agree to the terms of the Dgraph Community License when asked.

Do you agree to the terms of the Dgraph Community License? [Y/n] Y
Latest release version is v1.0.11.
Downloading checksum file for v1.0.11 build.
################################################################## 100.0%
Download complete.
......

A successful installation should give output similar to below.

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.

Dgraph binaries will be installed in /usr/local/bin. Ensure this directory is in your $PATH.

$ ls /usr/local/bin/dgraph<TAB>
dgraph dgraph-ratel

Step 2: Create systemd service unit files

Since both CentOS 7 and Ubuntu 18.04 uses systemd init system, we will configure Dgraph services to use Systemd for managing its states.

First, create a system account for dgraph service:

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

Create required directories – for 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

Create systemd service files starting with dgraph.service.

cat <<EOF | sudo tee /etc/systemd/system/dgraph.service
[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
EOF

Also add one for dgraph-zero.service.

cat <<EOF | sudo tee /etc/systemd/system/dgraph-zero.service
[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
EOF

Lastly create graph-ui.service.

cat <<EOF | sudo tee /etc/systemd/system/dgraph-ui.service
[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
EOF

Next, enable and start the dgraph services.

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

Check the status to confirm all services are running.

$ systemctl status dgraph dgraph-zero dgraph-ui
● dgraph.service - dgraph.io data server
Loaded: loaded (/etc/systemd/system/dgraph.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-02-25 05:27:58 UTC; 1min 3s ago
Main PID: 5585 (dgraph)
CGroup: /system.slice/dgraph.service
└─5585 /usr/local/bin/dgraph alpha --lru_mb 2048 -p /var/run/dgraph/p -w /var/run/dgraph/w
● dgraph-zero.service - dgraph.io zero server
Loaded: loaded (/etc/systemd/system/dgraph-zero.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2019-02-25 05:27:58 UTC; 1min 3s ago
Main PID: 5584 (dgraph)
CGroup: /system.slice/dgraph-zero.service
└─5584 /usr/local/bin/dgraph zero --wal /var/run/dgraph/zw
● dgraph-ui.service - dgraph.io UI server
Loaded: loaded (/etc/systemd/system/dgraph-ui.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-02-25 05:28:20 UTC; 41s ago
Main PID: 5657 (dgraph-ratel)
CGroup: /system.slice/dgraph-ui.service
└─5657 /usr/local/bin/dgraph-ratel

Allow ports 8000 and 8080 on the firewall.

# CentOS 7
sudo firewall-cmd --add-port={8000,8080}/tcp --permanent

# Ubuntu 18.04
sudo ufw allow proto tcp from any to any port 8000,8080

Accessing Dgraph UI

To access Dgraph UI, open the Server IP or hostname with port 8000. You should see an interface similar to below.

Choose the ratel interface to load. On the next page, enter the Dgraph URL, it should be port “8080“.

You should then get the Dgraph Dashboard.

Refer to Dgraph Documentation for more reading. Below are similar articles.

Install and Configure DBeaver on Ubuntu 18.04 / Ubuntu 16.04 / Debian 9

How to Install TimescaleDB on Ubuntu 18.04 LTS

How to install LevelDB on Ubuntu 18.04 / Ubuntu 16.04