LoginSignup
9

More than 5 years have passed since last update.

bitcoindをAWSのAmazon Linuxにインストール

Last updated at Posted at 2016-03-21

Githubの公式ドキュメントを読みながらAmazon Linuxへのインストール・起動までをメモ。

環境

  • Amazon Linux AMI 2015.09.2 (HVM), SSD Volume Type
  • bitcoin v0.12.0

事前準備

SSD100GB, t2.mediumでEC2インスタンスを起動しておく。

手順

依存ライブラリをインストール。

$ sudo yum install -y gcc-c++ autoconf automake libtool boost-devel openssl-devel libevent-devel

bitcoinをダウンロード。

$ curl -L https://github.com/bitcoin/bitcoin/archive/v0.12.0.tar.gz -o bitcoin-0.12.0.tar.gz
$ tar zxvf bitcoin-0.12.0.tar.gz
$ cd bitcoin-0.12.0

Berkeley DBをインストール。

$ BITCOIN_ROOT=$(pwd)

$ BDB_PREFIX="${BITCOIN_ROOT}/db4"
$ mkdir -p $BDB_PREFIX

$ wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz'
$ echo '12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef  db-4.8.30.NC.tar.gz' | sha256sum -c
$ tar -xzvf db-4.8.30.NC.tar.gz

$ cd db-4.8.30.NC/build_unix/
$ ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX
$ make install

bitcoinをインストール。

$ cd $BITCOIN_ROOT
$ ./autogen.sh
$ ./configure LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/"

$ make && sudo make install && echo DONE
...
DONE

起動スクリプトをinit.dに配置してサービスに登録。

$ sudo cp ./contrib/init/bitcoind.init /etc/init.d/bitcoind
$ sudo chmod 755 /etc/init.d/bitcoind
$ sudo chkconfig --add bitcoind
$ sudo chkconfig bitcoind on

起動スクリプトのオプションを定義。

$ sudo mkdir /etc/bitcoin
$ sudo vi /etc/sysconfig/bitcoind
# 以下の内容を設定。
BITCOIND_BIN="/usr/local/bin/bitcoind"
BITCOIND_OPTS="-daemon -disablewallet -datadir=/var/lib/bitcoin -conf=/etc/bitcoin/bitcoin.conf"

設定ファイルを配置。

$ sudo cp ./contrib/debian/examples/bitcoin.conf /etc/bitcoin/
$ sudo vi /etc/bitcoin/bitcoin.conf
# 以下の内容を設定。
rpcbind=0.0.0.0
rpcuser=xxxuser
rpcpassword=xxxpass
rpcport=8332

データディレクトリを作成。

$ sudo mkdir /var/lib/bitcoin

起動

$ sudo service bitoind start

ブロックのダウンロードが完了するまで、デーモン起動OKのメッセージは表示されない。
以下のコマンドのblocksとblockchain.infoの最新ブロックの差分からおおよその進捗が確認できる。

追記: デーモン起動が完了しないのは、単に起動オプションから -daemon が抜けていただけだった。

$ sudo /usr/local/bin/bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf getinfo
{
  "version": 120000,
  "protocolversion": 70012,
  "blocks": 261496,
  "timeoffset": -1,
  "connections": 8,
  "proxy": "",
  "difficulty": 148819199.8050926,
  "testnet": false,
  "paytxfee": 0.00000000,
  "relayfee": 0.00001000,
  "errors": ""
}

稼働確認

稼働確認のためbitcoinをインストールしたAmazon LinuxにSSHポートフォワーディング。

$ ssh -L '8832:127.0.0.1:8832' bitcoin-node

別ターミナルのPythonからブロック数を確認。

$ sudo pip install python-bitcoinlib
$ python
>>> import bitcoin.rpc
>>> proxy = bitcoin.rpc.Proxy(service_url='http://xxxuser:xxxpass@127.0.0.1:8332')
>>> proxy.getblockcount()
311367

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9