以太坊POA共识的私有联盟链的建立

以太坊POA共识的私有联盟链的建立,采用geth客户端进行多机联盟链的配置部署

 

更多区块链技术与应用分类:

区块链应用    区块链开发

以太坊 | Fabric | BCOS | 密码技术 | 共识算法 | 比特币其他链

通证经济传统金融场景 | 去中心化金融 | 防伪溯源 | 数据共享 | 可信存证

基本环境

主机节点 -----> IP

主机节点1 172.27.83.194

主机节点2 172.27.83.114

主机节点3 172.27.83.115

配置环节

进入主机节点1,创建必要文件,然后再向其他节点分发。

下载最新源码

进入go-ethereum目录

make all
sudo ln -s $PWD/build/bin/* /usr/local/bin/

创建目录及生成秘钥

在目录/home/user_dev/wanghaoyi/privateEthereum下执行

mkdir bootdir
mkdir boot1
mkdir boot2
cd bootdir
bootnode --genkey boot.key
bootnode --nodekey=boot.key -verbosity 9

显示

enode://214bb2e74a4f4b5a79d685b2bc1118fe55689c2c80db8f72ab21fe37c89091e05a90de2252a1c53a995cc54d0ee3dcbf67c9733b611c37f77227cf11992905a5@127.0.0.1:0?discport=30301

创建账户

cd boot1
 
geth --datadir ./ account new
 
(password:ruanke)
 
0xA17F7ADdd0E9d0126A3a90d10407bdf82A32A506
 
cd boot2
 
geth --datadir ./ account new
 
(password:ruanke)
 
0x0DbD92EDe044269b4853321e472eb3bC53baE4cA

在boot上级目录运行puppeth

用以生成创世区块

 

以太坊POA共识的私有联盟链的建立

复制配置文件

cp 1818.json ./boot1/
 
cp 1818.json ./boot2/

两个区块链节点初始化文件

cd boot1/
 
geth --datadir /home/user_dev/wanghaoyi/privateEthereum/boot1/ init 1818.json
 
cd boot2/
 
geth --datadir /home/user_dev/wanghaoyi/privateEthereum/boot2/ init 1818.json

先在主机节点1启动bootnode

(首次启动其他节点时需要,后面断掉就无所谓了)

bootnode --genkey=boot.key
 
bootnode --nodekey=boot.key -verbosity 9

启动私链boot1区块链节点

nohup geth --networkid 1818 --datadir "/home/user_dev/wanghaoyi/privateEthereum/boot1/" --rpc --port 30310 -rpcaddr="0.0.0.0" --rpcport 7545 --rpcapi "web3,personal,admin,db,net,eth,miner,rpc,txpool,clique" --rpccorsdomain "" --ws -wsaddr="0.0.0.0" --wsport 8546 --wsapi "web3,personal,admin,db,net,eth,miner,rpc,txpool,clique" --wsorigins "" --unlock 0 --password pwd --bootnodes "enode://214bb2e74a4f4b5a79d685b2bc1118fe55689c2c80db8f72ab21fe37c89091e05a90de2252a1c53a995cc54d0ee3dcbf67c9733b611c37f77227cf11992905a5@127.0.0.1:0?discport=30301" --targetgaslimit 0x247b760 --syncmode "full" --nousb --allow-insecure-unlock --mine --minerthreads=1 --etherbase=0xA17F7ADdd0E9d0126A3a90d10407bdf82A32A506 > /home/user_dev/wanghaoyi/privateEthereum/boot1/ethRunning.log &

(--mine和--etherbase就能够在启动的同时进行挖矿,--etherbase一定要指明,才知道收益矿工是谁,因为其默认为“0”)

注意

若没有./geth目录则重新初始化,

cd boot2/
 
geth --datadir /home/user_dev/wanghaoyi/privateEthereum/boot2/ init 1818.json

将boot2复制到主机节点2

启动私链boot2区块链节点

nohup geth --networkid 18188 --datadir "/home/user_dev/wanghaoyi/privateEthereum/boot2/" --rpc --port 30310 -rpcaddr="0.0.0.0" --rpcport 7545 --rpcapi "web3,personal,admin,db,net,eth,miner,rpc,txpool,clique" --rpccorsdomain "" --ws -wsaddr="0.0.0.0" --wsport 8546 --wsapi "web3,personal,admin,db,net,eth,miner,rpc,txpool,clique" --wsorigins "" --unlock 0 --password pwd --bootnodes "enode://214bb2e74a4f4b5a79d685b2bc1118fe55689c2c80db8f72ab21fe37c89091e05a90de2252a1c53a995cc54d0ee3dcbf67c9733b611c37f77227cf11992905a5@**172.27.83.194:0?discport=30301**" --targetgaslimit 0x247b760 --syncmode "full" --nousb --allow-insecure-unlock --mine --minerthreads=1 --etherbase=0x0DbD92EDe044269b4853321e472eb3bC53baE4cA
> /home/user_dev/wanghaoyi/privateEthereum/boot2/ethRunning.log &

注意:

  • 若不在同一主机节点中,修改enode后IP为真实地址
  • 若账户余额显示为0,说明初始化未成功,初始化成功后即使不挖矿也可正常显示余额
  • 若产生以下错误:

WARN [08-14|13:33:20.770] System clock seems off by 2m45.277120101s, which can prevent network connectivity

WARN [08-14|13:33:20.770] Please enable network time synchronisation in system settings.

可用如下解决方法:

timedatectl set-ntp true
sudo systemctl start ntpd
sudo systemctl enable ntpd

geth 命令行 查看链接数>net

新增加区块链节点node3:

(1)创建keytore

cd boot3
 
geth --datadir ./ account new
 
(password:ruanke)
 
0x08aEF83902aFAFd1792FA56aDbF9167049fdCb67

(2) 初始化:

cd boot3/
 
geth --datadir /home/user_dev/wanghaoyi/privateEthereum/boot3/ init 1818.json

(3)在节点1启动前确保bootnode 处于启动

bootnode --nodekey=boot.key -verbosity 9

(4) 启动geth

nohup geth --networkid 1818 --datadir "/home/user_dev/wanghaoyi/privateEthereum/boot3/" --rpc --port 30310 -rpcaddr="0.0.0.0" --rpcport 7545 --rpcapi "web3,personal,admin,db,net,eth,miner,rpc,txpool,clique" --ws -wsaddr="0.0.0.0" --wsport 8546 --wsapi "web3,personal,admin,db,net,eth,miner,rpc,txpool,clique" --wsorigins "*" --unlock 0 --password pwd --bootnodes "enode://214bb2e74a4f4b5a79d685b2bc1118fe55689c2c80db8f72ab21fe37c89091e05a90de2252a1c53a995cc54d0ee3dcbf67c9733b611c37f77227cf11992905a5@**172.27.83.194:0?discport=30301**" --targetgaslimit 0x247b760 --syncmode "full" --nousb --allow-insecure-unlock > /home/user_dev/wanghaoyi/privateEthereum/boot3/ethRunning.log &

(5)提名挖矿

现在共有3个节点,所以需要一半以上的节点提名节点3的根账号,它才能被加入验证人列表。在boot1节点和boot2节点提名boot3的根账号:

clique.propose("0x08aef83902afafd1792fa56adbf9167049fdcb67",true)

(net显示peerCount为0,发现ntpd挂掉,使用:sudo systemctl restart ntpd,发现已成功连接其他节点,并开始同步区块。)


原文链接:以太坊POA共识的私有联盟链的建立

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值