• Archive by category "数字货币"

Blog Archives

geth以太坊节点安装

比特币吸金之道系列文章,由计算机黑客发明的网络货币,无国界,无政府,无中心。没有政府滥发货币,没有通货膨胀。在全球计算机网络中,自由的实现货币兑换和流通。

本系列文章只讲程序和策略,不谈挖矿…

关于作者:

  • 张丹(Conan), 程序员/Quant: Java,R,Nodejs
  • blog: http://blog.fens.me
  • email: bsspirit@gmail.com

转载请注明出处:
http://blog.fens.me/bitcoin-install-geth

前言

以太坊(ETH)的出现开启了区块链的2.0时代,为了获得数据,最直接的方法就是搭建一个以太坊的客户端,直接从以太坊的公链上面同步账本获得数据。通过安装和运行geth,可以连接到以太坊的公链的实时网络,并进行以下操作,包括 挖掘真的以太币,在不同地址间转移资金,创建合约发送交易,探索区块历史等。

那么,让我们从搭建geth客户端节点开始吧。如果你想知道,如何使用比特币的客户端 bitcoin 获得数据,请参考文章 bitcoin比特币节点安装

目录

  1. geth安装过程
  2. 启动geth的节点

1. geth安装过程

go-ethereum客户端通常被称为geth,它是个命令行界面,执行在Go语言的运行时环境上,实现了完整以太坊节点。以太坊的官方网站地址为:https://ethereum.github.io/go-ethereum/

1.1 go的运行环境安装

由于geth是go语言开发的,在安装geth客户端之前,我们要先把go的运行环境装好。go语言的在Ubuntu的详细安装方法,请参考文章go语言安装。

下面列出go语言的简单的安装过程脚本:


# 下载最新的go包
> wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz

# 将下载的源码包解压至 /usr/local目录。
> tar -C /usr/local/ -xvf go1.10.3.linux-amd64.tar.gz

> 将 /usr/local/go/bin 目录添加至PATH环境变量
> export PATH=$PATH:/usr/local/go/bin

# 运行go的命令
> go
Go is a tool for managing Go source code.

Usage:

	go command [arguments]

The commands are:

	build       compile packages and dependencies
	clean       remove object files and cached files
	doc         show documentation for package or symbol
	env         print Go environment information
	bug         start a bug report
	fix         update packages to use new APIs
	fmt         gofmt (reformat) package sources
	generate    generate Go files by processing source
	get         download and install packages and dependencies
	install     compile and install packages and dependencies
	list        list packages
	run         compile and run Go program
	test        test packages
	tool        run specified go tool
	version     print Go version
	vet         report likely mistakes in packages

Use "go help [command]" for more information about a command.

Additional help topics:

	c           calling between Go and C
	buildmode   build modes
	cache       build and test caching
	filetype    file types
	gopath      GOPATH environment variable
	environment environment variables
	importpath  import path syntax
	packages    package lists
	testflag    testing flags
	testfunc    testing functions

Use "go help [topic]" for more information about that topic.

这样go的运行环境,就安装好了。

1.2 geth客户端安装

从源代码安装geth客户端的操作过程,分为以下3步:

  1. 从github下载代码库
  2. 编译geth客户端
  3. 验证geth客户端

接下来,我们就一步一步的进行操作。本文使用的Linux系统环境为:Linux Ubuntu 16.04 LTS 64bit。

1.2.1 先从geth的官方github下载代码库。

安装git的过程,就不再多说了,只需要一条命令apt install git就行了。


> git clone https://github.com/ethereum/go-ethereum.git
> cd go-ethereum

1.2.2 编译geth客户端


> make geth
build/env.sh go run build/ci.go install ./cmd/geth
>>> /usr/local/go/bin/go install -ldflags -X main.gitCommit=f1986f86f2229ea5ff587c65c9229a65f40bf591 -v ./cmd/geth
github.com/ethereum/go-ethereum/vendor/github.com/hashicorp/golang-lru/simplelru
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/html/atom
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/internal/identifier

// 省略

github.com/ethereum/go-ethereum/eth
github.com/ethereum/go-ethereum/les
github.com/ethereum/go-ethereum/ethstats
github.com/ethereum/go-ethereum/cmd/utils
github.com/ethereum/go-ethereum/cmd/geth
Done building.
Run "/root/go-ethereum/build/bin/geth" to launch geth.

把geth的目录,加入环境变量中。


