CentOS - Bitcoin

Install

from https://bitcoincore.org/en/download/ :

# useradd -m bitcoin
# passwd bitcoin
# su bitcoin

$ cd
$ wget https://bitcoincore.org/bin/bitcoin-core-25.1/bitcoin-25.1-x86_64-linux-gnu.tar.gz
$ tar xvzf ./bitcoin-25.1-x86_64-linux-gnu.tar.gz

copy (as root) to /usr/local

create RPC user/password:

# cd
# wget https://raw.githubusercontent.com/bitcoin/bitcoin/master/share/rpcauth/rpcauth.py
# chmod +x ./rpcauth.py
# ./rpcauth.py <rpc_username>

create configuration, service and bitcoin data directory:

# mkdir /etc/bitcoin
# vim /etc/bitcoin/bitcoin.conf

bind=<public_ip>
rpcbind=127.0.0.1
#rpcbind=<public_ip_or_some_other_ip>
rpcallowip=127.0.0.1/32
#allow RPC from subnet
#rpcallowip=10.8.11.0/24
#allow RPC from exact IP
#rpcallowip=<public_ip_of_RPC_client>/32

rpcauth=<rpc_username>:<rpc_password_encoded>
#rpcauth=<another_rpc_username>:<another_rpc_password_encoded>
server=1

# optional, can be one of following options: 1 (means all debugs), net, tor, mempool, http, bench, zmq, walletdb, rpc, estimatefee, addrman, selectcoins, reindex, cmpctblock, rand, prune, proxy, mempoolrej, libevent, coindb, qt, leveldb, validation
#debug=rpc

# optional - where we want to publish zeromq stream
#zmqpubrawtx=tcp://<public_ip_or_some_other_ip>:3000

create systemd unit (taken from https://github.com/bitcoin/bitcoin/blob/master/contrib/init/bitcoind.service - only thing changed is the binary location in /usr/local/bin) :

# mkdir /var/lib/bitcoin
# chown bitcoin.bitcoin /var/lib/bitcoin

# vim /usr/lib/systemd/system/bitcoind.service

# It is not recommended to modify this file in-place, because it will
# be overwritten during package upgrades. If you want to add further
# options or overwrite existing ones then use
# $ systemctl edit bitcoind.service
# See "man systemd.service" for details.

# Note that almost all daemon options could be specified in
# /etc/bitcoin/bitcoin.conf, but keep in mind those explicitly
# specified as arguments in ExecStart= will override those in the
# config file.

[Unit]
Description=Bitcoin daemon
Documentation=https://github.com/bitcoin/bitcoin/blob/master/doc/init.md

# https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/local/bin/bitcoind -pid=/run/bitcoind/bitcoind.pid \
                            -conf=/etc/bitcoin/bitcoin.conf \
                            -datadir=/var/lib/bitcoind \
                            -startupnotify='systemd-notify --ready' \
                            -shutdownnotify='systemd-notify --stopping'

# Make sure the config directory is readable by the service user
PermissionsStartOnly=true
ExecStartPre=/bin/chgrp bitcoin /etc/bitcoin

# Process management
####################

Type=notify
NotifyAccess=all
PIDFile=/run/bitcoind/bitcoind.pid

Restart=on-failure
TimeoutStartSec=infinity
TimeoutStopSec=600

# Directory creation and permissions
####################################

# Run as bitcoin:bitcoin
User=bitcoin
Group=bitcoin

# /run/bitcoind
RuntimeDirectory=bitcoind
RuntimeDirectoryMode=0710

# /etc/bitcoin
ConfigurationDirectory=bitcoin
ConfigurationDirectoryMode=0710

# /var/lib/bitcoind
StateDirectory=bitcoind
StateDirectoryMode=0710

# Hardening measures
####################

# Provide a private /tmp and /var/tmp.
PrivateTmp=true

# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full

# Deny access to /home, /root and /run/user
ProtectHome=true

# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true

# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true

# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true

[Install]
WantedBy=multi-user.target

Please note: if we will be using wallet notify script running something in /home directory, we need to comment (or change to false) option `ProtectHome=true` in systemd unit service file above ^^^.

Add to firewall (open TCP 8333 port):

# firewall-cmd --zone=public --add-port=8333/tcp --permanent
# firewall-cmd --reload

Also RPC port 8332 (if used) should be added to firewall on correct intreface/zone.

Run daemon:

# systemctl start bitcoind && systemctl status bitcoind && systemctl enable bitcoind

check debug log

test rpc from server:

$ curl --data-binary '{"jsonrpc": "1.0", "id":"test", "method": "uptime", "params": [] }' -H 'content-type: text/plain;' "http://<rpc_user>:<rpc_password>@127.0.0.1:8332/"

test rpc from webapp server (the same, replace ip address)

Create wallet and load automatically after start

$ curl --data-binary '{"jsonrpc": "1.0", "id":"test", "method": "createwallet", "params": ["walletname"] }' -H 'content-type: text/plain;' "http://<rpc_user>:<rpc_password>@127.0.0.1:8332/"

On older bitcoin core node versions, we need to load it explicitely after creating (this is not necessary on new versions):

$ curl --data-binary '{"jsonrpc": "1.0", "id":"test", "method": "loadwallet", "params": ["walletname", true] }' -H 'content-type: text/plain;' "http://<rpc_user>:<rpc_password>@127.0.0.1:8332/"

Add all wallets to bitcoin.conf to load automatically after start:

$ vim /etc/bitcoin/bitcoin/conf

#load these wallets automatically after start
wallet=wallet_name
wallet=another_wallet

Restart:

# systemctl stop bitcoind && systemctl start bitcoind

Test if loaded:

$ curl --data-binary '{"jsonrpc": "1.0", "id":"test", "method": "listwallets", "params": [] }' -H 'content-type: text/plain;' "http://<rpc_user>:<rpc_password>@127.0.0.1:8332/"

Alternative run & stop without systemd unit:

$ bitcoind -d

$ ps x

$ bitcoin-cli stop

Zeromq

Check if zeromq support is compiled in:

# ldd /usr/local/bin/bitcoind | grep -i mq

$ curl --data-binary '{"jsonrpc": "1.0", "id":"test", "method": "getzmqnotifications", "params": [] }' -H 'content-type: text/plain;' "http://<rpc_user>:<rpc_password>@127.0.0.1:8332/"

Compile from source

Taken from https://ma.ttias.be/run-a-bitcoin-core-full-node-on-centos-7/

Old version download links are here: https://bitcoin.org/en/version-history (https://bitcoincore.org/bin/)

# yum -y install epel-release
# yum install -y autoconf automake boost-devel gcc-c++ git libdb4-cxx libdb4-cxx-devel libevent-devel libtool openssl-devel wget zeromq zeromq-devel
# su bitcoin

$ wget https://bitcoincore.org/bin/bitcoin-core-0.17.2/bitcoin-0.17.2.tar.gz
$ tar xvzf ./bitcoin-0.17.2.tar.gz
$ cd ./bitcoin-0.17.2
$ ./autogen.sh
$ ./configure
$ make -j 2

$ ./src/bitcoin-cli --version

# cd /home/bitcoin/bitcoin-0.17.2
# make install