Single Host Setup - Deploy

Run directly on the host

Run dgraph zero

dgraph zero --my=IPADDR:5080

The --my flag is the connection that Dgraph alphas would dial to talk to zero. So, the port 5080 and the IP address must be visible to all the Dgraph alphas.

For all other various flags, run dgraph zero --help.

Run dgraph alpha

dgraph alpha --lru_mb=<typically one-third the RAM> --my=IPADDR:7080 --zero=localhost:5080
dgraph alpha --lru_mb=<typically one-third the RAM> --my=IPADDR:7081 --zero=localhost:5080 -o=1

Notice the use of -o for the second Alpha to add offset to the default ports used. Zero automatically assigns an unique ID to each Alpha, which is persisted in the write ahead log (wal) directory, users can specify the index using --idx option. Dgraph Alphas use two directories to persist data and wal logs, and these directories must be different for each Alpha if they are running on the same host. You can use -p and -w to change the location of the data and WAL directories. For all other flags, run

dgraph alpha --help.

Run dgraph UI

dgraph-ratel

Run using Docker

Dgraph cluster can be setup running as containers on a single host. First, you’d want to figure out the host IP address. You can typically do that via

ip addr  # On Arch Linux
ifconfig # On Ubuntu/Mac

We’ll refer to the host IP address via HOSTIPADDR.

Create Docker network

docker network create dgraph_default

Run dgraph zero

mkdir ~/zero # Or any other directory where data should be stored.
docker run -it -p 5080:5080 --network dgraph_default -p 6080:6080 -v ~/zero:/dgraph dgraph/dgraph:v20.07 dgraph zero --my=HOSTIPADDR:5080

Run dgraph alpha

mkdir ~/server1 # Or any other directory where data should be stored.
docker run -it -p 7080:7080 --network dgraph_default -p 8080:8080 -p 9080:9080 -v ~/server1:/dgraph dgraph/dgraph:v20.07 dgraph alpha --lru_mb=<typically one-third the RAM> --zero=HOSTIPADDR:5080 --my=HOSTIPADDR:7080
mkdir ~/server2 # Or any other directory where data should be stored.
docker run -it -p 7081:7081 --network dgraph_default -p 8081:8081 -p 9081:9081 -v ~/server2:/dgraph dgraph/dgraph:v20.07 dgraph alpha --lru_mb=<typically one-third the RAM> --zero=HOSTIPADDR:5080 --my=HOSTIPADDR:7081  -o=1

Notice the use of -o for server2 to override the default ports for server2.

Run dgraph UI

docker run -it -p 8000:8000 --network dgraph_default dgraph/dgraph:v20.07 dgraph-ratel

Run using Docker Compose (On single AWS instance)

We will use Docker Machine. It is a tool that lets you install Docker Engine on virtual machines and easily deploy applications.

Note These instructions are for running Dgraph Alpha without TLS config. Instructions for running with TLS refer TLS instructions.

Here we’ll go through an example of deploying Dgraph Zero, Alpha and Ratel on an AWS instance.

  • Make sure you have Docker Machine installed by following instructions, provisioning an instance on AWS is just one step away. You’ll have to configure your AWS credentials for programmatic access to the Amazon API.

  • Create a new docker machine.

    docker-machine create --driver amazonec2 aws01
    

Your output should look like

Running pre-create checks...
Creating machine...
(aws01) Launching instance...
...
...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env aws01

The command would provision a t2-micro instance with a security group called docker-machine (allowing inbound access on 2376 and 22). You can either edit the security group to allow inbound access to ‘5080,8080,9080` (default ports for Dgraph Zero & Alpha) or you can provide your own security group which allows inbound access on port 22, 2376 (required by Docker Machine), 5080, 8080 and 9080. Remember port 5080 is only required if you are running Dgraph Live Loader or Dgraph Bulk Loader from outside.

Here is a list of full options for the amazonec2 driver which allows you choose the instance type, security group, AMI among many other things.

Tip Docker machine supports other drivers like GCE, Azure etc.
  • Install and run Dgraph using docker-compose

Docker Compose is a tool for running multi-container Docker applications. You can follow the instructions here to install it.

Run the command below to download the docker-compose.yml file on your machine.

wget https://github.com/dgraph-io/dgraph/raw/master/contrib/config/docker/docker-compose.yml

Note The config mounts /data(you could mount something else) on the instance to /dgraph within the container for persistence.

  • Connect to the Docker Engine running on the machine.

Running docker-machine env aws01 tells us to run the command below to configure our shell.

eval $(docker-machine env aws01)

This configures our Docker client to talk to the Docker engine running on the AWS Machine.

Finally run the command below to start the Zero and Alpha.

docker-compose up -d

This would start 3 Docker containers running Dgraph Zero, Alpha and Ratel on the same machine. Docker would restart the containers in case there is any error. You can look at the logs using docker-compose logs.


This is a companion discussion topic for the original entry at https://dgraph.io/docs/deploy/single-host-setup/
1 Like