# 将 /root/go-ethereum/build/bin 目录添加至PATH环境变量
> export PATH=$PATH:/root/go-ethereum/build/bin

1.2.3 验证geth客户端安装成功

检查geth是否安装成功,通过运行geth客户端,查看版本。


> geth version
Geth
Version: 1.8.12-unstable
Git Commit: f1986f86f2229ea5ff587c65c9229a65f40bf591
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10.3
Operating System: linux
GOPATH=
GOROOT=/usr/local/go

这样就完成了,geth的客户端的安装。

2. 启动geth节点

安装好后,我们就可以启动geth客户端程序了,我们可以先启动以太坊公链的测试网络,增加命令行参数–testnet。


# 测试网络中启动geth
> geth --testnet console
INFO [06-20|17:15:04.991843] Maximum peer count                       ETH=25 LES=0 total=25
INFO [06-20|17:15:04.993534] Starting peer-to-peer node               instance=Geth/v1.8.12-unstable-f1986f86/linux-amd64/go1.10.3
INFO [06-20|17:15:04.993635] Allocated cache and file handles         database=/root/.ethereum/testnet/geth/chaindata cache=768 handles=512
INFO [06-20|17:15:05.054257] Writing custom genesis block 
INFO [06-20|17:15:05.069545] Persisted trie from memory database      nodes=355 size=51.89kB time=1.935374ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [06-20|17:15:05.070105] Initialised chain configuration          config="{ChainID: 3 Homestead: 0 DAO:  DAOSupport: true EIP150: 0 EIP155: 10 EIP158: 10 Byzantium: 1700000 Constantinople:  Engine: ethash}"
INFO [06-20|17:15:05.070282] Disk storage enabled for ethash caches   dir=/root/.ethereum/testnet/geth/ethash count=3
INFO [06-20|17:15:05.070394] Disk storage enabled for ethash DAGs     dir=/root/.ethash                       count=2
INFO [06-20|17:15:05.070531] Initialising Ethereum protocol           versions="[63 62]" network=3
INFO [06-20|17:15:05.07101] Loaded most recent local header          number=0 hash=419410…ca4a2d td=1048576
INFO [06-20|17:15:05.071186] Loaded most recent local full block      number=0 hash=419410…ca4a2d td=1048576
INFO [06-20|17:15:05.071281] Loaded most recent local fast block      number=0 hash=419410…ca4a2d td=1048576
INFO [06-20|17:15:05.071548] Regenerated local transaction journal    transactions=0 accounts=0
INFO [06-20|17:15:05.072007] Starting P2P networking 
INFO [06-20|17:15:07.258259] UDP listener up                          self=enode://652a8e7e33f87110907f31aa0943137a5252a47508f496730780fe9bdad84bc33eddc27ac2e5404f4050b1e655dc290a2106af8e4f73a5d40ac0d473e0394656@[::]:30303
INFO [06-20|17:15:07.261285] RLPx listener up                         self=enode://652a8e7e33f87110907f31aa0943137a5252a47508f496730780fe9bdad84bc33eddc27ac2e5404f4050b1e655dc290a2106af8e4f73a5d40ac0d473e0394656@[::]:30303
INFO [06-20|17:15:07.262189] IPC endpoint opened                      url=/root/.ethereum/testnet/geth.ipc
Welcome to the Geth JavaScript console!

instance: Geth/v1.8.12-unstable-f1986f86/linux-amd64/go1.10.3
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> 

当然,我们的目标是从以太坊公链中同步数据,接下来,关掉测试网络,我们直接启动主网。


