Ubuntu系統下BTC服務安裝

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章