Guide to Staking on Ethereum 2.0 (Ubuntu/Prater/Teku)

Warnings

Acknowledgements and Disclaimer

Support

Prerequisites

Note for Raspberry Pi Users

Requirements

Overview

Step 1 — Generate Staking Data

Download the Deposit Tool (Eth2 Deposit CLI)

$ cd ~
$ sudo apt install curl
$ curl -LO https://github.com/ethereum/eth2.0-deposit-cli/releases/download/v1.2.0/eth2deposit-cli-256ea21-linux-amd64.tar.gz
$ sudo tar xvf eth2deposit-cli-256ea21-linux-amd64.tar.gz
$ cd eth2deposit-cli-256ea21-linux-amd64

Run the Deposit Tool (Eth2 Deposit CLI)

$ sudo ./deposit new-mnemonic --num_validators NumberOfValidators --mnemonic_language=english --chain prater
deposit.exe new-mnemonic --num_validators NumberOfValidators --mnemonic_language=english --chain prater

Step 2 — Connect to the Server

# adduser <yourusername>
# usermod -aG sudo <yourusername>
# rsync --archive --chown=<yourusername>:<yourusername> ~/.ssh /home/<yourusername>

Step 3 — Update the Server

$ sudo apt update && sudo apt upgrade
$ sudo apt dist-upgrade && sudo apt autoremove
$ sudo reboot

Step 4 — Secure the Server

Configure the firewall

$ sudo ss -tulpn | grep ':<yourSSHportnumber>'
$ sudo ufw allow <yourSSHportnumber>/tcp
$ sudo nano /etc/ssh/sshd_config
$ sudo systemctl restart ssh
$ sudo ufw deny 22/tcp
$ sudo ufw allow 30303
$ sudo ufw allow 9000
$ sudo ufw allow 3000/tcp
$ sudo ufw allow 9090/tcp
$ sudo ufw enable
$ sudo ufw status numbered

Step 5 — Configure Timekeeping

$ timedatectl
$ sudo timedatectl set-ntp on
$ ntpq -p
$ sudo apt-get remove ntp

Step 6 — Install and Run Go Ethereum Node

Install Go Ethereum

$ sudo add-apt-repository -y ppa:ethereum/ethereum
$ sudo apt update
$ sudo apt install geth

Run Go Ethereum as a Background Service

$ sudo useradd --no-create-home --shell /bin/false goeth
$ sudo mkdir -p /var/lib/goethereum
$ sudo chown -R goeth:goeth /var/lib/goethereum
$ sudo nano /etc/systemd/system/geth.service
[Unit]
Description=Ethereum go client
After=network.target
Wants=network.target
[Service]
User=goeth
Group=goeth
Type=simple
Restart=always
RestartSec=5
ExecStart=geth --goerli --http --datadir /var/lib/goethereum
[Install]
WantedBy=default.target
$ sudo systemctl daemon-reload
$ sudo systemctl start geth
$ sudo systemctl status geth
$ sudo systemctl enable geth
$ sudo journalctl -fu geth.service
$ sudo systemctl stop geth
$ sudo nano /etc/systemd/system/geth.service
ExecStart=geth --goerli --http --datadir /var/lib/goethereum --bootnodes "enode://46add44b9f13965f7b9875ac6b85f016f341012d84f975377573800a863526f4da19ae2c620ec73d11591fa9510e992ecc03ad0751f53cc02f7c7ed6d55c7291@94.237.54.114:30313,enode://119f66b04772e8d2e9d352b81a15aa49d565590bfc9a80fe732706919f8ccd00a471cf8433e398c55c4862aadb4aadf3a010201483b87e8358951698aa0b6f07@13.250.50.139:30303"
$ sudo systemctl daemon-reload
$ sudo systemctl start geth
$ sudo journalctl -fu geth.service

Step 7 — Install Teku Dependencies

$ sudo apt install default-jre default-jdk
$ java --version
$ javac --version
ethstaker@ETH-STAKER-001:~$ java --version
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)
ethstaker@ETH-STAKER-001:~$ javac --version
javac 11.0.11

Step 8 — Clone and Build Teku

$ cd ~
$ git clone https://github.com/Consensys/teku.git
$ cd teku
$ sudo ./gradlew installDist

Step 9 — Copy the Teku Binary

$ cd ~
$ sudo cp -a teku/build/install/teku/. /usr/local/bin/teku

Step 10 — Configure the Beacon Node and Validator

Setup Accounts and Directories

$ sudo useradd --no-create-home --shell /bin/false teku
$ sudo mkdir -p /var/lib/teku
$ sudo mkdir -p /etc/teku
$ sudo cp -a /$HOME/<ValidatorKeysPath> /var/lib/teku
$ cd /var/lib/teku/validator_keys
$ ls
$ sudo rm <DepositDataFileName>

Create the Validator Password File(s)

$ ls /var/lib/teku/validator_keys
$ sudo nano /var/lib/teku/validator_keys/<jsonfilename>.txt

