Install and Configure 0G Storage KV Node
Overview
Section titled “Overview”The 0G Storage KV (Key-Value) service provides an interface for efficient data retrieval within the 0G ecosystem. This guide covers the end-to-end installation process, from compiling the source code to managing the service with systemd.
Prerequisites
Section titled “Prerequisites”Before proceeding, ensure your system meets the hardware requirements for 0G infrastructure and that you have a functional 0G Storage Node running.
Verify Rust Installation
Section titled “Verify Rust Installation”The 0G Storage KV node is written in Rust. Verify your installation:
rustc --versionIf Rust is not installed, use the official installer:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shBuild Storage KV from Source
Section titled “Build Storage KV from Source”Clone the official repository and compile the binary. This process may take several minutes depending on your CPU performance.
git clone https://github.com/0glabs/0g-storage-kv.gitcd 0g-storage-kvgit submodule update --initcargo build --releaseConfiguration
Section titled “Configuration”The node requires a config.toml file to define network endpoints and contract addresses.
Initialize Configuration File
Section titled “Initialize Configuration File”Copy the provided example configuration to the active run directory:
cp $HOME/0g-storage-kv/run/config_example.toml $HOME/0g-storage-kv/run/config.tomlExtract Environment Variables
Section titled “Extract Environment Variables”To ensure compatibility with your existing 0G Storage Node, extract the necessary parameters directly from your local configuration files:
STORAGE_PORT=$(grep -oP '(?<=rpc_listen_address = "0.0.0.0:)\d+(?=")' $HOME/0g-storage-node/run/config.toml)ZGS_LOG_SYNC_BLOCK=$(grep -oP '(?<=log_sync_start_block_number = )\d+' $HOME/0g-storage-node/run/config.toml)STORAGE_RPC_ENDPOINT=http://$(wget -qO- eth0.me):$STORAGE_PORTBLOCKCHAIN_RPC_ENDPOINT=$(sed -n 's/blockchain_rpc_endpoint = "\([^"]*\)"/\1/p' $HOME/0g-storage-node/run/config.toml)LOG_CONTRACT_ADDRESS=$(sed -n 's/log_contract_address = "\([^"]*\)"/\1/p' $HOME/0g-storage-node/run/config.toml)MINE_CONTRACT_ADDRESS=$(sed -n 's/mine_contract_address = "\([^"]*\)"/\1/p' $HOME/0g-storage-node/run/config.toml)JSON_PORT=$(sed -n '/\[json-rpc\]/,/^address/ s/address = "0.0.0.0:\([0-9]*\)".*/\1/p' $HOME/.0gchain/config/app.toml)JSON_RPC_ENDPOINT=http://$(wget -qO- eth0.me):$JSON_PORTUpdate Configuration File
Section titled “Update Configuration File”Apply the extracted variables to the config.toml file using sed:
sed -i "s|rpc_listen_address = .*|rpc_listen_address = \"0.0.0.0:6789\"|" $HOME/0g-storage-kv/run/config.tomlsed -i "s|zgs_node_urls = .*|zgs_node_urls = \"$STORAGE_RPC_ENDPOINT\"|" $HOME/0g-storage-kv/run/config.tomlsed -i "s|log_config_file = .*|log_config_file = \"$HOME/0g-storage-kv/run/log_config\"|" $HOME/0g-storage-kv/run/config.tomlsed -i "s|blockchain_rpc_endpoint = .*|blockchain_rpc_endpoint = \"$BLOCKCHAIN_RPC_ENDPOINT\"|" $HOME/0g-storage-kv/run/config.tomlsed -i "s|log_contract_address = .*|log_contract_address = \"$LOG_CONTRACT_ADDRESS\"|" $HOME/0g-storage-kv/run/config.tomlsed -i "s|log_sync_start_block_number = .*|log_sync_start_block_number = $ZGS_LOG_SYNC_BLOCK|" $HOME/0g-storage-kv/run/config.tomlService Management
Section titled “Service Management”Using systemd ensures the KV node runs in the background and restarts automatically upon failure.
Create Systemd Service
Section titled “Create Systemd Service”Create the service file using the following block:
sudo tee /etc/systemd/system/zgs-kv.service > /dev/null <<EOF[Unit]Description=0G Storage KV NodeAfter=network.target
[Service]User=$USERWorkingDirectory=$HOME/0g-storage-kv/runExecStart=$HOME/0g-storage-kv/target/release/zgs_kv --config $HOME/0g-storage-kv/run/config.tomlRestart=on-failureRestartSec=10LimitNOFILE=65535
[Install]WantedBy=multi-user.targetEOFLaunch the Node
Section titled “Launch the Node”Reload the daemon and enable the service:
sudo systemctl daemon-reloadsudo systemctl enable zgs-kvsudo systemctl start zgs-kvMonitoring and Maintenance
Section titled “Monitoring and Maintenance”Check Node Logs
Section titled “Check Node Logs”Monitor the real-time output of your KV node to verify synchronization and connection status:
sudo journalctl -u zgs-kv.service -fService Controls
Section titled “Service Controls”| Action | Command |
|---|---|
| Stop Node | sudo systemctl stop zgs-kv |
| Start Node | sudo systemctl start zgs-kv |
| Restart Node | sudo systemctl restart zgs-kv |
| Check Status | sudo systemctl status zgs-kv |