Step-by-Step Setting Up Your Own OKP4 Validator Node and Setting Up Monitoring!

NodeX Capital
7 min readJan 1, 2023

--

okp4 validator setup

Are you ready to become a part of the OKP4 community and help secure the network as a validator? If so, you’ll be glad to know that the OKP4 community has developed a number of resources specifically designed to help you succeed in your role.

One of the key responsibilities of a validator is to ensure the availability and performance of their node. That’s why the OKP4 community has created a validator documentation portal, filled with detailed guides and tutorials on how to set up and run a validator node here https://docs.okp4.network/docs/nodes/introduction, as well as best practices for validator operation.

But for now I will share the manual installation way to be able to run the okp4 validator based on my guide from github below https://github.com/nodexcapital/testnet/blob/main/okp4/manual_install.md

Okp4 Validator Setup — Manual Installation

##Hardware Requirements

  • 4x CPUs; the faster clock speed the better
  • 8GB RAM
  • 160GB of storage (SSD or NVME)
  • Permanent Internet connection (traffic will be minimal during testnet; 10Mbps will be plenty — for production at least 100Mbps is expected)

##Setting Up Variables

Here you have to put name of your moniker (validator) that will be visible in explorer : https://explorer.nodexcapital.com/okp4 and save into system

MONIKER="NodeX Validator" - Example Moniker

OKP4_PORT=24 - Example Custom Port
echo "export MONIKER=$MONIKER" >> $HOME/.bashrc
if [ ! $WALLET ]; then
echo "export WALLET=wallet" >> $HOME/.bashrc
fi
echo "export OKP4_CHAIN_ID=okp4-nemeton-1" >> $HOME/.bashrc
echo "export OKP4_PORT=${OKP4_PORT}" >> $HOME/.bashrc

source $HOME/.bashrc

##Update Packages

Updating packages refers to the process of installing the latest versions of software on a computer or server. This is typically done to ensure that the software is up to date and has the latest security patches and feature updates

sudo apt update && sudo apt upgrade -y

##Install dependencies

Installing dependencies refers to the process of installing additional software that is required by another piece of software in order to function properly. These additional pieces of software are known as dependencies.

sudo apt install curl tar wget clang pkg-config libssl-dev jq build-essential bsdmainutils git make ncdu gcc git jq chrony liblz4-tool -y

##Install Golang

Go is the process of setting up the Go programming language on your computer so that you can use it to develop software.

wget https://golang.org/dl/go1.19.3.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.19.3.linux-amd64.tar.gz

##Setting Path for Go

Setting the PATH environment variable for Go is the process of telling your operating system where the Go binary files are located on your computer.

export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin" >> ~/.bashrc

##Download & Build Binaries

Downloading and building binaries refers to the process of downloading the source code for a software application and compiling it into executable binary files that can be run on your computer.

cd $HOME
git clone https://github.com/okp4/okp4d.git
cd okp4d
git checkout v3.0.0
make install

##Configure Application

After we run all the commands above we need to configure our node by giving a command below so that the system can know if we have made some “default” changes, for example for keyring test & cutom port 24.

okp4d config chain-id $OKP4_CHAIN_ID
okp4d config keyring-backend test
okp4d config node tcp://localhost:${OKP4_PORT}657

##Initializing Application

This could refer to the process of setting up a container for running an app. This might involve pulling an app image from a container registry and starting the container with the appropriate environment variables and configuration

okp4d init $MONIKER --chain-id $OKP4_CHAIN_ID

##Download Genesis & Addrbook

  • Genesis: contains the initial state of a blockchain and specifies the initial set of validators or nodes.
  • Addrbook: contains a list of addresses and other information about the nodes on a blockchain network. Helps nodes communicate and find each other.
wget -qO $HOME/.okp4d/config/genesis.json "https://raw.githubusercontent.com/okp4/networks/main/chains/nemeton-1/genesis.json"
wget -O $HOME/.okp4d/config/addrbook.json "https://raw.githubusercontent.com/nodexcapital/testnet/main/okp4/addrbook.json"

