Set up Avalanche Node

Selcuk
6 min readNov 20, 2023

Learn how to run avalanchego on a cloud service by creating avalanchego.service but before dive into it, let’s prepare our server and necessary tools to run avalanchego.

RENT A CONTABO VPS SERVICE AS START

You can choose one of the 4 options shown below as VPS M, VPS L and VPS XL on https://contabo.com/en/vps/. Choose the most suitable one according to your budget. If you already have a VPS or a Linux ubuntu18.04 or 20.04 system running at home, you can skip to the Terminal installation or preliminaries section below…

the link https://contabo.com/en/vps/vps-xl-ssd/?qty=1&contract=12&storage-type=vps-xl-nvme-400-gb assuming you want the best for Avalanche. The price of 323 Euros per year, excluding VAT. You may also rent a “Dedicated Server” according to the stake amount of your Node. You will receive a VPS with AMD EPYC processor and operating system we will use will be Ubuntu 20.04. Considering Avalanche Subnets and the increasing capacity need in future , we can add NVME SSD to our list by buying 800 GB at least.

KYC

When the purchase is completed, KYC (know your customer) will be requested by Contabo team by email ( support@contabo.com) and once you complete it, another email sent to you that contains necessary information to log in to your terminal such as IP adress, user name and password as shown below

PUTTY TERMINAL SET UP AND LOG IN TO YOUR TERMINAL

We will download putty terminal on https://www.putty.org/ and set up on our operating system.

TERMINAL

log as: enter your username as root and then the password given to you in the e-mail.

you can optionally change the root password as this is the first time we are logging into this terminal.

sudo passwd root

After changing the password, you can delete your e-mailed information.

PRELIMINARY PREPARATIONS

First, let’s make sure that our main system is up to date. Let’s type these two commands to update;

sudo apt-get update && sudo apt-get upgrade

After making our update, let’s define a new user and continue our node installation and execution processes with our new username. Let’s use selcuk as an example. You can give any name you like.

sudo adduser selcuk

After entering the information, let’s define the privileges in root for the newly defined user name selcuk. First, let’s open our editor by typing the following command;

visudo

Let’s write our username and authorize where shown in yellow color in the picture below;

selcuk ALL=(ALL:ALL) ALL

Save with “CTRL O” and exit again with “CTRL X”.

Close the terminal completely, re-enter the terminal with the username and password we defined this time and install the following add-ons into the new user selcuk.

HELPFUL PRE-INSTALLATION ADD-ONS

a) JQ: It will be very useful especially during API queries

sudo apt-get install jq

b) CCZE: is a nice plugin that colors log records when we want to monitor process flows.

sudo apt-get install ccze

c) HTOP: is a useful plugin that allows you to see system information, background processes and CPU load.

sudo apt-get install htop

d) UFW: This command, which is a firewall plugin, will be required to open ports in the avalanche, so we need to install it.

sudo apt-get install ufw -y

NODE INSTALLATION

  1. First of all, let’s open port 9651 for Avalanche node
sudo ufw allow 9651/tcp

2) Download the current version of Avalanchego;

wget https://github.com/ava-labs/avalanchego/releases/download/v1.10.15/avalanchego-linux-amd64-v1.10.15.tar.gz

3) Now let’s set up Avalanchego;

sudo tar -xvf avalanchego-linux-amd64-v1.10.15.tar.gz

now let’s create a new service file to run avalanchego in the background before running it. this is one of the ways to run avalanchego. even if you log out of the terminal, the avalanche node runs in the background thanks to the service file. first, let’s enter the following command to create the service file;

sudo nano /etc/systemd/system/avalanchego.service

Since we are in the editor, let’s copy the lines below into the editor. Make the necessary changes according to your username. Below, change user name selcuk and IP address .

[Unit]
Description=AVAX node
Wants=network-online.target
After=network.target network-online.target

[Service]
User=selcuk
WorkingDirectory=/home/selcuk/avalanchego-v1.10.15
ExecStart=/home/selcuk/avalanchego-v1.10.15/avalanchego --public-ip=100.100.130.100
KillMode=process
KillSignal=SIGINT
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=avalanchego

Restart=always
RestartSec=0

# Hardening measures

####################

# Provide a private /tmp and /var/tmp.
PrivateTmp=true

# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full

# Deny access to /home, /root and /run/user
# ProtectHome=true# Disallow the process and all of its children to gain

# new privileges through execve().
NoNewPrivileges=true

# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true

[Install]
WantedBy=multi-user.target

Save with “CTRL O” and exit with “CTRL X”.

Now let’s give the necessary authorizations to the avalanchego.service file;

sudo chmod 644 /etc/systemd/system/avalanchego.service
sudo systemctl enable avalanchego && sudo systemctl daemon-reload

NODE PRUNE SETTINGS

Avalanche hosts 3 types of nodes. One of them is the Archive node (hosting a database of about 3TB and above), the other is a pruned node (about 1TB and above Database) and the other is the State node version. When we start the node, unless we specify otherwise with the code, the pruned node runs and tries to pull the database. If we are not going to start a dapp or subnet project, the “state node” will do the job. For this, we need to do the following steps
The ~/.avalanchego folder will not be created because we did not run the node for the first time. this folder is created automatically when we run it for the first time and stop the node. we need to create the configs, chains and capital C folders respectively.

mkdir -p ~/.avalanchego/configs/chains/C 
cd ~/.avalanchego/configs/chains/C

then create config.json file with nano editor in C folder

sudo nano config.json

lets Type below codes;

{
“state-sync-enabled”: true
}

Save with CTRL O and exit with CTRL X.

Now we can start our new avalanche node.

sudo systemctl start avalanchego

or if you want to see their records immediately after the system is up and running;

sudo systemctl start avalanchego && sudo journalctl -u  avalanchego -f -n 100 | ccze

Stop monitoring the log with CTRL X and wait for the system database download. We call this the Database Sync process.

COMMANDS TO LOOK AT SYSTEM LOGS

#logs
sudo journalctl -u avalanchego -f#logs
sudo journalctl -u avalanchego -f -n 100# former 100 logs
sudo tail -f cat ~/.avalanchego/logs/C.log

Again, at the end of these commands, we can add the command “ | ccze “ for the “log colorizer” plugin we installed in the plugins.

API‘s : https://docs.avax.network/reference

With the API queries given on docs.avax.network, you can query your Nodeid, whether it is working healthy or not.
The API query that interests us most here is Health, that is, whether the node is healthy.

curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"health.health"
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/health | jq

As you can see, we added the “ | jq “ from the plugins at the end. This makes the query result more readable. I recommend adding it at the end of every API query. The Health API query result is expected to be “TRUE”. In the example below you see the output of health API.

for donation,

X-avax1gfh8ysl4487andp0ef3849tmaxkw9k6g5wclz7

--

--