ETH 私鏈搭建
阿新 • • 發佈:2018-08-11
base apt times nco slim git limit repo add
一.下載ETH源碼
github網址: https://github.com/ethereum/go-ethereum
二.編譯
1.首先下載ETH相關的工具
sudo add-apt-repository -y ppa:ethereum/ethereum sudo apt-get update sudo apt-get install ethereum
2.下載golang
https://golang.google.cn/dl/
下載後解壓到/usr/local/go,然後在/usr/profile中添加環境變量 :
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
3.編譯
cd go-ethereum
make geth
三. 環境配置與運行
1.編寫genesis.json文件,放到~/config下面,內容如下:
{ "config": { "chainId": 10, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }, "alloc" : {}, "coinbase" : "0x0000000000000000000000000000000000000000", "difficulty" : "0x02000000", "extraData" : "", "gasLimit" : "0x2fefd8", "nonce" : "0x0000000000000042", "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp" : "0x00" }
2.運行節點
geth --datadir ~/ether/n1 init genesis.json geth --identity "hello" --datadir ~/ether/n1 --port 30301 --rpcport 8101--networkid 12345 console 2>> ~/ether/n1/geth.log
成功後再獲取節點信息:
> admin.nodeInfo { enode: "enode://cc21a7d2d54587fbac48cc6ae942918fb6e833811dc2ee8acbecb0a32072273489cf8b863e358b6136ab97774477ee63fe7850d184ba3aca869b190551047066@[::]:30301", id: "cc21a7d2d54587fbac48cc6ae942918fb6e833811dc2ee8acbecb0a32072273489cf8b863e358b6136ab97774477ee63fe7850d184ba3aca869b190551047066", ip: "::", listenAddr: "[::]:30301", name: "Geth/hello/v1.8.12-stable-37685930/linux-amd64/go1.10", ports: { discovery: 30301, listener: 30301 }, protocols: { eth: { config: { chainId: 10, eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000", eip155Block: 0, eip158Block: 0, homesteadBlock: 0 }, difficulty: 33554432, genesis: "0xbf289100224ae9e27375b93509ff30b7624af5e8ae3eae472e814a2dd6ad1419", head: "0xbf289100224ae9e27375b93509ff30b7624af5e8ae3eae472e814a2dd6ad1419", network: 12345 } } }
將第二臺和第三臺的機器按照上面的步驟部署,
機器二和機器三的encode:
enode://d0aa73f9dbf892ad5ca9fd9a12c67622603b8b126616730d7d202a76edc9a51341b8c3c173a48b3897c11af1b0f4d07fd63122c0dfa9b57cf46b2cb0806ed91f@[::]:30301
enode://545e112d84633ad17c537bd402a87cf17572b5efb5c4e639c88fc16ce41795b28bc1d0ba9f4e4406284566ac88480c9f15651c140f0a37db521beecffe79efa2@[::]:30301
將它們加入到機器一的連接中,在機器一中接著運行:
admin.addPeer("enode://d0aa73f9dbf892ad5ca9fd9a12c67622603b8b126616730d7d202a76edc9a51341b8c3c173a48b3897c11af1b0f4d07fd63122c0dfa9b57cf46b2cb0806ed91f@[::]:30301") admin.addPeer("enode://545e112d84633ad17c537bd402a87cf17572b5efb5c4e639c88fc16ce41795b28bc1d0ba9f4e4406284566ac88480c9f15651c140f0a37db521beecffe79efa2@[::]:30301")
再查看連接信息:
> net.peerCount 2 > admin.peers [{ caps: ["eth/61", "eth/62", "eth/63"], id: "07954219f1a52acfa7562ac841e77860505bb6f6cc948bc540b94326606679d33e805a21b21cb105eaf58f449b0acc84893560919afee00bbc01b8a3fc0213af", name: "Geth/v1.4.5-stable-a269a713/linux/go1.6.2/hello", network: { localAddress: "219.216.65.127:30301", remoteAddress: "219.216.64.144:36332" }, protocols: { eth: { difficulty: 5290384, head: "337f2059a1a6d82aee1afba91828d86a8a3b6f85d83b8cb2f8a9210af3b29c1c", version: 63 } } }, { caps: ["eth/61", "eth/62", "eth/63"], id: "54b7b1dccbe37148cda6e0c9889d23ffb8e2efc905f3c2d001cd66b3b513210a4a426706bab795d83d0c236b9b1647f46947d86c48ac8faf7f802aff318c4aa1", name: "Geth/v1.4.5-stable/windows/go1.6.2/hello", network: { localAddress: "219.216.65.127:30301", remoteAddress: "219.216.65.139:50911" }, protocols: { eth: { difficulty: 5290384, head: "337f2059a1a6d82aee1afba91828d86a8a3b6f85d83b8cb2f8a9210af3b29c1c", version: 63 } } }]
表示連接成功,至此結束。
ETH 私鏈搭建