0G Storage Node Guide
Hello. In the previous tutorial, we implemented a validator with a light snapshot that took up little space. Now we want to implement a storage node on the same server.
To run the Node Validator, refer to the tutorial below. My suggestion is to run both.
The prerequisites are the same. If you have more hard drives, you have less risk of running out of space.
- Memory: 16 GB RAM
- CPU: 4 cores
- Disk: 500GB / 1T NVME SSD
- Bandwidth: 500 MBps for Download / Upload
START
sudo apt-get update
sudo apt-get install clang cmake build-essentialIf you are asked a question along the way, press the y key.
cd $HOME && \
ver="1.22.0" && \
wget "https://golang.org/dl/go$ver.linux-amd64.tar.gz" && \
sudo rm -rf /usr/local/go && \
sudo tar -C /usr/local -xzf "go$ver.linux-amd64.tar.gz" && \
rm "go$ver.linux-amd64.tar.gz" && \
echo "export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin" >> ~/.bash_profile && \
source ~/.bash_profile && \
go versioncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shEnter
. "$HOME/.cargo/env"git clone https://github.com/0glabs/0g-storage-node.gitcd 0g-storage-node
git checkout v0.8.4
git submodule update --initsudo apt install cargo
sudo apt update
sudo apt install -y pkg-config libssl-dev
cargo build --releaseIt may take a while.
👾 If you receive a warning, you can use the following codes:
unset OPENSSL_DIR
cargo clean
cargo build --release..
wget -O $HOME/0g-storage-node/run/config-testnet-turbo.toml https://josephtran.co/config-testnet-turbo.tomlprintf '\033[34mEnter your private key: \033[0m' && read -s PRIVATE_KEYSo enter the private key here. I suggest you enter the validator wallet.
To get the private key, you can add 24 words in Metamask or OKX Wallet and then remove the private key.
sed -i 's|^\s*#\?\s*miner_key\s*=.*|miner_key = "'"$PRIVATE_KEY"'"|' $HOME/0g-storage-node/run/config-testnet-turbo.toml && echo -e "\033[32mPrivate key has been successfully added to the config file.\033[0m"grep -E "^(network_dir|network_enr_address|network_enr_tcp_port|network_enr_udp_port|network_libp2p_port|network_discovery_port|rpc_listen_address|rpc_enabled|db_dir|log_config_file|log_contract_address|mine_contract_address|reward_contract_address|log_sync_start_block_number|blockchain_rpc_endpoint|auto_sync_enabled|find_peer_timeout)" $HOME/0g-storage-node/run/config-testnet-turbo.tomlSnapshot
We download snapshots to speed up syncing.
sudo systemctl stop zgssudo apt-get update
sudo apt-get install wget lz4 aria2 pv -ycd $HOME
rm storage_0gchain_snapshot.lz4
aria2c -x 16 -s 16 -k 1M https://josephtran.co/storage_0gchain_snapshot.lz4Skip this section if you don’t need it.
This process will take some time. If you think your internet might be down, redirect it to screen.
apt install screen screen -S snapshotNow run the snapshot download commands.
Get Fmusicmc’s stories in your inbox
Join Medium for free to get updates from this writer.
And navigate to the background with control+A+D
To see the screen, type the code below.
screen -R snapshotExtract
rm -rf $HOME/0g-storage-node/run/db
lz4 -c -d storage_0gchain_snapshot.lz4 | pv | tar -x -C $HOME/0g-storage-node/runStart Node
sudo tee /etc/systemd/system/zgs.service > /dev/null <<EOF
[Unit]
Description=ZGS Node
After=network.target
[Service]
User=$USER
WorkingDirectory=$HOME/0g-storage-node/run
ExecStart=$HOME/0g-storage-node/target/release/zgs_node --config $HOME/0g-storage-node/run/config-testnet-turbo.toml
Restart=on-failure
RestartSec=10
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOFsudo systemctl daemon-reload && \
sudo systemctl enable zgs && \
sudo systemctl restart zgs && \
sudo systemctl status zgsControl +C
Logs
tail -f ~/0g-storage-node/run/log/zgs.log.$(date +%Y-%m-%d) | grep -v "discv5\|network\|router\|Peer"while true; do
response=$(curl -s -X POST http://localhost:5678 -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"zgs_getStatus","params":[],"id":1}')
logSyncHeight=$(echo $response | jq '.result.logSyncHeight')
connectedPeers=$(echo $response | jq '.result.connectedPeers')
echo -e "logSyncHeight: \033[32m$logSyncHeight\033[0m, connectedPeers: \033[34m$connectedPeers\033[0m"
sleep 5;
done