# 启动geth客户端
> geth --datadir=/data0/eth
INFO [06-20|17:41:49.295669] Maximum peer count                       ETH=25 LES=0 total=25
INFO [06-20|17:41:49.296785] Starting peer-to-peer node               instance=Geth/v1.8.12-unstable-f1986f86/linux-amd64/go1.10.3
INFO [06-20|17:41:49.296874] Allocated cache and file handles         database=/data0/eth/geth/chaindata cache=768 handles=512
INFO [06-20|17:41:49.352014] Writing default main-net genesis block 
INFO [06-20|17:41:49.75667] Persisted trie from memory database      nodes=12356 size=1.88mB time=59.845085ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [06-20|17:41:49.757004] Initialised chain configuration          config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople:  Engine: ethash}"
INFO [06-20|17:41:49.757053] Disk storage enabled for ethash caches   dir=/data0/eth/geth/ethash count=3
INFO [06-20|17:41:49.757066] Disk storage enabled for ethash DAGs     dir=/root/.ethash          count=2
INFO [06-20|17:41:49.757112] Initialising Ethereum protocol           versions="[63 62]" network=1
INFO [06-20|17:41:49.757397] Loaded most recent local header          number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [06-20|17:41:49.757427] Loaded most recent local full block      number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [06-20|17:41:49.757438] Loaded most recent local fast block      number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [06-20|17:41:49.75756] Regenerated local transaction journal    transactions=0 accounts=0
INFO [06-20|17:41:49.757872] Starting P2P networking 
INFO [06-20|17:41:51.914746] UDP listener up                          self=enode://a42c2cfd562a0edf5ec8b647b48fa3f51639ab7a37191046578777c100022fae08976a82806def07c67c11d9b24e33aaa1e2c7a039d85803dcd78724ba2a422f@[::]:30303
INFO [06-20|17:41:51.915259] RLPx listener up                         self=enode://a42c2cfd562a0edf5ec8b647b48fa3f51639ab7a37191046578777c100022fae08976a82806def07c67c11d9b24e33aaa1e2c7a039d85803dcd78724ba2a422f@[::]:30303
INFO [06-20|17:41:51.918433] IPC endpoint opened                      url=/data0/eth/geth.ipc
INFO [06-20|17:42:01.916843] Block synchronisation started 
INFO [06-20|17:42:04.015969] Imported new block headers               count=192 elapsed=1.016s number=192 hash=723899…123390 ignored=0
INFO [06-20|17:42:04.032948] Imported new block receipts              count=2   elapsed=168.99µs number=2   hash=b495a1…4698c9 size=8.00B  ignored=0
INFO [06-20|17:42:04.087556] Imported new block headers               count=192 elapsed=68.154ms number=384 hash=d3d5d5…c79cf3 ignored=0

启动参数:

  • –datadir,用于指定目录

接下来,进入/data0/eth的指定目录。


> cd /data0/eth
> ll
total 16
drwxr-xr-x 4 root root 4096 Jun 20 17:43 ./
drwxr-xr-x 5 root root 4096 Jun 20 17:41 ../
drwx------ 5 root root 4096 Jun 20 17:43 geth/
srw------- 1 root root    0 Jun 20 17:43 geth.ipc=
drwx------ 2 root root 4096 Jun 20 17:41 keystore/

有2个文件夹,分别存入不同的文件:

  • geth, 用于存储公链的数据
  • keystore, 用于存储秘钥
  • geth.ipc=, 启动时产生一个文件

接下来,我们打开一个命令工作台


> geth --datadir=/data0/eth attach
Welcome to the Geth JavaScript console!

instance: Geth/v1.8.12-unstable-f1986f86/linux-amd64/go1.10.3
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

# 输入eth命令
> eth
{
  accounts: [],
  blockNumber: 0,
  coinbase: undefined,
  compile: {
    lll: function(),
    serpent: function(),
    solidity: function()
  },
  defaultAccount: undefined,
  defaultBlock: "latest",
  gasPrice: 18000000000,
  hashrate: 0,
  mining: false,
  pendingTransactions: [],
  protocolVersion: "0x3f",
  syncing: {
    currentBlock: 1841355,
    highestBlock: 5822416,
    knownStates: 4513217,
    pulledStates: 4491604,
    startingBlock: 1628922
  },
  call: function(),
  contract: function(abi),
  estimateGas: function(),
  filter: function(options, callback, filterCreationErrorCallback),
  getAccounts: function(callback),
  getBalance: function(),
  getBlock: function(),
  getBlockNumber: function(callback),
  getBlockTransactionCount: function(),
  getBlockUncleCount: function(),
  getCode: function(),
  getCoinbase: function(callback),
  getCompilers: function(),
  getGasPrice: function(callback),
  getHashrate: function(callback),
  getMining: function(callback),
  getPendingTransactions: function(callback),
  getProtocolVersion: function(callback),
  getRawTransaction: function(),
  getRawTransactionFromBlock: function(),
  getStorageAt: function(),
  getSyncing: function(callback),
  getTransaction: function(),
  getTransactionCount: function(),
  getTransactionFromBlock: function(),
  getTransactionReceipt: function(),
  getUncle: function(),
  getWork: function(),
  iban: function(iban),
  icapNamereg: function(),
  isSyncing: function(callback),
  namereg: function(),
  resend: function(),
  sendIBANTransaction: function(),
  sendRawTransaction: function(),
  sendTransaction: function(),
  sign: function(),
  signTransaction: function(),
  submitTransaction: function(),
  submitWork: function()
}

