This past week I took a few hours to get a Bitcoin full node running on my Debian server. As a believer in the Bitcoin project I’m more than happy to host a full node on my media server.
From your home directory clone the bitcoin project. I used the 0.11 branch.
git clone https://github.com/bitcoin/bitcoin -b 0.11
Following the directions from the github readme I configured and compiled.
I installed the necessary tools and libraries to compile the code.
sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev
Then I got the build environment set up.
Since I didn’t need wallet functionality, I didn’t need to install Berkeley DB. I also enabled hardening because, well because why not right? Extra security!
./configure --disable-wallet --enable-hardening
After the configuration was complete I compiled. I noticed make was only utilizing one core and was taking a long time to run. I reran with make configured to utilize 9 (n + 1) cores.
Since I’m on Debian I wanted to package the code up so I could install it via dpkg. CheckInstall puts the code into a .deb file that dpkg can then install. This will allow for future uninstall or upgrades to go smoothly, and is better than blindly placing files into the system.
Next I needed to create a configuration file for bitcoind to use. I created a new bitcoin.conf file in ~/.bitcoin/ and placed the following text in it.
# server=1 tells Bitcoin-Qt and bitcoind to accept JSON-RPC commands server=1 # You must set rpcuser and rpcpassword to secure the JSON-RPC api rpcuser=superSecretUsername rpcpassword=superSecretPassword
I created a .service file for Debian so the application would autostart. I created a “bitcoinuser” user and “bitcoin” group for the process to run under.
[Unit] Description=Bitcoin's distributed currency daemon After=network.target [Service] User=bitcoinuser Group=bitcoin Type=forking ExecStart=/usr/local/bin/bitcoind -daemon -conf=/home/bitcoinuser/.bitcoin/bitcoin.conf -datadir=/home/bitcoinuser/.bitcoin/ Restart=always PrivateTmp=true TimeoutStopSec=60s TimeoutStartSec=20s StartLimitInterval=1s StartLimitBurst=5 [Install] WantedBy=multi-user.target
I placed it in /lib/systemd/system/bitcoind.service
After creating, I updated the system to pick up the changes.
sudo systemctl daemon-reload
Then I could issue nice commands to handle everything for me like
sudo service bitcoind start
I wanted to be able to monitor the status of bitcoind remotely via the web, which requires bitcoind to listen to JSON-RPC commands. Craig Watson has a nice PHP project to do just this. I cloned his github repo and installed it into Apache. It needed a small amount of configuration, mainly setting the RPC username and password (that I assigned in the bitcoin.conf file previously), as well as configuring what information I wanted displayed on the main page. After installing the website and configuring Apache with the new route I got a nice screen.
It took around 24 hours for it to download the entire blockchain (around 55GB at time of writing), quite surprising with the fast connection the server has.