Deploy and Configure Indexer stack
This guide provides instructions for:
Installing indexer-agent, graph-cli, indexer-cli, indexer-service
Where relevant, configuring a systemd unitfile for each component, so they auto-restart on failure.
Acknowledgements and Disclaimer
The contents of this guide has been pulled together from a variety of sources. It has been tested on Ubuntu Server 18.04 and 20.04. Your mileage may vary. The exact versions of Graph components needed for mainnet/testnet are documented here - many of the commands include specific versions of the Graph software and you will need to crosscheck and use the latest versions approved for the network you are deploying on.
Prerequisites
First and foremost, it is assumed that you have decided on your architecture per the earlier part of this guide series - VMs or containers, storage sizing and redundancy, Eth node choice. At all times, this guide will use the reference architecture from the first page for all instructions. This guide is not intended for absolute beginners. It assumes some knowledge of using a linux terminal. Before you get started you will need to have your Ubuntu server instance up and running and up to date. Your server will require an internet connection. This guide assumes that you are logged into the server using a non-root account with SUDO access. Security will not be covered in this guide.
Note: If you are using Linux containers and being economical with the resources you assign to them, you need to be sure that you supply them with enough memory and compute power to install packages, or you will see strange, un-diagnosable behavior from npm. 4 vcpu and 2GB of memory should be sufficient in most cases.
Specific versions of graph software will be used in this guide, but you should always install the latest builds for the network you are deploying to (mainnet or testnet). You can find the approved versions here
Testnet prerequisites
You will need two Ethereum addresses in order to run your Indexer. One Indexer address and one Operator address. Indexer = your main address with all privileges. Operator = the address used by the indexer, only has specific privileges to run the indexer software.
If you are deploying to testnet you will need testnet GRT in order to register your Indexing operation on-chain. Check the discord for info on how to register and receive testnet GRT.
Software prerequisites
Additional packages that need to be installed:
Important: Due to the inclusion of a Rust build process in the NPM install for many graph indexer components, it is necessary to complete the install process logged in as root. Using sudo
is not sufficient. Once the indexer software is installed, you are free to run it with any user account you like. If somebody knows how to overcome this need to use a root account and has tested their solution, please submit a PR.
Install curl:
Latest version of node and npm:
Rust and related packages for building with Rust:
Rust - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Git - sudo apt install git
To support Rust compiles - sudo apt-get install -y clang libpq-dev libssl-dev pkg-config build-essential
Install indexer-agent
Per the reference architecture, one indexer-agent should be deployed. Reminder: this must be completed signed into the root account, not using sudo
Now that you have installed the agent, you can check that it is working by logging out of the root account and into another user account and running:
And if it's working you should get a version response.
Configure the indexer-agent
Now we will create a startup script for the indexer agent:
Notes: You need two separate Ethereum addresses.
--mnemonic correct horse battery staple... - This is the mnemonic for your Indexer Operator address. It has limited ability to only operate the agent and nothing more.
--indexer-address 0x... This is the top level Indexer address, the address with all the privileges. You will use this address to set the Indexer Operator address as a valid operator for your Indexer address later.
Make your startup script executable chmod +x graph-indexer-agent-startup.sh
Create a service unit file for the agent, so it can auto start on reboot and process failures. Note, in the example below the user user
is used; you can choose to run the agent under your own choice of username.
Now install the new service using sudo systemctl daemon-reload
At this point it is a good idea to manually run your graph-indexer-agent-startup.sh
and check that it runs correctly. Keep in mind that in order to do this your testnet addresses will need to have Rinkeby eth in order to perform on-chain actions such as registering as an indexer and setting operators. You can follow the official guide to registering on-chain https://github.com/graphprotocol/indexer/blob/main/docs/networks.md#testnet-httpstestnetthegraphcom-rinkeby
Once you are confident it works correctly, you can enable the service for auto-restart using sudo systemctl enable graph-indexer-agent.service
Install indexer-service
Install the additional packages described earlier, just as you did for indexer-agent. Remember to install them as root per the above notes, at which point you can then move to a dedicated user for the indexer-service.
Now you can install the service (again, do this as root)
Configure the indexer-service
Now we will create a startup script for the indexer service:
Make your startup script executable chmod +x graph-indexer-service-startup.sh
Create a service unit file for the agent, so it can auto start on reboot and process failures. Note, in the example below the user user
is used; you can choose to run the agent under your own choice of username.
Install indexer-cli
The indexer-cli is the command line interface tool for interacting with an indexing operation. In this example we deploy a small container specifically for using the CLI however you can deploy this wherever you want within your infrastructure. Deploying a dedicated container for the CLI is quite useful as a starting point for building a Bastion server for your operation - the single point in the network that can access all servers in whatever fashion is required - SSH, Graph CLI or otherwise.
As per other Indexer components, install as root and install all the pre-req software first.
npm install -g @graphprotocol graph-cli
npm install -g @graphprotocol indexer-cli@0.12.0
You can check the software is installed correctly with graph --help
and graph indexer --help
You are now ready to connect to your indexer-agent using graph indexer connect http://graph-test-agent-0:18000
once your agent is up and running. Assuming you are deploying to testnet, you need to follow this guide for getting set up on chain before you start any graph components.
Quick final note: If you have issues with npm install
when following the testnet instructions for getting set up on chain linked above, make sure you have all the pre-req software from this guide installed where your client is installed, and failing that, you can use yarn install
and yarn run compile
as an alternative and that should work for your environment.
Last updated