以太坊私网建立

先思考两个问题
决定存储区块链数据的目录
选择网络id,默认1为主网
为了在同一台机器能够运行两个节点,我们需要为不同的节点设置不同的port和rpcport。


开始编码
liyuechun:Desktop yuechunli$ cd 1015/
liyuechun:1015 yuechunli$ mkdir test
liyuechun:1015 yuechunli$ cd test/
liyuechun:test yuechunli$ 
查看你的ip地址
liyuechun:~ yuechunli$ ifconfig|grep netmask|awk '{print $2}' 
127.0.0.1
192.168.1.5
10.20.0.8
打开节点
liyuechun:test yuechunli$ geth --networkid 123 --datadir data1 --rpc --rpcaddr 192.168.1.5 --rpcport 8989 --port 3000 console
WARN [10-15|08:20:18] No etherbase set and no accounts found as default 
INFO [10-15|08:20:18] Starting peer-to-peer node               instance=Geth/v1.7.1-stable-05101641/darwin-amd64/go1.9.1
INFO [10-15|08:20:18] Allocated cache and file handles         database=/Users/liyuechun/Desktop/1015/test/hi/geth/chaindata cache=128 handles=1024
INFO [10-15|08:20:18] Writing default main-net genesis block 
INFO [10-15|08:20:18] Initialised chain configuration          config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Engine: ethash}"
INFO [10-15|08:20:18] Disk storage enabled for ethash caches   dir=/Users/liyuechun/Desktop/1015/test/hi/geth/ethash count=3
INFO [10-15|08:20:18] Disk storage enabled for ethash DAGs     dir=/Users/liyuechun/.ethash                          count=2
INFO [10-15|08:20:18] Initialising Ethereum protocol           versions="[63 62]" network=123
INFO [10-15|08:20:18] Loaded most recent local header          number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [10-15|08:20:18] Loaded most recent local full block      number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [10-15|08:20:18] Loaded most recent local fast block      number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [10-15|08:20:18] Regenerated local transaction journal    transactions=0 accounts=0
INFO [10-15|08:20:18] Starting P2P networking 
INFO [10-15|08:20:20] UDP listener up                          self=enode://032ff589bae471ab0884cce696a632fcb44ec9b7c33dfa5c06e547de099ed116360e74172c0398396588e6a374bf0dd7da1558e0a4899e9670d2ce7a1967cf11@[::]:3000
INFO [10-15|08:20:20] RLPx listener up                         self=enode://032ff589bae471ab0884cce696a632fcb44ec9b7c33dfa5c06e547de099ed116360e74172c0398396588e6a374bf0dd7da1558e0a4899e9670d2ce7a1967cf11@[::]:3000
INFO [10-15|08:20:20] IPC endpoint opened: /Users/liyuechun/Desktop/1015/test/hi/geth.ipc 
INFO [10-15|08:20:20] HTTP endpoint opened: http://192.168.1.4:8545 
Welcome to the Geth JavaScript console!


instance: Geth/v1.7.1-stable-05101641/darwin-amd64/go1.9.1
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0



多节点连接
Enode url其实就是和另外一个节点互动的唯一的id。


节点A
> admin.nodeInfo.enode 
"enode://032ff589bae471ab0884cce696a632fcb44ec9b7c33dfa5c06e547de099ed116360e74172c0398396588e6a374bf0dd7da1558e0a4899e9670d2ce7a1967cf11@[::]:3000"

[::]等价于192.168.1.5,3000是端口号。


节点B
如果是同一台电脑,需要设置不同的rcpport和不同的port。如果是不同的电脑,直接重复上面节点A的步骤即可。


> admin.addPeer("enode://032ff589bae471ab0884cce696a632fcb44ec9b7c33dfa5c06e547de099ed116360e74172c0398396588e6a374bf0dd7da1558e0a4899e9670d2ce7a1967cf11@[::]:3000")
> true
查看节点
admin.peers 
查看连接节点数
> web3.net.peerCount
1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

devopen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值