##Setting Peers, Gas Prices & Seeds

  • Peers: other nodes on the blockchain network that a node can connect to and communicate with.
  • Gas prices: fees required to execute transactions on the blockchain, paid in the native cryptocurrency.
  • Seeds: nodes on the network that can be used as a starting point to discover other nodes
sed -i.bak -e "s/^minimum-gas-prices *=.*/minimum-gas-prices = \"0.0uknow\"/;" ~/.okp4d/config/app.toml
sed -i -e "s/^filter_peers *=.*/filter_peers = \"true\"/" $HOME/.okp4d/config/config.toml
external_address=$(wget -qO- eth0.me)
sed -i.bak -e "s/^external_address *=.*/external_address = \"$external_address:26656\"/" $HOME/.okp4d/config/config.toml
peers="f595a1386d5ca2e0d2cd81d3c6372c3bf84bbd16@65.109.31.114:2280,a49302f8999e5a953ebae431c4dde93479e17155@162.19.71.91:26656,dc14197ed45e84ca3afb5428eb04ea3097894d69@88.99.143.105:26656,79d179ea2e1fbdcc0c59a95ab7f1a0c48438a693@65.108.106.131:26706,501ad80236a5ac0d37aafa934c6ec69554ce7205@89.149.218.20:26656,5fbddca54548bf125ee96bb388610fe1206f087f@51.159.66.123:26656,769f74d3bb149216d0ab771d7767bd39585bc027@185.196.21.99:26656,024a57c0bb6d868186b6f627773bf427ec441ab5@65.108.2.41:36656,fff0a8c202befd9459ff93783a0e7756da305fe3@38.242.150.63:16656,2bfd405e8f0f176428e2127f98b5ec53164ae1f0@142.132.149.118:26656,bf5802cfd8688e84ac9a8358a090e99b5b769047@135.181.176.109:53656,dc9a10f2589dd9cb37918ba561e6280a3ba81b76@54.244.24.231:26656,085cf43f463fe477e6198da0108b0ab08c70c8ab@65.108.75.237:6040,803422dc38606dd62017d433e4cbbd65edd6089d@51.15.143.254:26656,b8330b2cb0b6d6d8751341753386afce9472bac7@89.163.208.12:26656"
sed -i.bak -e "s/^persistent_peers *=.*/persistent_peers = \"$peers\"/" $HOME/.okp4d/config/config.toml
seeds=""
sed -i.bak -e "s/^seeds =.*/seeds = \"$seeds\"/" $HOME/.okp4d/config/config.toml
sed -i 's/max_num_inbound_peers =.*/max_num_inbound_peers = 100/g' $HOME/.okp4d/config/config.toml
sed -i 's/max_num_outbound_peers =.*/max_num_outbound_peers = 100/g' $HOME/.okp4d/config/config.toml

##Custom Port 33 Okp4 Validator

A custom port is a network port that has been designated for a specific purpose or use. Network ports are numbered locations on a computer or network device that are used for transmitting and receiving data over a network.

sed -i.bak -e "s%^proxy_app = \"tcp://127.0.0.1:26658\"%proxy_app = \"tcp://127.0.0.1:${OKP4_PORT}658\"%; s%^laddr = \"tcp://127.0.0.1:26657\"%laddr = \"tcp://127.0.0.1:${OKP4_PORT}657\"%; s%^pprof_laddr = \"localhost:6060\"%pprof_laddr = \"localhost:${OKP4_PORT}060\"%; s%^laddr = \"tcp://0.0.0.0:26656\"%laddr = \"tcp://0.0.0.0:${OKP4_PORT}656\"%; s%^prometheus_listen_addr = \":26660\"%prometheus_listen_addr = \":${OKP4_PORT}660\"%" $HOME/.okp4d/config/config.toml
sed -i.bak -e "s%^address = \"tcp://0.0.0.0:1317\"%address = \"tcp://0.0.0.0:${OKP4_PORT}317\"%; s%^address = \":8080\"%address = \":${OKP4_PORT}080\"%; s%^address = \"0.0.0.0:9090\"%address = \"0.0.0.0:${OKP4_PORT}090\"%; s%^address = \"0.0.0.0:9091\"%address = \"0.0.0.0:${OKP4_PORT}091\"%" $HOME/.okp4d/config/app.toml

