美文网首页
以太坊私有链网络配置

以太坊私有链网络配置

作者: 张_a1d6 | 来源:发表于2018-03-06 15:03 被阅读0次

一 环境以及软件版本:

1)VMware Workstation 12 Pro

2)Ubuntu 16.04 desktop

3)以太坊geth go语言客户端(Version: 1.8.2-unstable)

4)go语言版本 1.9.4(geth 需要1.7或以上的版本)

二 如何连接:

Geth会持续尝试在网络上连接到其他节点,直到有了端点为止。节点通过发现协议找到对等端。在发现协议中,节点互相

闲聊发现网络上的其他节点。最开始,geth会使用一系列辅助程序节点,这些辅助程序节点的端点记录在源代码中。

三 检查连接和enode身份:

通过net模块可以查看当前客户端连接的对等端数量以及节点是否在监听。

> net.listening

true

> net.peerCount

0


四 节点

Geth支持一个叫静态节点的特征,如果有特定的端点,它会一直想与静态节点连接,如果断开,静态节点就会再次连接。

可以配置永久性静态节点,在当前节点数据目录下创建static-nodes.json文件,内容如下:

[ "enode://f4642fa65af50cfdea8fa7414a5def7bb7991478b768e296f5e4a54e8b995de102e0ceae2e826f293c481b5325f89be6d207b003382e18a8ecba66fbaf6416c0@33.4.2.1:30303",

"enode://pubkey@ip:port"

]


也可以通过控制台添加

>admin.addPeer("enode://867739a9292f889afc02c5e2badb965886fd85d3a3a76a70d41def32240e85c105f46944d82ac68718e4f57cead2b23b96cf467ef949a4c231b996a368ff1169@[::]:30303?discport=0")

true


如果想要了解对等端点的信息(IP地址,端口号等等)

>admin.addPeer("enode://8fb1cc35aea0211046f480067bd24ae19181eaff507689a0e6d14ddd58b6441331c8c0d5158f6d0da6306da042c0ddb7d94baf578e1c9f82a36056e49b16660d@[::]:30303?discport=0" ... )

true

> admin.peers

[{ caps: ["eth/63"],

id:"8fb1cc35aea0211046f480067bd24ae19181eaff507689a0e6d14ddd58b6441331c8c0d5158f6d0da6306da042c0ddb7d94baf578e1c9f82a36056e49b16660d",

name: "Geth/v1.8.2-unstable-0b814d32/linux-amd64/go1.9.4",

network: {

inbound: false,

localAddress: "[::1]:41010",

remoteAddress: "[::1]:30303",

static: true,

trusted: false },

protocols: {

eth: {

difficulty: 262144,

head: "0xa0e580c6769ac3dd80894b2a256164a76b796839d2eb7f799ef6b9850ea5e82e",

version: 63 } } }]


本地起了两个节点以方便测试:

 //第一个节点

tmpPrivate# /eth/go-ethereum/build/bin/geth --datadir "chain" init genesis.json

/eth/go-ethereum/build/bin/geth --datadir "chain" --nodiscover --networkid 15 --port 30306 console 2>> eth.log

 //第二个节点 

tmpPrivateOne# /eth/go-ethereum/build/bin/geth --datadir "chain" init genesis.json

/eth/go-ethereum/build/bin/geth --datadir "chain" --nodiscover --networkid 15 console 2>> eth.log 

相关文章

网友评论

      本文标题:以太坊私有链网络配置

      本文链接:https://www.haomeiwen.com/subject/etelfftx.html