Home 2023 Moonbeam Node Server Setup Guide
Post
Cancel

2023 Moonbeam Node Server Setup Guide

Overview:

Creating a Hetzner Server

If you want to run your node on a server then Hetzner is your best bet. There are other options out there like Digital Ocean and Vultr, but neither of them gets to the price point that Hetzner provides.

First Create an account at Hetzner. Then login at hetzner.cloud and bookmark this page. Go ahead and create a new project naming it whatever you like. Once it is created click on it and then click on ADD SERVER. In the options pick any location you want and Ubuntu for the Image.

Server Creation 1 Next pick the type standard and the option CPX41 which has 240 GB of storage.

Server Creation 2

Current requirements for a node based on the moonbeam docs say that we need an 8 Core CPU, 16 GB Ram, and a 1 TB SSD. These requirements are a bit over the top as they are intended for Validators/Collators and are future-proof. The main minimum specs we need to worry about is storage. As of writing this post a Full node on moonbeam currently needs roughly 400 GB of storage. This storage requirement will grow with time so keep that in mind. For now, we can use the CPX41 option as it meets the requirements, but most importantly the storage.

Node: Going under the 8 Core and 16 GB Ram requirements will work fine for a noncritical node and will only result in slower sync time. However, it is not recommended for Validators/Collators.

Next, create and add your SSH key. If you do not know how I suggest using ssh-keygen. An article explaining “How to Use ssh-keygen to Generate a New SSH Key?”.

Add SSH

Once the SSH key is added leave everything else default and click CREATE & BUY NOW

Server Creation 3

With the server created we can now login using ssh.

1
ssh root@<SERVER_IP>

You should then get a response as such.

SSH Login

Once logged in I recommend updating the server using 

1
sudo apt update && sudo apt upgrade

and rebooting.

Creating a Volume

In Hetzner click on the server, you created and go to the VOLUMES tab on the left. Then click Create Volume and set the storage to 524 GB and name it volume1. Now click CREATE & BUY NOW.

Create Volume

After the volume is created go back to where you logged into the server and configure the volume by following the commands given in the settings of the volume on Hetzner.

Volume Config

This mounts the volume at /mnt/volume1 where we will download the chain data.

Enabling SwapFile

Creating a Linux SwapFile is not necessary but is nice to have if you are running other memory-intensive programs on your server. Using a swap is a very useful way to extend the RAM because it provides the necessary additional memory when the RAM space has been exhausted and a process has to be continued. If you want to create a swap file run the following commands.

1
sudo fallocate -l 16G /swapfile
1
sudo chmod 600 /swapfile
1
sudo mkswap /swapfile
1
sudo swapon /swapfile

Open the /etc/fstab file

1
sudo nano /etc/fstab

add the following to the end of the file

1
/swapfile swap swap defaults 0 0

Save the file with Ctrl+s and close it with Ctrl+x

To verify that the swap file is active use

1
sudo swapon - show

It should result in something like the following.

1
2
NAME TYPE SIZE USED PRIO
/swapfile file 1024M 507.4M -1

Downloading Snapshot (optional)

Something that can GREATLY increase sync time is downloading an already synced snapshot of either the moonbeam para-chain, the relay chain, or both. If you need your node up quickly or don’t want to bother waiting this is your best option. My current recommendation is to use Certhum’s backups as they are updated regularly. If you want to sync the node from scratch skip down to the section Service and Binary Setup.

Moonbeam Relay Chain Backup

Download the backup to volume1. This will take time depending on your network speed.

1
wget -O /mnt/volume1/moonbeam-polkadot-backup.tar.zst https://db.certhum.com/moonbeam-polkadot-backup.tar.zst

Note: If the download fails or gets canceled reenter the command with the -c flag to continue the download from where it left off.

wgetBackup

next download the sst

1
wget -O /mnt/volume1/moonbeam-polkadot-sst.dict https://db.certhum.com/moonbeam-polkadot-sst.dict

install zstd (ZSTD speeds up the unzipping process)

1
sudo apt install zstd

Create the directory for the database in mnt/volume1

