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.
Compilation
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.
./autogen.sh
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.
make -j9
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.
sudo checkinstall
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
Autorun
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
Remote Status
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’s Working!
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.
Thank you, go Bitcoin Classic running.
I added the following command to start bitcoind at boot.
sudo systemctl enable bitcoind.service
just to add how I managed to get also the Bitcoind wallet function working under Debian8 (Jessie).
The OS is a 64 bit version running on a Xen based Virtual Private Server.
download and install:
dpkg -i libdb4.8_4.8.30-2_amd64.deb
dpkg -i /libdb4.8-dev_4.8.30-2_amd64.deb
apt-get purge libdb5.3-dev
dpkg -i /libdb4.8-dev_4.8.30-2_amd64.deb
dpkg -i /libdb4.8++-dev_4.8.30-2_amd64.deb
The purge is needed as the 5.3-dev that was there in my case interferes.
I found the packages via https://archive.debian.net/squeeze/
as they are no longer maintained; they install without any problem on Debian8. Try a few mirrors as most don’t have them anymore.
Also this bunch needs to be present:
apt-get install \
libtool automake autotools-dev 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 libcrypto++
Then I followed the approach to compiling as done with gcc compilation:
make another target directory next to the one to which the bitcoin-master was unzipped or git cloned.
In that empty target dir create 4 subdirectories: src and src/consensus src/leveldb src/obj-test.
From within the target directory top call autogen.sh and configure and make, like’ ../bitcoin-master/autogen.sh’.
For size optimization:
export CXXFLAGS=’-Os’
export CFLAGS=’-Os’
My configure parameters: –prefix=/usr –with-gui=no –with-boost
I actually wrote a shell script the runs next to the two directories and in which the appropriate change directory ‘cd’ commands are done to call for action from the right placs.
The resulting binaries and libraries can be installed into /usr/bin and /usr/lib.
Binaries are bitcoind, bitcoin-tx, and bitcoin-cli .
Binaries and libraries are found under src (.a and .lo type libs) and under src/.libs (.so ).
Of course an /etc/init.d/bitcoin and /etc/bitcoin/bitcoin.conf are needed as well. But that is unrelated to Debian version.
archive.debian.NET can be DANGEROUS! Is not recommended to download binary files from “unknown¨ places, more if they are used to manage bitcoins.