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

Image for post
Image for post

***
NOTE: This guide is now deprecated. Please use the newer version targeting the Pyrmont testnet.

WARNING

Acknowledgements and Disclaimer

Prerequisites

Note for Raspberry Pi Users

Requirements

Overview

Image for post
Image for post

***
NOTE: This guide is now deprecated. Please use the newer version targeting the Pyrmont testnet.

Step 1 — Secure Your System

Configure the firewall

# ufw allow 22/tcp
# ufw allow 30303/tcp
# ufw allow 30303/udp
# ufw allow 9001/tcp
# ufw allow 9001/udp
# ufw allow 3000/tcp
# ufw allow 9090/tcp
# ufw enable
# ufw status numbered
Image for post
Image for post

Create a new user and grant administrative privileges

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

Step 2 — Update Your System

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

***
NOTE: This guide is now deprecated. Please use the newer version targeting the Pyrmont testnet.

Step 3 — Install and Run Go Ethereum Node

Install Go Ethereum

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

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
Image for post
Image for post
$ sudo systemctl daemon-reload
$ sudo systemctl start geth
$ sudo systemctl status geth
Image for post
Image for post
$ sudo systemctl enable geth
$ sudo journalctl -f -u 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 -f -u geth.service
Image for post
Image for post
Image for post
Image for post

Step 4— Prepare the Validator Deposit Data

Get Goerli ETH

Generate Validator Keys

$ cd ~
$ git clone https://github.com/ethereum/eth2.0-deposit-cli.git
$ cd eth2.0-deposit-cli
$ python3 -V
$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt update
$ sudo apt install python3.7
$ sudo apt install python3-pip
$ sudo ./deposit.sh install
$ ./deposit.sh new-mnemonic --num_validators <numberofvalidators> --mnemonic_language=english --chain medalla
Success!
Your keys can be found at: /home/<yourusername>/eth2.0-deposit-cli/validator_keys

Copy Deposit Data File

Fund the Validator Keys

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Check the Status of Your Validators

Image for post
Image for post

***
NOTE: This guide is now deprecated. Please use the newer version targeting the Pyrmont testnet.

Step 5— Install Dependencies

$ sudo apt install default-jre default-jdk
$ java --version
$ javac --version

Step 6 — Clone and Build Teku

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

Step 7 — Copy Teku Build Output

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

***
NOTE: This guide is now deprecated. Please use the newer version targeting the Pyrmont testnet.

Step 8— 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 chown -R teku:teku /var/lib/teku
$ sudo chown -R teku:teku /etc/teku
$ sudo cp -a /$HOME/eth2.0-deposit-cli/validator_keys /var/lib/teku

Create a Validator Password File

$ sudo nano /etc/teku/validators-password.txt
Image for post
Image for post

Create the Teku Configuration File

$ sudo nano /etc/teku/teku.yaml
data-path: "/var/lib/teku"network: "medalla"eth1-endpoint: "http://127.0.0.1:8545/"validators-key-files: [
"/var/lib/teku/validator_keys/keystore-m_*.json",
"/var/lib/teku/validator_keys/keystore-m_*.json",
...
"/var/lib/teku/validator_keys/keystore-m_*.json",
"/var/lib/teku/validator_keys/keystore-m_*.json"
]
validators-key-password-files: [
"/etc/teku/validators-password.txt",
"/etc/teku/validators-password.txt",
...
"/etc/teku/validators-password.txt",
"/etc/teku/validators-password.txt"
]
validators-graffiti: "<yourPOAPstring>"p2p-port: 9001log-destination: CONSOLEmetrics-enabled: true
metrics-port: 8008
rest-api-enabled: true
rest-api-docs-enabled: true
$ cd /var/lib/teku/validator_keys
$ ls
Image for post
Image for post

Create and Configure the Service

