CentOS 7 安裝以太坊(Etherum)Geth嘗試挖礦
阿新 • • 發佈:2019-01-08
本地私有鏈嘗試以太坊挖礦功能
參考
虛擬機器環境
2C4G20G,CentOS Linux release 7.4.1708 (Core)
安裝所需基礎工具:
yum update -y && yum install git wget bzip2 vim gcc-c++ ntp epel-release nodejs cmake -y
安裝Go
wget https://dl.google.com/go/go1.10.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.10.linux-amd64.tar.gz
echo 'export GOROOT=/usr/local/go' >> /etc/profile
echo 'export PATH=$PATH:$GOROOT/bin' >> /etc/profile
echo 'export GOPATH=/root/go' >> /etc/profile
echo 'export PATH=$PATH:$GOPATH/bin' >> /etc/profile
source /etc/profile
驗證
$ go version
go version go1.10 linux/amd64
克隆編譯專案go-ethereum
git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum
make all
在path中加入geth路徑
echo 'export PATH=$PATH:/opt/go-ethereum/build/bin' >> /etc/profile
source /etc/profile
驗證
$ geth version
Geth
Version: 1.8.2-unstable
Git Commit: bd6879ac518431174a490ba42f7e6e822dcb3ee1
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10
Operating System: linux
GOPATH =/root/go
GOROOT=/usr/local/go
配置私有鏈初始狀態,新建檔案genesis.json
{
"config": {
"chainId": 22,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : {},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x400",
"extraData" : "",
"gasLimit" : "0x2fefd8",
"nonce" : "0x0000000000000038",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}
初始化區塊鏈,生成創世區塊和初始狀態
geth --datadir /opt/data init /opt/eth/genesis.json
啟動節點,進入Geth的cli介面挖礦
geth --identity "TestNode" --rpc --rpcport "8545" --datadir /opt/data/ --port "30303" --nodiscover console
mine.start()總是null,挖不到,於是清空資料換一種方式啟動節點,進入Geth的cli介面並直接開始挖礦
geth --identity "TestNode" --rpc --rpcport "8545" --datadir /opt/data/ --port "30303" --nodiscover --dev --dev.period 1 console
加了兩個引數:--dev 表示自動建立一個賬戶並直接開始挖礦,--dev.period 1表示不用等有交易了才挖,如果設成0的話沒有交易挖礦就是null
檢視賬號
personal.listAccounts
[]
新建賬號,密碼123456
personal.newAccount(“123456”)
"0x7d84a2638c9b25a758026446e67c822f34247bd8"
檢視cionbase
eth.coinbase
"0x7d84a2638c9b25a758026446e67c822f34247bd8"
檢視區塊數量
eth.blockNumber
19
檢視賬號餘額
myAddress = "0x7d84a2638c9b25a758026446e67c822f34247bd8"
"0x480086c9411cc3297c4aa6773a2e07c7b1efbafe"
eth.getBalance("0x7d84a2638c9b25a758026446e67c822f34247bd8")
1.15792089237316195423570985008687907853269984665640564039457584007913129639927e+77
換另一個使用者挖礦
miner.setEtherbase("0x3e5b31e581546f2900c0f3289153c788c92a2b41")
報錯
WARN [03-05|23:08:47] Block sealing failed err="authentication needed: password or unlock"
解鎖挖礦使用者
personal.unlockAccount(eth.coinbase)
再更換挖礦使用者挖,又報錯
WARN [03-05|23:18:48] Block sealing failed err=unauthorized
再用誰挖都是null,暫時不試了,再繼續深入學習。