0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

bitcoin: 编译与运行

Last updated at Posted at 2019-02-12

服务器中最常见的系统是ubuntu, 我们拿ubuntu来做演示.
由于同步全部的区块链,大概需要 200G的空间,记得挂载个大硬盘哦。

在B站上传了一个无声版的视频—— 使用ubuntu系统 编译 bitcoin

挂载分区

阿里云挂载数据盘

更新系统

sudo apt-get update
sudo apt-get upgrade

下载Bitcoin源码, 并切换版本

sudo apt-get install -y git
git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin && git checkout v0.16.0

安装依赖

sudo apt-get install -y  autoconf libtool pkg-config \
libboost-all-dev libssl-dev libevent-dev

安装 berkeleyDB

berkeleyDB 是一款嵌入式数据库, 类似 Sqlite.
BerkeleyDB 做钱包数据库, 保存私钥等. 而且需要一个老的版本 berkeleyDB-4.8.30.

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:bitcoin/bitcoin
sudo apt-get update
sudo apt-get install libdb4.8-dev libdb4.8++-dev

编译bitcoin

./autogen.sh
./configure 
make
make install

在执行 ./configure 时, 出现以下提示, 表示准备工作已经完成

Options used to compile and link:
  with wallet   = yes
  with gui / qt = no
  with zmq      = no
  with test     = yes
  with bench    = yes
  with upnp     = auto
  debug enabled = no
  werror        = no

  target os     = linux
  build os      =

  CC            = gcc
  CFLAGS        = -g -O2
  CPPFLAGS      = -I/usr/local/BerkeleyDB.4.8/include -O2 -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS
  CXX           = g++ -std=c++11
  CXXFLAGS      = -g -O2 -Wall -Wextra -Wformat -Wvla -Wformat-security -Wno-unused-parameter
  LDFLAGS       = -L/usr/local/BerkeleyDB.4.8/lib

运行 bitcoin

bitcoind -daemon -datadir=<datadir>

bitcoind -daemon -datadir=/mnt/blocks 
# datadir把同步的数据下载到/mnt/blocks  /mnt是新挂载的数据盘

需要一段时间等待数据全部同步完.

执行rpc命令

详细的 rpc 列表 https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

bitcoin-cli -datadir=/mnt/blocks getblockhash 0
# 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

bitcoin-cli -datadir=/mnt/blocks getblockcount
# 311952

说明节点已经在同步数据了.

停止bitcoind

bitcoin-cli stop

本人根据官方步骤做了一些裁剪, 在服务器运行, 不需要qt客户端,
就没有安装qt依赖, 尽量保持精简.

安装QT5依赖

sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler

sudo apt-get install libqrencode-dev

再执行 make -j3, 会生成 bitcoin-qt, 运行./src/qt/bitcoin-qt会启动图形界面.

mac系统qt界面


参考:

https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md
https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list
https://github.com/bitcoin/bitcoin/issues/3686
http://man.linuxde.net/ldconfig
https://en.bitcoin.it/wiki/Running_Bitcoin

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?