How to Set Up a Bitcoin Mainnet Node on CentOS

Β·

Setting up a Bitcoin mainnet node is a foundational step for developers, blockchain enthusiasts, and enterprises seeking direct access to the Bitcoin network. Running your own node enhances privacy, security, and contributes to the decentralization of the network. This guide walks you through deploying a full Bitcoin node on CentOS 7.2, including installation, configuration, synchronization monitoring, and RPC API usage β€” all while ensuring optimal performance and reliability.

Whether you're integrating blockchain data into applications or exploring consensus mechanisms, hosting a node gives you unfettered access to real-time blockchain data. Let’s dive into the process step by step.


Prerequisites for Bitcoin Node Setup

Before installing the Bitcoin Core software, ensure your server meets the following requirements:

πŸ‘‰ Learn how to optimize blockchain data retrieval with secure infrastructure.


Step 1: Download and Install Bitcoin Core

Begin by downloading the official Bitcoin Core binary from bitcoin.org. We’ll use version 0.17.0.1 in this tutorial, though newer stable releases are also compatible with similar steps.

cd /opt/
wget https://bitcoin.org/bin/bitcoin-core-0.17.0.1/bitcoin-0.17.0.1-x86_64-linux-gnu.tar.gz

Once downloaded, extract the archive:

tar zxf bitcoin-0.17.0.1-x86_64-linux-gnu.tar.gz

To simplify future upgrades, create symbolic links:

ln -fs /opt/bitcoin-0.17.0 /opt/bitcoin
ln -fs /opt/bitcoin/bin/bitcoind /usr/local/bin/bitcoind
ln -fs /opt/bitcoin/bin/bitcoin-cli /usr/local/bin/bitcoin-cli

These symlinks allow you to upgrade binaries without changing environment paths.


Step 2: Configure the Bitcoin Node

Proper configuration ensures your node runs securely and efficiently.

First, create a dedicated data directory on your larger storage volume:

mkdir -p /data/btc_data

Then, set up the configuration file:

mkdir ~/.bitcoin
vim ~/.bitcoin/bitcoin.conf

Add the following content to ~/.bitcoin/bitcoin.conf:

datadir=/data/btc_data
dbcache=10240
txindex=1
rpcuser=btc
rpcpassword=btc2019
daemon=1
server=1
rest=1
rpcbind=0.0.0.0:8332
rpcallowip=0.0.0.0/0
deprecatedrpc=accounts

Key Configuration Parameters Explained

πŸ” Security Tip: Exposing RPC ports publicly (0.0.0.0) poses risks. For production environments, restrict rpcallowip to trusted IPs or use SSH tunneling.

Step 3: Start the Bitcoin Daemon

Launch the node in the background:

bitcoind -daemon

You should see output confirming that Bitcoin Core has started successfully.

To verify it's running:

ps aux | grep bitcoind

Step 4: Monitor Blockchain Synchronization

After startup, the node begins downloading and validating the entire blockchain from genesis. This can take several hours to days depending on hardware.

Check synchronization status using:

bitcoin-cli getblockchaininfo

Look for the "blocks" field and compare it with the latest block height on public explorers like BTC.com or Blockchain.com.

You can also get mining-related stats:

bitcoin-cli getmininginfo

For quick terminal-based progress checks:

# Get current block height
bitcoin-cli getblockchaininfo | grep '"blocks"' | awk '{print $2}' | tr -d ','

Synchronization is complete when "blocks" equals "headers" in the getblockchaininfo output.

πŸ‘‰ Discover how real-time blockchain data powers decentralized applications today.


Step 5: Interact via RPC API

Once synced, you can query and interact with the blockchain programmatically using JSON-RPC.

Example: Query mining info via curl:

curl -s -X POST --user btc:btc2019 \
  -H 'content-type: text/plain;' http://127.0.0.1:8332/ \
  --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getmininginfo", "params": [] }'

Extract just the block height:

curl -s -X POST --user btc:btc2019 \
  -H 'content-type: text/plain;' http://127.0.0.1:8332/ \
  --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getmininginfo", "params": [] }' \
  | awk -F '[:,]' '{print $3}'

Ensure the username and password match those in bitcoin.conf.


Common Issues and Troubleshooting

❌ Cannot Obtain Lock on Wallet Directory

If you receive a lock error upon restart:

Cannot obtain a lock on wallet directory

Delete the stale lock file:

rm /data/btc_data/.lock

Then restart the daemon.

⚠️ Never delete .lock files while bitcoind is running β€” this may corrupt data.

❌ Incorrect RPC Password

Double-check credentials in both bitcoin.conf and your curl/client scripts.

Use strong passwords in production and avoid defaults like btc:btc2019.

Default Data Location

If datadir is not specified, Bitcoin stores data in ~/.bitcoin. Always define a custom path for better disk management.


Frequently Asked Questions (FAQ)

Q: How long does it take to sync a Bitcoin full node?
A: Initial synchronization typically takes 24 to 72 hours, depending on internet speed, disk I/O (SSD vs HDD), and available RAM.

Q: Is txindex=1 required?
A: Only if you need to query arbitrary transactions not tied to wallet addresses. It increases disk usage and sync time but is essential for explorers or analytics tools.

Q: Can I run this node securely behind a firewall?
A: Yes. Disable public RPC access by removing rpcbind=0.0.0.0 and rpcallowip=0.0.0.0/0, then use SSH tunnels for remote management.

Q: What happens after Bitcoin Core version 0.18 removes account support?
A: The deprecatedrpc=accounts flag temporarily restores backward compatibility. New applications should use label-based APIs instead.

Q: How much storage will the blockchain need in the future?
A: As of 2025, the blockchain exceeds 500GB and grows roughly 50–70GB per year. Plan for expansion accordingly.

Q: Can I use this node for wallet operations?
A: Yes β€” once synced, you can create wallets, send/receive BTC, and sign transactions using bitcoin-cli.


Final Thoughts

Running a Bitcoin mainnet node on CentOS provides unparalleled control over your interaction with the world’s most robust decentralized network. From validating transactions independently to powering dApps with real-time data, a self-hosted node is an indispensable tool.

Core keywords naturally integrated throughout: Bitcoin mainnet node, CentOS Bitcoin setup, bitcoind configuration, Bitcoin Core installation, blockchain synchronization, RPC API access, full node setup, txindex enable.

As blockchain technology evolves, maintaining infrastructure literacy becomes increasingly valuable β€” especially when paired with platforms that bridge traditional finance and crypto ecosystems.

πŸ‘‰ Explore advanced tools that complement your self-hosted node infrastructure.