1
sudo mkdir -p /mnt/volume1/moonbeam-data/polkadot/chains/polkadot/db

and finally unzip the backup to the database using

1
sudo tar -I 'zstd -vd -T0 -D /mnt/volume1/moonbeam-polkadot-sst.dict' -xvf moonbeam-polkadot-backup.tar.zst -C /mnt/volume1/moonbeam-data/polkadot/chains/polkadot/db --strip-components=7

Note: Do not disconect from the server while unziping the backup or it will stop.

This should take some time so wait until it is finished.

Moonbeam Parachain RocksDB Backup

The process for downloading the Moonbeam Parachain is almost the same as the Relay Chain so I won’t go into as much detail.

1
wget -O /mnt/volume1/moonbeam-backup-archive.tar.zst https://db.certhum.com/moonbeam-backup.tar.zst
1
wget -O /mnt/volume1/moonbeam-sst.dict https://db.certhum.com/moonbeam-sst.dict
1
sudo mkdir -p /mnt/volume1/moonbeam-data/chains/moonbeam/db
1
sudo tar -I 'zstd -vd -T0 -D /mnt/volume1/moonbeam-sst.dict' -xvf /mnt/volume1/moonbeam-backup-archive.tar.zst -C /mnt/volume1/moonbeam-data/chains/moonbeam/db --strip-components=6

Service and Binary Setup

The following commands will set up everything regarding running the service.

  1. Creates a service account to run the service:
1
adduser moonbeam_service --system --no-create-home
  1. Creates a directory to store the binary and data:
1
sudo mkdir /mnt/volume1/moonbeam-data
  1. Downloads the Latest Moonbeam Binary:
1
sudo wget -O /mnt/volume1/moonbeam-data/moonbeam https://github.com/PureStake/moonbeam/releases/download/v0.30.3/moonbeam
  1. Sets the ownership and permissions for the local directory that stores the chain data:
1
sudo chmod +x /mnt/volume1/moonbeam-data/moonbeam
1
sudo chown -R moonbeam_service /mnt/volume1/moonbeam-data

Configuration File

The next step is to create the systemd configuration file. Depending on your needs there are a few different options between creating a full node or a pruning node. If you used the backups above you will need to have state-pruning set to archive. If you want a pruned node you can remove  - state-pruning=archive from the config file and the node will default to pruning the state to the last 256 blocks. More info about flags can be found here.

Note: Full nodes a.k.a “archive” nodes keep the full history of the chain.

Create the config file at /etc/systemd/system/moonbeam.service

1
sudo nano /etc/systemd/system/moonbeam.service

Add the following to the file changing YOUR-NODE-NAME to a name you want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[Unit]
Description="Moonbeam systemd service"
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=on-failure
RestartSec=10
User=moonbeam_service
SyslogIdentifier=moonbeam
SyslogFacility=local7
KillSignal=SIGHUP
ExecStart=/mnt/volume1/moonbeam-data/moonbeam \
     --execution wasm \
     --wasm-execution compiled \
     --state-pruning=archive \
     --trie-cache-size 0 \
     --base-path /mnt/volume1/moonbeam-data \
     --chain moonbeam \
     --name "YOUR-NODE-NAME" \
     -- \
     --execution wasm \
     --state-pruning 1000 \
     --name="YOUR-NODE-NAME (Embedded Relay)"

[Install]
WantedBy=multi-user.target

Save the file with Ctrl+s and close it with Ctrl+x

Running the Service

The last thing to do is enable and run the service.

1
systemctl enable moonbeam.service
1
systemctl start moonbeam.service

Check the output logs from the node with

1
journalctl -f -u moonbeam.service

Your node should now be running and should start back up if you ever reboot the system. Depending on if you downloaded the optional backups complete syncing of the node should take around 2-3 days.

If you ever need to stop the service do it with

1
systemctl stop moonbeam.service

and if you want to disable the service from starting on reboot

1
systemctl disable moonbeam.service

Telemetry

View your nodes telemetry by searching the name of your node at Polkadot’s Telemetry dashboard.

This post is licensed under CC BY 4.0 by the author.