##Configuration Pruning & Set Indexer null

Enabling config pruning can be useful for reducing the storage requirements of a blockchain node and improving its performance.

A nullindexer is your best bet if you want to run the node anticipating that your disk won’t get full from storing the blockchain data like tx_index.db.

pruning="custom"
pruning_keep_recent="100"
pruning_keep_every="0"
pruning_interval="10"
sed -i -e "s/^pruning *=.*/pruning = \"$pruning\"/" $HOME/.okp4d/config/app.toml
sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"$pruning_keep_recent\"/" $HOME/.okp4d/config/app.toml
sed -i -e "s/^pruning-keep-every *=.*/pruning-keep-every = \"$pruning_keep_every\"/" $HOME/.okp4d/config/app.toml
sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"$pruning_interval\"/" $HOME/.okp4d/config/app.toml

indexer="null" && \
sed -i -e "s/^indexer *=.*/indexer = \"$indexer\"/" $HOME/.okp4d/config/config.toml

##Creating Serviceokp4d.service

Process of creating a new service or application that runs on background and start automatically when server rebooted

sudo tee /etc/systemd/system/okp4d.service > /dev/null <<EOF
[Unit]
Description=okp4d
After=network-online.target

[Service]
User=$USER
ExecStart=$(which okp4d) start
Restart=on-failure
RestartSec=3
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
EOF

##Register, Start Service & Logs

After everything is finished running, now is the time to start the okp4d application in the following way

sudo systemctl daemon-reload
sudo systemctl enable okp4d
sudo systemctl restart okp4d && sudo journalctl -u okp4d -f -o cat

Setting Up Monitoring : Grafana & Prometheus

Download Script and save as file monitoring-stack.sh or visit here.

Thanks to my friend https://roomit.xyz for providing this easy script!

#!/bin/bash
PROMETHEUS_CHECKSUM="3f558531c6a575d8372b576b7e76578a98e2744da6b89982ea7021b6f000cddd"
PROMETHEUS_USER="prometheus"
PROMETHEUS_VERSION="2.36.2"
PROMETHEUS_ARCH="linux-amd64"
PROMETHEUS_URL="https://github.com/prometheus/prometheus/releases/download/"

OPTIONS=$1
MONITORING=$2


function help(){
echo "monitoring-stack [deploy|uninstall] [grafana|prometheus]"
}

function env:load(){
if ! [ -f /etc/profile.d/user-env.sh ]
then
cat > /etc/profile.d/user-env.sh <<EOF
#!/bin/env
export PATH="$PATH:/usr/local/bin"
EOF
source /etc/profile.d/user-env.sh
else
source /etc/profile.d/user-env.sh
fi
}

function prometheus:deploy(){
check_user_prometheus=`id ${PROMETHEUS_USER}`
if [ $? -eq 1 ]
then
useradd --no-create-home --shell /bin/false ${PROMETHEUS_USER}
fi
[ -d /etc/prometheus ] && echo "Directory Exist" || mkdir -p /etc/prometheus && chown ${PROMETHEUS_USER}:${PROMETHEUS_USER} /etc/prometheus;
[ -d /var/lib/prometheus ] && echo "Directory Exist" || mkdir /var/lib/prometheus && chown ${PROMETHEUS_USER}:${PROMETHEUS_USER} /var/lib/prometheus;

if ! [ -f /usr/local/bin/prometheus ] && ! [ -f /usr/local/bin/promtool ]
then
if [ -f /opt/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}.tar.gz ]
then
echo "FilePrometheus Exist"
else
wget -c ${PROMETHEUS_URL}/v${PROMETHEUS_VERSION}/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}.tar.gz -O /opt/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}.tar.gz
fi
check_prometheus_checksum=`sha256sum /opt/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}.tar.gz | awk '{print $1}'`
if [ "${PROMETHEUS_CHECKSUM}" == "${check_prometheus_checksum}" ]
then
tar xvf /opt/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}.tar.gz -C /opt/
cp /opt/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}/prometheus /usr/local/bin/
cp /opt/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}/promtool /usr/local/bin/
cp -r /opt/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}/consoles /etc/prometheus/ && chown -R prometheus:prometheus /etc/prometheus/consoles
cp -r /opt/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}/console_libraries /etc/prometheus/ && chown -R prometheus:prometheus /etc/prometheus/console_libraries
cp -r /opt/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}/prometheus.yml /etc/prometheus/ && chown -R prometheus:prometheus /etc/prometheus/prometheus.yml
else
echo "Checksumming Failed, File Integrity ${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}.tar.gz not match"
fi
fi


