CentOS 6.10でBitcoin Coreをビルドする


Bitcoin Coreを動かしたいだけなら、下記のサイトの方法でビルド済みのものをインストールすれば良い。

CentOS 6.x に bitcoind デーモンをインストールする方法 | block-chain.jp

Kusacoinのシードノードを動かしているサーバーを解約したかったけれど、他に借りているサーバーがCentOS 6.10だった。

手元のVMなどを使ってstaticビルドして、バイナリを持っていったほうが楽だったかもしれない。

How to compile static version bitcoind?

下記の手順は0.17ブランチで試した。今気が付いたが、タグではなくブランチだった。まあ、Bitcoinのバージョンが多少変わっても手順は変わらないでしょう。

UNIX用のビルド手順はここに書かれている。が、CentOSは載っていない。yumで入るパッケージが古い。古いものを別途インストールすれば良い。

yum

yumでインストールできるものをインストールする。

$ sudo yum install git automake libtool openssl-devel

autoconf

2.64以上が必要と言われるが、yumで入るものは2.63。惜しい。

$ ./autogen.sh
configure.ac:244: error: Autoconf version 2.64 or higher is required
build-aux/m4/ax_check_compile_flag.m4:60: AX_CHECK_COMPILE_FLAG is expanded from...
configure.ac:244: the top level
autom4te: /usr/bin/m4 failed with exit status: 63
aclocal: autom4te failed with exit status: 63
autoreconf: aclocal failed with exit status: 63

仕方が無いので、ソースコードからインストール。

$ curl -L -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
$ tar zxvf autoconf-latest.tar.gz
$ cd autoconf-2.69/
$ ./configure
$ make
$ sudo make install

gcc

./configureがコケる。

checking dependency style of g++... gcc3
checking whether g++ supports C++11 features with -std=c++11... no
checking whether g++ supports C++11 features with -std=c++0x... no
checking whether g++ supports C++11 features with +std=c++11... no
checking whether g++ supports C++11 features with -h std=c++11... no
configure: error: *** A compiler with support for C++11 language features is required.

gcc 4.4.7ではC++1の機能が使えないらしい。2012年リリースなのに……。SCLで新しいgccをインストールする。

$ sudo yum install centos-release-scl
$ sudo yum install devtoolset-7-gcc-c++
$ scl enable devtoolset-7 bash

boost

checking for boostlib >= 1.47.0... configure: We could not detect the boost libraries (version 1.47 or higher). If you have a staged boost library (still not installed) please specify $BOOST_ROOT in your environment and do not give a PATH to --with-boost option.  If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost for more documentation.
checking whether the Boost::System library is available... yes
configure: error: Could not find a version of the boost_system library!

boostも古い。必要なのは1.47.0以上。yumは1.41。ソースコードからインストール。

$ curl -L -O http://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.gz
$ tar zxvf boost_1_68_0.tar.gz
$ cd boost_1_68_0
$ ./bootstrap.sh
$ sudo ./b2 install

libevent

これも古い? yumlibevent2があるけれど、これをインストールしてもダメだったので、ソースコードからインストール。

$ curl -O -L https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
$ tar zxvf libevent-2.1.8-stable.tar.gz
$ cd libevent-2.1.8-stable
$ make
$ sudo make install

Bitcoin

$ git clone https://github.com/bitcoin/bitcoin.git
$ cd bitcoin
$ git checkout 0.17

./autogen.shで、

configure.ac:1426: error: possibly undefined macro: PKG_CONFIG_LIBDIR
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
autoreconf: /usr/local/bin/autoconf failed with exit status: 1

というエラーが出る。良く分からないけれど、configure.acを書き換える。

$ git diff
diff --git a/configure.ac b/configure.ac
index 44ca821..952e678 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,6 @@
 dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
 AC_PREREQ([2.60])
+m4_pattern_allow(PKG_CONFIG_LIBDIR)
 define(_CLIENT_VERSION_MAJOR, 0)
 define(_CLIENT_VERSION_MINOR, 17)
 define(_CLIENT_VERSION_REVISION, 0)

あとは普通にビルド。

$ ./autogen.sh
$ PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --disable-wallet
$ make
$ LD_LIBRARY_PATH=/usr/local/lib src/bitcoind

/usr/local/lib/を指定しているのは、CentOSだとパスに入っていないから。Berkeley DBが必要になるので、シードノードとしては不要なウォレット機能は無効にしている。Qtが無ければGUIは勝手に無効になる。

-fPICがどうこうというエラーが出た場合は、./configure--disable-hardeningを追加すると良い。脆弱性があった場合に攻撃しやすくなるので、本当は追加せずに何とかしたほうが良いのだろうけど。