1、包下载
下载地址:https://bitcoincore.org/en/download/
命令行下载:wget https://bitcoin.org/bin/bitcoin-core-0.19.0.1/bitcoin-0.19.0.1-x86_64-linux-gnu.tar.gz或wget https://bitcoincore.org/bin/bitcoin-core-0.19.0.1/bitcoin-0.19.0.1-x86_64-linux-gnu.tar.gz
注意:Ubuntu下载不要下载这个包bitcoin-0.19.0.1-riscv64-linux-gnu.tar.gz
2、配置路径结构
mkdir /data/BTC/
wget https://bitcoin.org/bin/bitcoin-core-0.19.0.1/bitcoin-0.19.0.1-x86_64-linux-gnu.tar.gz
cd /data/BTC/
mkdir btcdata
配置配置文件:此时的配置文件路径为/data/BTC/btcdata/bitcoin.conf
vim bitcoin.conf
rpcuser=btcrpc
rpcpassword=XXXXXXXXXXXXXXXXXXXXXXXXXXX
server=1
rpcallowip=0.0.0.0
rpcbind=0.0.0.0 #0.19版本的rpc默认只绑定127.0.0.1,之前版本默认是0.0.0.0
rpcport=8888
port=8889
txindex=1
datadir=/data/BTC/btcdata
切换到我们的启动路径下
cd /data/BTC
tar -xf bitcoin-0.19.0.1-x86_64-linux-gnu.tar.gz
cd BTC/bitcoin-0.19.0.1/bin
启动btc服务
./bitcoind --conf=/data/BTC/btcdata/bitcoin.conf -daemon
关闭btc服务
bitcoin-cli --conf=/data/BTC/btcdata/bitcoin.conf stop
# 查看区块链信息:如同步进度
/data/BTC/bitcoin-0.19.0.1/bin/bitcoin-cli -conf=/data/coins/BTC/btcdata/bitcoin.conf getblockchaininfo
例如如下
# /data/BTC/bitcoin-0.19.0.1/bin/bitcoin-cli -conf=/data/BTC/btcdata/bitcoin.conf getblockchaininfo
{
"chain": "main",
"blocks": 420330,
"headers": 619058,
"bestblockhash": "00000000000000000000000000000000000000000000000000000000000",
"difficulty": 213398925331.3239,
"mediantime": 1468268502,
"verificationprogress": 0.2786385637493364,
"initialblockdownload": true,
"chainwork": "0000000000000000000000000000000000000000000000000000000000",
"size_on_disk": 86874658516,
"pruned": false,
"softforks": {
"bip34": {
"type": "buried",
"active": true,
"height": 227931
},
"bip66": {
"type": "buried",
"active": true,
"height": 363725
},
"bip65": {
"type": "buried",
"active": true,
"height": 388381
},
"csv": {
"type": "buried",
"active": true,
"height": 419328
},
"segwit": {
"type": "buried",
"active": false,
"height": 481824
}
},
"warnings": ""
}
# 查询最新区块高度(没添加配置文件路径则需要输入密码)
curl --user btcrpc --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockchaininfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8888/
例如如下
# curl --user btcrpc --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockchaininfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8888/
Enter host password for user 'btcrpc':
{"result":{"chain":"main","blocks":413580,"headers":619058,"bestblockhash":"0000000000000000000000000000000000000000000000000000000000","difficulty":199312067531.243,"mediantime":1464310990,"verificationprogress":0.2588640920530745,"initialblockdownload":true,"chainwork":"0000000000000000000000000000000000000000000000000000000000","size_on_disk":80668134787,"pruned":false,"softforks":{"bip34":{"type":"buried","active":true,"height":227931},"bip66":{"type":"buried","active":true,"height":363725},"bip65":{"type":"buried","active":true,"height":388381},"csv":{"type":"buried","active":false,"height":419328},"segwit":{"type":"buried","active":false,"height":481824}},"warnings":""},"error":null,"id":"curltest"}
一些其他的相关命令
# 查看网络状态:
bitcoin-cli getnetworkinfo
# 查看网络节点:
bitcoin-cli getpeerinfo
# 查看区块链信息:如同步进度、
bitcoin-cli getblockchaininfo
# 查看所有命令
bitcoin-cli help