Ask a Question

Single Host Cluster Setup

Dgraph does not recommend single host setup for a production environment. For a production environment you need to ensure High Availability with external persistent storage, automatic recovery of failed services, automatic recovery of failed systems such as virtual machines, and highly recommended disaster recovery such as backup/restore or export/import with automation. You can install and run Dgraph cluster on a single host using Docker, Docker Compose, or Dgraph command line.

Docker

Dgraph cluster can be setup running as containers on a single host.

Note As of release v21.03, Dgraph no longer supports installation on Windows or macOS. Windows and macOS users who want to evaluate Dgraph can use the standalone Docker image.

Before you begin

Ensure that you have installed:

Using Docker

To setup a Dgraph cluster on a single host using Docker:

  1. Get the <IP_ADDRESS> of the host using:

       ip addr  # On Arch Linux
       ifconfig # On Ubuntu/Mac
    
  2. Pull the latest Dgraph image using docker:

       docker pull dgraph/dgraph:latest
    
  3. Verify that the image is downloaded:

       docker images
    
  4. Create a <DGRAPH_NETWORK> using:

       docker network create <DGRAPH_NETWORK>
    
  5. Create a directory <ZERO_DATA>to store data for Dgraph Zero and run the container:

       mkdir ~/<ZERO> # Or any other directory where data should be stored.
    
       docker run -it -p 5080:5080 --network <DGRAPH_NETWORK> -p 6080:6080 -v ~/<ZERO_DATA>:/dgraph dgraph/dgraph:latest dgraph zero --my=<IP_ADDRESS>:5080
    
  6. Create a directory <ALPHA_DATA_1> to store for Dgraph Alpha and run the container:

     mkdir ~/<ALPHA_DATA_1> # Or any other directory where data should be stored.
    
     docker run -it -p 7080:7080 --network <DGRAPH_NETWORK> -p 8080:8080 -p 9080:9080 -v ~/<ALPHA_DATA_1>:/dgraph dgraph/dgraph:latest dgraph alpha --zero=<IP_ADDRESS>:5080 --my=<IP_ADDRESS>:7080
    
  7. Create a directory <ALPHA_DATA_2> to store for the second Dgraph Alpha and run the container:

       mkdir ~/<ALPHA_DATA_2> # Or any other directory where data should be stored.
    
       docker run -it -p 7081:7081 --network <DGRAPH_NETWORK> -p 8081:8081 -p 9081:9081 -v ~/<ALPHA_DATA_2>:/dgraph dgraph/dgraph:v22.0.2 dgraph alpha --zero=<IP_ADDRESS>:5080 --my=<IP_ADDRESS>:7081  -o=1
    

    To override the default ports for the second Alpha use -o.

  8. Connect the Dgraph cluster that are running using https://play.dgraph.io/. For information about connecting, see Ratel UI.

Dgraph Command Line

You can run Dgraph directly on a single Linux host.

Before you begin

Ensure that you have:

  • Installed Dgraph on the Linux host.
  • Made a note of the <IP_ADDRESS> of the host.

Using Dgraph Command Line

You can start Dgraph on a single host using the dgraph command line.

  1. Run Dgraph zero

       dgraph zero --my=<IP_ADDRESS>:5080
    

    The --my flag is the connection that Dgraph alphas 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.

  2. Run two Dgraph alpha nodea:

       dgraph alpha --my=<IP_ADDRESS>:7080 --zero=localhost:5080
       dgraph alpha --my=<IP_ADDRESS>:7081 --zero=localhost:5080 -o=1
    

    Dgraph alpha nodes 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.To learn more about other flags, run dgraph alpha --help.

  3. Connect the Dgraph cluster that are running using https://play.dgraph.io/. For information about connecting, see Ratel UI.

Docker Compose

You can install Dgraph using the Docker Compose on a system hosted on any of the cloud provider.

Before you begin

  • Ensure that you have installed Docker Compose.
  • IP address of the system on cloud <CLOUD_IP_ADDRESS>.
  • IP address of the local host <IP_ADDRESS>.

Using Docker Compose

  1. Download the Dgraph docker-compose.yml file:

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

    By default only the localhost IP 127.0.0.1 is allowed. When you run Dgraph on Docker, the containers are assigned IPs and those IPs need to be added to the allowed list.

  2. Add a list of IPs allowed for Dgraph so that you can create the schema. Use an editor of your choice and add the <IP_ADDRESS> of the local host in docker-compose.yml file:

    # This Docker Compose file can be used to quickly bootup Dgraph Zero
    # and Alpha in different Docker containers.
    # It mounts /tmp/data on the host machine to /dgraph within the
    # container. You will need to change /tmp/data to a more appropriate location.
    # Run `docker-compose up` to start Dgraph.
    version: "3.2"
    services:
      zero:
        image: dgraph/dgraph:latest
        volumes:
          - /tmp/data:/dgraph
        ports:
          - 5080:5080
          - 6080:6080
        restart: on-failure
        command: dgraph zero --my=zero:5080
      alpha:
        image: dgraph/dgraph:latest
        volumes:
          - /tmp/data:/dgraph
        ports:
          - 8080:8080
          - 9080:9080
        restart: on-failure
        command: dgraph alpha --my=alpha:7080 --zero=zero:5080 --security whitelist=<IP_ADDRESS>
      ratel:
        image: dgraph/ratel:latest
        ports:
          - 8000:8000
    
    
  3. Run the docker-compose command to start the Dgraph services in the docker container:

    sudo docker-compose up
    

    After Dgraph is installed on Docker, you can view the images and the containers running in Docker for Dgraph.

  4. View the containers running for Dgraph using:

    sudo docker ps -a
    

    An output similar to the following appears:

    CONTAINER ID   IMAGE                  COMMAND                  CREATED
    4b67157933b6   dgraph/dgraph:latest   "dgraph zero --my=ze…"   2 days ago
    3faf9bba3a5b   dgraph/ratel:latest    "/usr/local/bin/dgra…"   2 days ago
    a6b5823b668d   dgraph/dgraph:latest   "dgraph alpha --my=a…"   2 days ago
    
  5. To access the Ratel UI for queries, mutations, and altering schema, open your web browser and navigate to http://<CLOUD_IP_ADDRESS>:8000.

  6. Click Launch Latest to access the latest stable release of Ratel UI.

  7. In the Dgraph Server Connection dialog that set the Dgraph server URL as http://<CLOUD_IP_ADDRESS>:8080

  8. Click Connect . The connection health appears green.

  9. Click Continue to query or run mutations.