Set Permissions

$ sudo chown -R teku:teku /var/lib/teku
$ sudo chown -R teku:teku /etc/teku
$ ls -dl /var/lib/teku; ls -dl /etc/teku
$ sudo chmod -R 700 /var/lib/teku/validator_keys
$ sudo ls -lh /var/lib/teku/validator_keys

Create the Teku Configuration File

$ sudo nano /etc/teku/teku.yaml
data-base-path: "/var/lib/teku"network: "prater"eth1-endpoint: "http://127.0.0.1:8545/"initial-state: "https://20YexISmkpKSGgkR2Dak9NDbSqZ:77c62480c2af841241edc5ea2e86dd53@eth2-beacon-prater.infura.io/eth/v1/debug/beacon/states/finalized"validator-keys: "/var/lib/teku/validator_keys:/var/lib/teku/validator_keys"validators-graffiti: "<yourGraffitiString>"p2p-port: 9000log-destination: CONSOLEmetrics-enabled: true
metrics-port: 8008
rest-api-enabled: true
rest-api-docs-enabled: true
$ sudo systemctl daemon-reload
$ sudo systemctl stop teku
$ sudo rm -rf /var/lib/teku/beacon
$ sudo systemctl start teku

Create and Configure the Teku Service

$ sudo nano /etc/systemd/system/teku.service
[Unit]
Description=Teku Client
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=teku
Group=teku
Restart=always
RestartSec=5
Environment="JAVA_OPTS=-Xmx4g"
ExecStart=/usr/local/bin/teku/bin/teku --config-file=/etc/teku/teku.yaml
[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload
$ sudo systemctl start teku
$ sudo systemctl status teku
$ sudo systemctl enable teku
$ sudo journalctl -fu teku.service
Started Teku Client.
...
INFO - Loading 2 validator keys...
INFO - BLS: loaded BLST library
INFO - Loaded 2 Validators: 96a349b, b7f51b6
...
INFO - Sync Event *** Current slot: 30174, Head slot: 54, Connected peers: 1
INFO - Sync Event *** Current slot: 30175, Head slot: 92, Connected peers: 6
INFO - Sync Event *** Current slot: 30176, Head slot: 128, Connected peers: 8
INFO - Sync Event *** Current slot: 30177, Head slot: 160, Connected peers: 10

Step 11 — Fund the Validator Keys

Get Göerli ETH

Complete the Launchpad

Check the Status of Your Validators

Step 12 — Monitoring: Install Prometheus

Create User Accounts

$ sudo useradd --no-create-home --shell /bin/false prometheus
$ sudo useradd --no-create-home --shell /bin/false node_exporter

Create Directories

$ sudo mkdir /etc/prometheus
$ sudo mkdir /var/lib/prometheus
$ sudo chown -R prometheus:prometheus /etc/prometheus
$ sudo chown -R prometheus:prometheus /var/lib/prometheus

Download Prometheus software

$ cd ~
$ curl -LO https://github.com/prometheus/prometheus/releases/download/v2.29.2/prometheus-2.29.2.linux-amd64.tar.gz
$ tar xvf prometheus-2.29.2.linux-amd64.tar.gz
$ sudo cp prometheus-2.29.2.linux-amd64/prometheus /usr/local/bin/
$ sudo cp prometheus-2.29.2.linux-amd64/promtool /usr/local/bin/
$ sudo chown -R prometheus:prometheus /usr/local/bin/prometheus
$ sudo chown -R prometheus:prometheus /usr/local/bin/promtool
$ sudo cp -r prometheus-2.29.2.linux-amd64/consoles /etc/prometheus
$ sudo cp -r prometheus-2.29.2.linux-amd64/console_libraries /etc/prometheus
$ sudo chown -R prometheus:prometheus /etc/prometheus/consoles
$ sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
$ rm -rf prometheus-2.29.2.linux-amd64.tar.gz prometheus-2.29.2.linux-amd64

Edit the Configuration File

$ sudo nano /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "teku"
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets: ["localhost:8008"]
$ sudo chown -R prometheus:prometheus /etc/prometheus/prometheus.yml
$ sudo -u prometheus /usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
level=info ts=2021-09-06T16:57:40.941Z caller=main.go:784 msg="Server is ready to receive web requests."

Set Prometheus to Auto-Start as a Service

$ sudo nano /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=always
RestartSec=5
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload
$ sudo systemctl start prometheus
$ sudo systemctl status prometheus
$ sudo systemctl enable prometheus

Step 13 — Install Node Exporter

$ cd ~
$ curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
$ tar xvf node_exporter-1.2.2.linux-amd64.tar.gz
$ sudo cp node_exporter-1.2.2.linux-amd64/node_exporter /usr/local/bin
$ sudo chown -R node_exporter:node_exporter /usr/local/bin/node_exporter
$ rm -rf node_exporter-1.2.2.linux-amd64.tar.gz node_exporter-1.2.2.linux-amd64

Set Node Exporter to Auto-Start as a Service

$ sudo nano /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload
$ sudo systemctl start node_exporter
$ sudo systemctl status node_exporter
$ sudo systemctl enable node_exporter

Test Prometheus and Node Exporter (Optional)

http://<yourserverip>:9090/new/graph?g0.expr=node_memory_MemFree_bytes&g0.tab=1&g0.stacked=0&g0.range_input=1h

Step 14 — Monitoring: Install Grafana

$ wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
$ sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
$ sudo apt update
$ apt-cache policy grafana
grafana:
Installed: (none)
Candidate: 8.1.2
Version table:
8.1.2 500
500 https://packages.grafana.com/oss/deb stable/main amd64 Packages
8.1.1 500
500 https://packages.grafana.com/oss/deb stable/main amd64
...
$ sudo apt install grafana
$ sudo systemctl start grafana-server
$ sudo systemctl status grafana-server
$ sudo systemctl enable grafana-server

Configure Grafana Login

Configure the Grafana Data Source

Add data source screen.
Data source configuration.
Data source is confirmed working.

Import a Grafana Dashboard

Final Remarks and Recommended Next Steps

Further Reading

Appendix A — Updating Geth

$ sudo systemctl stop teku
$ sudo systemctl stop geth
$ sudo apt update && upgrade
$ sudo systemctl start geth
$ sudo systemctl status geth # <-- Check for errors
$ sudo journalctl -f -u geth # <-- Monitor
$ sudo systemctl start teku
$ sudo systemctl status teku # <-- Check errors
$ sudo journalctl -fu teku # <-- Monitor

Appendix B — Updating Teku

$ cd ~
$ sudo rm -r teku # <-- Remove any old teku files
# Get latest version of Teku and build it
$ git clone https://github.com/Consensys/teku.git
$ cd teku
$ sudo ./gradlew installDist
# Stop teku service, delete old files, copy new files
$ sudo systemctl stop teku
$ sudo rm -r /usr/local/bin/teku
$ sudo cp -a teku/build/install/teku/. /usr/local/bin/teku
# Start the teku service and monitor
$ sudo systemctl start teku
$ sudo systemctl status teku
$ sudo journalctl -fu teku

Appendix C — Adding Validators

Generate Deposit Data

$ sudo ./deposit existing-mnemonic --validator_start_index <ValidatorStartIndex> --num_validators <NumberOfValidators> --chain prater
deposit.exe existing-mnemonic --validator_start_index <ValidatorStartIndex> --num_validators <NumberOfValidators> --chain prater

Copy the Validator Keystore Files

$ sudo systemctl stop teku
$ sudo chown -R <yourusername>:<yourusername> /var/lib/teku
$ sudo cp -a /$HOME/<ValidatorKeysPath> /var/lib/teku
$ cd /var/lib/teku/validator_keys
$ ls
$ sudo rm <DepositDataFileName>

Create the Validator Password File(s)

$ ls /var/lib/teku/validator_keys
$ sudo nano /var/lib/teku/validator_keys/<jsonfilename>.txt
$ sudo chown -R teku:teku /var/lib/teku
$ sudo chmod -R 700 /var/lib/teku/validator_keys
$ sudo ls -lh /var/lib/teku/validator_keys
$ sudo systemctl start teku
$ sudo systemctl status teku # <-- Check errors
$ sudo journalctl -fu teku # <-- Monitor
...
INFO - Loading 4 validator keys...
...
INFO - Loaded 4 Validators: 8d7605e, 957ae4f, b477469, 898ef3d

Appendix D — Exiting Validators

$ /usr/local/bin/teku/bin/teku voluntary-exit --beacon-node-api-endpoint=http://127.0.0.1:5051 --validator-keys=/var/lib/teku/validator_keys/keystore-m_12381_3600_0_0_0-1606061625.json:/var/lib/teku/validator_keys/keystore-m_12381_3600_0_0_0-1606061625.txt
$ /usr/local/bin/teku/bin/teku voluntary-exit --beacon-node-api-endpoint=http://127.0.0.1:5051 --validator-keys=/var/lib/teku/validator_keys:/var/lib/teku/validator_keys

Appendix E — Expanding the Logical Volume

$ sudo lvdisplay # <-- Check your logical volume size
$ sudo lvm
> lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
> lvextend -l +100%FREE -r /dev/ubuntu-vg/ubuntu-lv
> exit
$ sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
$ df -h # <-- Check results

--

--

--

Passionate about Ethereum and decentralized technology.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Somer Esat

Somer Esat

Passionate about Ethereum and decentralized technology.

More from Medium

Olympus DAO Forks crash, what happened and is it over ?

What crypto projects do I think will do well in the coming years as we go into 2022?

Tokenized Bitcoins on Ethereum: Part 4

What can we Learn from the Solana Wormhole Hack?