新建一个账户,test.dan


# 查看我的账户 
> eth.accounts
[]

# 新建一个账户
> personal.newAccount("test.dan")
"0x377410e6b50762a51d54d9f26830e60124072f35"

# 再查看我的账户
> eth.accounts
["0x377410e6b50762a51d54d9f26830e60124072f35"]

# 查看账号余额
> eth.getBalance(eth.accounts[0])
0

同时,我们也可以直接通过etherscan,以太坊的区块浏览器来查询这个新建的账号的情况。

从网页上,我们可以看到这个地址已经生效,只是没有金额。看到这些信息,代表你的geth程序已经启动了。有几十G的数据,需要同步!

安装geth相比bitcoin安装复杂度差不多,按照官方文档的介绍基本能走通的,安装过程对于技术人来不是什么大问题。不同的公链,有不同的节点软件,安装方法也不同,下一篇文章将介绍EOS的客户端EOSIO的安装。

转载请注明出处:
http://blog.fens.me/bitcoin-install-geth

打赏作者

bitcoin比特币节点安装

比特币吸金之道系列文章,由计算机黑客发明的网络货币,无国界,无政府,无中心。没有政府滥发货币,没有通货膨胀。在全球计算机网络中,自由的实现货币兑换和流通。

本系列文章只讲程序和策略,不谈挖矿…

关于作者:

  • 张丹(Conan), 程序员/Quant: Java,R,Nodejs
  • blog: http://blog.fens.me
  • email: bsspirit@gmail.com

转载请注明出处:
http://blog.fens.me/bitcoin-install

前言

量化交易的第一步就是获取数据,那么获得比特币的数据,最直接的方法就是搭建一个比特币的客户端,直接从比特币的公链上面同步账本获得数据。比特币网络的构建基础,是基于无中心节点和透明化,这样每个节点都会获得比特币网络中的全量数据。

那么,先我们从搭建bitcoin客户端节点开始吧。

目录

  1. bitcoin安装过程
  2. 启动bitcoin的节点

1. bitcoin安装过程

从源代码安装bitcoin客户端的操作过程,分为以下7步:

  1. 从github下载代码库
  2. 切换最新的版本
  3. 安装系统依赖库
  4. 运行autogen.sh脚本
  5. 运行configure脚本
  6. 运行make和make install
  7. 验证bitcoin安装成功

接下来,我们就一步一步的进行操作。本文使用的Linux系统环境为:Linux Ubuntu 16.04 LTS 64bit。

1.1 先从bitcoin的官方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 运行configure脚本

执行完成后,发现当前目标生了configure文件,然后运行configure文件。运行时,会出现一个BerkerlyDB的错误,它指定要求装4.8版本的BerkerlyDB。解决方法有2种,第1种,去下载对应版本的BerkerlyDB;第二种,跳过这一步的检查。我们先用第2种方法,跳过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 验证bitcoin安装成功

验证bitcoin安装成功,有2个命令 bitcoin-cli和bitcoind。我们需要检查一下,是否这个启动命令,安装到在系统环境中。

  • bitcoind,用于启动bitcoin的节点,同步账本数据。
  • bitcoin-cli,用于与bitcoind节点通信。

查看启动命令的系统安装位置。


> which bitcoin-cli
/usr/local/bin/bitcoin-cli

> which bitcoind
/usr/local/bin/bitcoind

分别查看bitcoind 和 bitcoin-cli 命令的帮助信息。


> bitcoind -help
> bitcoin-cli -help

这样就完成了,bitcoin的客户端的安装。

2. 启动bitcoin节点

通过bitcoind命令启动bitcoin的核心客户端程序。运行前,我先要定义一个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

....

启动参数:

  • -datadir,用于指定目录
  • -conf,用于指定配置文件
  • -printtoconsole,用于控制台输出

如果打算后台执行,可以增加-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": ""
}

看到这些信息,代表你的bitcoin程序已经启动了。有几十G的数据,需要同步!

安装bitcoin相比用apt安装要复杂一些,不过按照官方文档的介绍基本能走通的,安装过程对于技术人来不是什么大问题。不同的公链,有不同的节点软件,安装方法也不同,下一篇文章将介绍以太坊的客户端Geth的安装

转载请注明出处:
http://blog.fens.me/bitcoin-install

打赏作者