主页 > imtoken支持bcc > 比特币比特币节点安装
比特币比特币节点安装
前言
量化交易的第一步是获取数据btc客户端下载,所以获取比特币数据最直接的方式就是搭建比特币客户端,直接从比特币公链同步账本获取数据。 比特币网络的基础是去中心化的节点和透明性,这样每个节点都会获得比特币网络中的全部数据。
因此,让我们从构建比特币客户端节点开始。
目录
比特币安装过程 启动比特币节点 1. 比特币安装过程
从源码安装比特币客户端的操作过程分为以下7个步骤:
从 github 下载代码库并切换到最新版本。 安装系统依赖库。 运行 autogen.sh 脚本。 运行配置脚本。 运行 make 和 make install 验证比特币安装是否成功。
接下来,我们将一步步进行。 本文使用的Linux系统环境为:Linux Ubuntu 16.04 LTS 64bit。
1.1 首先从比特币官方github下载代码库。
安装git的过程就不多说了,只需要一个命令:apt install git。
> git clone https://github.com/bitcoin/bitcoin.git
> cd bitcoin
1.2 找到最新的tag版本v0.16.0。
> git tag
noversion
v0.1.5
...
v0.16.0
v0.16.0rc1
v0.16.0rc2
v0.16.0rc3
v0.16.0rc4
v0.2.0
...
v0.9.3
v0.9.3rc1
v0.9.3rc2
v0.9.4
v0.9.5
v0.9.5rc1
v0.9.5rc2
切换到最新版本分支。
> git checkout v0.16.0
1.3 安装需要依赖的系统工具。 这里会用到libtool、pkg-config、libboost、libdb工具包,需要提前安装好。
> apt install libtool
> apt install pkg-config
> apt install libboost-all-dev
> apt install libdb5.3++-dev
> apt install libevent-dev
1.4 使用./autogen.sh脚本编译,
> ./autogen.sh
1.5 运行配置脚本
执行完成后,发现已经为当前target生成了configure文件,然后运行configure文件。 运行时会出现BerkerlyDB错误,提示需要4.8版本的BerkerlyDB。 有两种解决方法。 首先是下载对应版本的BerkerlyDB; 二是跳过这一步检查。 我们先用第二种方法,跳过BerkeleyDB的兼容性检查。
> ./configure
configure: error: Found Berkeley DB other than 4.8, required for portable wallets (--with-incompatible-bdb to ignore or --disable-wallet to disable wallet functionality)
# 跳过BerkeleyDB的兼容性检查
> ./configure --with-incompatible-bdb
1.6 执行make和make install。
> make
> make install
1.7 验证比特币安装是否成功
要验证比特币是否成功安装,有 2 个命令 bitcoin-cli 和 bitcoind。 我们需要检查系统环境中是否安装了这个启动命令。
查看launch命令的系统安装位置。
> which bitcoin-cli
/usr/local/bin/bitcoin-cli
> which bitcoind
/usr/local/bin/bitcoind
分别查看bitcoind和bitcoin-cli命令的帮助信息。
> bitcoind -help
> bitcoin-cli -help
这样就完成了比特币客户端的安装。
2.启动比特币节点
通过bitcoind命令启动比特币核心客户端程序。 在运行之前,我需要定义一个bitcoin.conf配置文件来设置RPC-JSON访问用户。
创建一个新的配置文件 .bitcoin/bitcoin.conf。 设置rpc用户的帐号和密码,请按照复杂的密码设置要求进行设置。 官方推荐的bitcoin.conf文件的配置项,打开文件。
> vi .bitcoin/bitcoin.conf
rpcuser=bsspirit
rpcpassword=98jfidayelqlvjieJDIjda
启动bitcoind服务器,将数据写入/data/btc目录,并在控制台打印输出。
> bitcoind -datadir=/data/btc -conf=/root/.bitcoin/bitcoin.conf -printtoconsole
2018-05-30 01:51:06 Bitcoin Core version v0.16.0 (release build)
2018-05-30 01:51:06 InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1
2018-05-30 01:51:06 Assuming ancestors of block 0000000000000000005214481d2d96f898e3d5416e43359c145944a909d242e0 have valid signatures.
2018-05-30 01:51:06 Setting nMinimumChainWork=000000000000000000000000000000000000000000f91c579d57cad4bc5278cc
2018-05-30 01:51:06 Using the 'sse4' SHA256 implementation
2018-05-30 01:51:06 Using RdRand as an additional entropy source
2018-05-30 01:51:06 Default data directory /root/.bitcoin
2018-05-30 01:51:06 Using data directory /data/btc
2018-05-30 01:51:06 Using config file /root/.bitcoin/bitcoin.conf
2018-05-30 01:51:06 Using at most 125 automatic connections (1024 file descriptors available)
2018-05-30 01:51:06 Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements
2018-05-30 01:51:06 Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements
2018-05-30 01:51:06 Using 4 threads for script verification
2018-05-30 01:51:06 scheduler thread start
2018-05-30 01:51:06 HTTP: creating work queue of depth 16
2018-05-30 01:51:06 Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcuser for rpcauth auth generation.
2018-05-30 01:51:06 HTTP: starting 4 worker threads
2018-05-30 01:51:06 Using wallet directory /data/btc
2018-05-30 01:51:06 init message: Verifying wallet(s)...
2018-05-30 01:51:06 Using BerkeleyDB version Berkeley DB 5.3.28: (September 9, 2013)
2018-05-30 01:51:06 Using wallet wallet.dat
2018-05-30 01:51:06 CDBEnv::Open: LogDir=/data/btc/database ErrorFile=/data/btc/db.log
2018-05-30 01:51:06 Cache configuration:
2018-05-30 01:51:06 * Using 2.0MiB for block index database
2018-05-30 01:51:06 * Using 8.0MiB for chain state database
2018-05-30 01:51:06 * Using 440.0MiB for in-memory UTXO set (plus up to 286.1MiB of unused mempool space)
2018-05-30 01:51:06 init message: Loading block index...
2018-05-30 01:51:06 Opening LevelDB in /data/btc/blocks/index
2018-05-30 01:51:07 Opened LevelDB successfully
2018-05-30 01:51:07 Using obfuscation key for /data/btc/blocks/index: 0000000000000000
2018-05-30 01:51:08 LoadBlockIndexDB: last block file = 0
2018-05-30 01:51:08 LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=1, size=293, heights=0...0, time=2009-01-03...2009-01-03)
2018-05-30 01:51:08 Checking all blk files are present...
2018-05-30 01:51:08 LoadBlockIndexDB: transaction index disabled
2018-05-30 01:51:08 Opening LevelDB in /data/btc/chainstate
2018-05-30 01:51:08 Opened LevelDB successfully
2018-05-30 01:51:08 Using obfuscation key for /data/btc/chainstate: 6adad0af82f188f1
2018-05-30 01:51:08 Loaded best chain: hashBestChain=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f height=0 date=2009-01-03 18:15:05 progress=0.000000
2018-05-30 01:51:08 init message: Rewinding blocks...
2018-05-30 01:51:09 init message: Verifying blocks...
2018-05-30 01:51:09 block index 2369ms
2018-05-30 01:51:09 init message: Loading wallet...
2018-05-30 01:51:09 nFileVersion = 160000
2018-05-30 01:51:09 Keys: 2001 plaintext, 0 encrypted, 2001 w/ metadata, 2001 total
2018-05-30 01:51:09 wallet 67ms
2018-05-30 01:51:09 setKeyPool.size() = 2000
2018-05-30 01:51:09 mapWallet.size() = 0
2018-05-30 01:51:09 mapAddressBook.size() = 0
2018-05-30 01:51:09 mapBlockIndex.size() = 279999
2018-05-30 01:51:09 nBestHeight = 0
2018-05-30 01:51:09 Imported mempool transactions from disk: 0 succeeded, 0 failed, 0 expired, 0 already there
2018-05-30 01:51:09 AddLocal(103.211.167.71:8333,1)
2018-05-30 01:51:09 Discover: IPv4 eth0: 103.211.167.71
2018-05-30 01:51:09 Bound to [::]:8333
2018-05-30 01:51:09 Bound to 0.0.0.0:8333
2018-05-30 01:51:09 init message: Loading P2P addresses...
2018-05-30 01:51:09 torcontrol thread start
2018-05-30 01:51:09 Loaded 2445 addresses from peers.dat 9ms
2018-05-30 01:51:09 init message: Loading banlist...
2018-05-30 01:51:09 init message: Starting network threads...
2018-05-30 01:51:09 dnsseed thread start
2018-05-30 01:51:09 net thread start
2018-05-30 01:51:09 addcon thread start
2018-05-30 01:51:09 init message: Done loading
2018-05-30 01:51:09 opencon thread start
2018-05-30 01:51:09 msghand thread start
2018-05-30 01:51:09 New outbound peer connected: version: 70015, blocks=525031, peer=0
2018-05-30 01:51:11 New outbound peer connected: version: 70015, blocks=525031, peer=1
....
启动参数:
如果打算在后台执行,可以增加-daemon参数。 同时去掉-printtoconsole参数,在如下日志文件中输出。
> bitcoind -datadir=/data/btc -conf=/root/.bitcoin/bitcoin.conf -daemon
Bitcoin server starting
# 查看日志,在数据输出的目录,跟踪debug.log文件。
> tail -f /data/btc/debug.log
11-04-11 22:01:50' progress=0.001211 cache=23.8MiB(165438txo)
2018-05-30 04:21:12 UpdateTip: new best=00000000000044640cb1d3e034f8df6604d1ac1346e6162bfca8dc60c4bbd887 height=117873 version=0x00000001 log2_work=61.645341 tx=403428 date='2011-04-11 22:02:29' progress=0.001212 cache=23.8MiB(165441txo)
2018-05-30 04:21:12 UpdateTip: new best=0000000000006488914c16dc226f1d73d5dcd6c258c3bc926fa0f804909dbd1b height=117874 version=0x00000001 log2_work=61.645483 tx=403445 date='2011-04-11 22:19:06' progress=0.001212 cache=23.8MiB(165459txo)
2018-05-30 04:21:12 UpdateTip: new best=000000000000988f65c0d5b018241f0dd13ea6b73c6228efccbbb577b5791f06 height=117875 version=0x00000001 log2_work=61.645624 tx=403453 date='2011-04-11 22:21:40' progress=0.001212 cache=23.8MiB(165460txo)
...
运行 bitcoin-cli getblockchaininfo 命令以显示有关比特币网络节点、钱包和区块链数据库状态的基本信息。
> bitcoin-cli getblockchaininfo
{
"chain": "main",
"blocks": 2867,
"headers": 525050,
"bestblockhash": "000000006d6af482c12555a44bed3a0d4bbadf0fa27274225a1ed808b8a7d405",
"difficulty": 1,
"mediantime": 1233666084,
"verificationprogress": 8.75401245716694e-06,
"initialblockdownload": true,
"chainwork": "00000000000000000000000000000000000000000000000000000b340b340b34",
"size_on_disk": 852350,
"pruned": false,
"softforks": [
{
"id": "bip34",
"version": 2,
"reject": {
"status": false
}
},
{
"id": "bip66",
"version": 3,
"reject": {
"status": false
}
},
{
"id": "bip65",
"version": 4,
"reject": {
"status": false
}
}
],
"bip9_softforks": {
"csv": {
"status": "defined",
"startTime": 1462060800,
"timeout": 1493596800,
"since": 0
},
"segwit": {
"status": "defined",
"startTime": 1479168000,
"timeout": 1510704000,
"since": 0
}
},
"warnings": ""
}
看到这个信息就说明你的比特币程序已经启动了。 有几十G的数据需要同步!
安装bitcoin比用apt安装要复杂一些,但是按照官方文档的介绍基本就可以搞定,安装过程对技术人员来说问题不大。 不同的公链节点软件不同btc客户端下载,安装方式也不同。 下一篇文章将介绍以太坊客户端Geth的安装。