Friday, November 15, 2024
Google search engine
HomeData Modelling & AIHow To Install Dgraph on Ubuntu 22.04|20.04|18.04

How To Install Dgraph on Ubuntu 22.04|20.04|18.04

Question: How to install Dgraph on Ubuntu 22.04|20.04|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 Ubuntu22.04|20.04|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 Ubuntu22.04/20.04/18.04

Download the latest binaries of Dgraph to your OS.

curl https://get.dgraph.io -sSf | sudo 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

A successful installation should give output similar to below.

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

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

$ ls /usr/local/bin/dgraph
/usr/local/bin/dgraph

Confirm version installed as reported from command line interface:

$ dgraph version

Dgraph version   : v21.03.2
Dgraph codename  : rocket-2
Dgraph SHA-256   : 00a53ef6d874e376d5a53740341be9b822ef1721a4980e6e2fcb60986b3abfbf
Commit SHA-1     : b17395d33
Commit timestamp : 2021-08-26 01:11:38 -0700
Branch           : HEAD
Go version       : go1.16.2
jemalloc enabled : true

For Dgraph official documentation, visit https://dgraph.io/docs.
For discussions about Dgraph     , visit https://discuss.dgraph.io.
For fully-managed Dgraph Cloud   , visit https://dgraph.io/cloud.

Licensed variously under the Apache Public License 2.0 and Dgraph Community License.
Copyright 2015-2021 Dgraph Labs, Inc.

Step 2: Create systemd service unit files

Since 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-alpha.service.

cat <<EOF | sudo tee /etc/systemd/system/dgraph-alpha.service
[Unit]
Description=dgraph.io Alpha instance
Wants=network.target
After=network.target dgraph-zero.service
Requires=dgraph-zero.service

[Service]
Type=simple
WorkingDirectory=/var/lib/dgraph
ExecStart=/usr/bin/bash -c 'dgraph alpha -p /var/lib/dgraph/p -w /var/lib/dgraph/w'
LimitNOFILE=65536
Restart=on-failure
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 instance
Wants=network.target
After=network.target

[Service]
Type=simple
WorkingDirectory=/var/lib/dgraph
ExecStart=/usr/bin/bash -c 'dgraph zero --wal /var/lib/dgraph/zw'
LimitNOFILE=65536
Restart=on-failure
StandardOutput=journal
StandardError=journal
User=dgraph
Group=dgraph

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

Next, enable and start the dgraph services.

sudo systemctl daemon-reload
sudo systemctl enable --now dgraph-alpha
sudo systemctl enable --now dgraph-zero

Check the status to confirm all services are running.

systemctl status dgraph-alpha dgraph-zero

Allow ports 8000 and 8080 on the firewall.

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.

install dgraph ubuntu 18.04 01

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

install dgraph ubuntu 18.04 02

You should then get the Dgraph Dashboard.

install dgraph ubuntu 18.04 03
install dgraph ubuntu 18.04 04

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

RELATED ARTICLES

Most Popular

Recent Comments