if ! [ -f /etc/systemd/system/prometheus.service ]
then
cat >/etc/systemd/system/prometheus.service<<EOF
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
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
EOF
systemctl daemon-reload
fi


systemctl start prometheus
systemctl enable prometheus
systemctl status prometheus
}


function prometheus:uninstall(){
systemctl stop prometheus
systemctl disable prometheus

userdel ${PROMETHEUS_USER}
rm /usr/local/bin/prometheus
rm /usr/local/bin/promtool
rm /etc/systemd/system/prometheus.service
rm /etc/profile.d/user-env.sh
rm -rf /etc/prometheus/
rm -rf /var/lib/prometheus/
rm -rf /opt/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}
rm -rf /opt/${PROMETHEUS_USER}-${PROMETHEUS_VERSION}.${PROMETHEUS_ARCH}.tar.gz
}

function grafana:deploy(){
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" > /etc/apt/sources.list.d/grafana.list
apt update
apt install grafana -y
systemctl start grafana-server
systemctl enable grafana-server
}

function grafana:uninstall(){
systemctl disable grafana-server
systemctl stop grafana-server
apt purge grafana
}

check_os=`cat /etc/os-release | grep "NAME=\"Ubuntu\"" | wc -l`

if [ ${check_os} -eq 1 ]
then
env:load;
case "${OPTIONS}" in
deploy)
if [ "${MONITORING}" == "prometheus" ]
then
prometheus:deploy;
elif [ "${MONITORING}" == "grafana" ]
then
grafana:deploy;
else
help;
fi
;;
uninstall)
if [ "${MONITORING}" == "prometheus" ]
then
prometheus:uninstall;
elif [ "${MONITORING}" == "grafana" ]
then
grafana:uninstall;
else
help;
fi
;;
*)
help;
;;
esac
else
echo "Make sure your OS is Ubuntu"
fi

How To Use?

Install Grafana & Prometheus

bash monitoring-stack.sh grafana
bash monitoring-stack.sh prometheus

Services

systemctl start grafana-server prometheus
systemctl stop grafana-server prometheus
systemctl status grafana-server prometheus
systemctl restart grafana-server prometheus

Install Grafana Renderer

Grafana Renderer is plugin for render content and can send to media notification

Install NodeJS

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

Install Yarn

curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn

Install Grafana Renderer

wget https://github.com/grafana/grafana-image-renderer/archive/refs/heads/master.zip
unzip master.zip -d /opt/
mkdir -p /opt/grafana-plugin
mv /opt/grafana-image-renderer-master /opt/grafana-plugin/

Build & Create Service

yarn install --pure-lockfile
yarn run build
cat > /etc/systemd/system/grafana-render.service<<EOF
[Unit]
Description=Grafana instance
Documentation=http://docs.grafana.org
Wants=network-online.target
After=network-online.target
After=postgresql.service mariadb.service mysql.service

[Service]
User=grafana
Group=grafana
Type=simple
ExecStart=/usr/bin/node /opt/grafana-plugin/grafana-image-renderer-master/build/app.js server --port=8081

[Install]
WantedBy=multi-user.target
EOF

Register & Start Grafana Renderer

systemctl daemon-reload
systemctl start grafana-render

Install Plugin & Add in /etc/grafana/grafana.ini

grafana-cli plugins install grafana-image-renderer
[rendering]
server_url = http://localhost:8081/render
callback_url = http://localhost:3000/

Restart Grafana

systemctl restart grafana-server

--

--

NodeX Capital
NodeX Capital

Written by NodeX Capital

Hi, NodeX Capital is here! secure and reliable nodes validator. Find me at Discord : https://discord.gg/nodexcapital

No responses yet