$ sudo nano /etc/systemd/system/teku.service
[Unit]
Description=Teku Beacon Node
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=teku
Group=teku
Restart=always
RestartSec=5
ExecStart=/usr/local/teku/bin/teku -c /etc/teku/teku.yaml
[Install]
WantedBy=multi-user.target
Image for post
Image for post
$ sudo systemctl daemon-reload
$ sudo systemctl start teku
$ sudo systemctl status teku
Image for post
Image for post
$ sudo systemctl enable teku
$ sudo journalctl -f -u teku.service
Started Teku Beacon Node.
INFO Configuring logging for destination: console
INFO Logging includes events: true
INFO Logging includes validator duties: true
INFO Logging includes color: true
INFO - Teku version: teku/v0.12.3-dev-1b9be173/linux-x86_64/-ubuntu-openjdk64bitservervm-java-11
INFO - Loading 9 validator keys...
INFO - Successfully loaded native BLS library
INFO - Loaded 9 Validators: 80fafaf, b250168, a39fe65, acdfd94, 84bfa11, 80720b3, a240cb7, 845b9e0, b033401
INFO - Using default implementation for ThreadExecutor
INFO - Job execution threads will use class loader of thread: main
...
INFO - Using data path: /var/lib/teku
INFO - Starting metrics http service on 127.0.0.1:8008
INFO - Data directory set to: /var/lib/teku
INFO - Metrics service started and listening on 8008:8008
INFO - Initializing storage
INFO - Storage initialization complete
...
INFO - Slot Event *** Slot: 48641, Block: ... empty, Epoch: 1520, Finalized checkpoint: 40, Finalized root: 285a29..250e, Peers: 0
INFO - Eth1 tracker successfully caught up to chain head
INFO - Slot Event *** Slot: 48642, Block: ... empty, Epoch: 1520, Finalized checkpoint: 40, Finalized root: 285a29..250e, Peers: 0
INFO - Slot Event *** Slot: 48643, Block: ... empty, Epoch: 1520, Finalized checkpoint: 40, Finalized root: 285a29..250e, Peers: 0
INFO - Sync Event *** Current slot: 48643, Head slot: 1351, Connected peers: 1

***
NOTE: This guide is now deprecated. Please use the newer version targeting the Pyrmont testnet.

Step 9— Updating Teku

$ cd teku
$ git pull
$ ./gradlew installDist
$ sudo systemctl stop teku
$ sudo rm -r /usr/local/teku
$ sudo cp -a ~/teku/build/install/teku/. /usr/local/teku
$ sudo systemctl start teku

Step 10— 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.20.0/prometheus-2.20.0.linux-amd64.tar.gz
$ tar xvf prometheus-2.20.0.linux-amd64.tar.gz
$ sudo cp prometheus-2.20.0.linux-amd64/prometheus /usr/local/bin/
$ sudo cp prometheus-2.20.0.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.20.0.linux-amd64/consoles /etc/prometheus
$ sudo cp -r prometheus-2.20.0.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.20.0.linux-amd64.tar.gz prometheus-2.20.0.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-dev"
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=2020-08-11T06:43:43.216Z caller=main.go:805 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
level=info ts=2020-08-11T06:43:43.217Z caller=main.go:833 msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml
level=info ts=2020-08-11T06:43:43.219Z caller=main.go:652 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
Image for post
Image for post
$ sudo systemctl enable prometheus

Step 11 — Install Node Exporter

$ cd ~
$ curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
$ tar xvf node_exporter-1.0.1.linux-amd64.tar.gz
$ sudo cp node_exporter-1.0.1.linux-amd64/node_exporter /usr/local/bin
$ sudo chown -R node_exporter:node_exporter /usr/local/bin/node_exporter
$ rm -rf node_exporter-1.0.1.linux-amd64.tar.gz node_exporter-1.0.1.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
Image for post
Image for post
$ 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 12 — 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: 7.1.3
Version table:
7.1.3 500
500 https://packages.grafana.com/oss/deb stable/main amd64 Packages
7.1.2 500
500 https://packages.grafana.com/oss/deb stable/main amd64 Packages
7.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
Image for post
Image for post
$ sudo systemctl enable grafana-server

Configure Grafana Login

Configure the Grafana Data Source

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

Import a Grafana Dashboard

Image for post
Image for post
Image for post
Image for post

Final Remarks

***
NOTE: This guide is now deprecated. Please use the newer version targeting the Pyrmont testnet.

Written by

Passionate about Ethereum and decentralized technology.

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