以太坊私有链搭建——POA(单主机)
一、单主机部署
(一)安装配置Go语言
1.1安装[Go语言]环境(linux)
下载Go 1.8版本的
wget https://golang.google.cn/dl/go1.11.4.linux-amd64.tar.gz
下载后解压目录
tar -zxvf go1.8.linux-amd64.tar.gz
将其移动到合适的位置
sudo mv go /usr/local
配置GOPATH的环境变量
export PATH=$PATH:/usr/local/go/bin
(二)下载geth并配置
2.1geth客户端下载地址(最好下载geth&tool版本)
https://geth.ethereum.org/downloads
2.2下载后解压缩
tar -zxvf geth-alltools-linux-amd64-1.10.17-25c9b49f.tar.gz
将其移动到合适的位置
sudo mv geth /usr/local
配置geth的环境变量:
export PATH=$PATH:/usr/local/geth-alltools-linux-amd64-1.10.17-25c9b49f
(三)使用的Go和Geth版本
Go:1.11.4
Geth & Tool:1.10.17
最好版本一致进行私有链搭建,不然有些参数和功能有差异
(四)搭建POA私有链
4.1bootnode配置
bootnode用于节点间通信和管理
在poachain2目录下建立三个文件夹,分别是bootdir,node1,node2三个文件夹。
mkdir poachain2
cd poachain2
mkdir bootdir node1 node2
在bootdir文件夹中配置bootnode节点用来做p2p网络路由
bootnode --genkey boot.key #创建名为boot.key的key文件。
bootnode --nodekey boot.key #启动bootnode路由节点。
#返回如下信息, 之后启动node节点时会用到,记录下来
enode://1472e9a4efd46449690d97eb248fdfa6208f94bef8389edaff0b7c43e15645292c0cb3167c824e8b1309f5396d8f97dc24fe7896c373e0f61d3064d7baf32f1d@127.0.0.1:0?discport=30301
#后台运行(节点通信时需要处于运行状态,建议一直运行)
nohup bootnode -nodekey boot.key -verbosity 9 -addr :30301 2>> bootnode_output.log &
4.2创建账户
在node1 node2 目录下创建账户
geth account new --datadir node0/keystore
geth account new --datadir node0/keystore
0x89D2b4Af9602115D67EE9EAD945012A129ba9350
0x136EbA275271Dd911000b914162632C31195898e
4.3产生创世块
使用puppeth
来产生创世文件. puppeth是geth自带的程序,可以引导用户创建geth的创世文件。
运行puppeth在poachain2目录产生创世块配置相关的json文件
root@0da3d8e84434:/workspace/app/poachain2# puppeth
+-----------------------------------------------------------+
| Welcome to puppeth, your Ethereum private network manager |
| |
| This tool lets you create a new Ethereum network down to |
| the genesis block, bootnodes, miners and ethstats servers |
| without the hassle that it would normally entail. |
| |
| Puppeth uses SSH to dial in to remote servers, and builds |
| its network components out of Docker containers using the |
| docker-compose toolset. |
+-----------------------------------------------------------+
Please specify a network name to administer (no spaces, hyphens or capital letters please)
> poa2
Sweet, you can set this via --network=poa2 next time!
INFO [03-06|08:16:25.057] Administering Ethereum network name=poa2
WARN [03-06|08:16:25.057] No previous configurations found path=/root/.puppeth/poa2
What would you like to do? (default = stats)
1. Show network stats
2. Configure new genesis
3. Track new remote server
4. Deploy network components
> 2
What would you like to do? (default = create)
1. Create new genesis from scratch
2. Import already existing genesis
> 1
Which consensus engine to use? (default = clique)
1. Ethash - proof-of-work
2. Clique - proof-of-authority
> 2
How many seconds should blocks take? (default = 15)
> 2
Which accounts are allowed to seal? (mandatory at least one)
> 0x89D2b4Af9602115D67EE9EAD945012A129ba9350
> 0x136EbA275271Dd911000b914162632C31195898e
> 0x
Which accounts should be pre-funded? (advisable at least one)
> 0x89D2b4Af9602115D67EE9EAD945012A129ba9350
> 0x
Should the precompile-addresses (0x1 .. 0xff) be pre-funded with 1 wei? (advisable yes)
> y
Specify your chain/network ID if you want an explicit one (default = random)
> 1501
INFO [03-06|08:17:42.762] Configured new genesis block
What would you like to do? (default = stats)
1. Show network stats
2. Manage existing genesis
3. Track new remote server
4. Deploy network components
> 2
1. Modify existing configurations
2. Export genesis configurations
3. Remove genesis configuration
> 2
Which folder to save the genesis specs into? (default = current)
Will create poa2.json, poa2-aleth.json, poa2-harmony.json, poa2-parity.json
>
INFO [03-06|08:18:12.002] Saved native genesis chain spec path=poa2.json
ERROR[03-06|08:18:12.002] Failed to create Aleth chain spec err="unsupported consensus engine"
ERROR[03-06|08:18:12.003] Failed to create Parity chain spec err="unsupported consensus engine"
INFO [03-06|08:18:12.003] Saved genesis chain spec client=harmony path=poa2-harmony.json
What would you like to do? (default = stats)
1. Show network stats
2. Manage existing genesis
3. Track new remote server
4. Deploy network components
> CRIT [03-06|08:18:16.906] Failed to read user input err=EOF
root@0da3d8e84434:/workspace/app/poachain2# ls
bootdir node1 node2 poa2-harmony.json poa2.json
4.4配置密码文件
cd node1
vi password.txt
cd node2
vi password.txt
4.5初始化节点
geth --datadir node1 init poa2.json
geth --datadir node2 init poa2.json
4.6启动节点(需确认bootnode开启)
#节点1
nohup geth --datadir node1 --networkid 981027 --ipcdisable -unlock '0x89D2b4Af9602115D67EE9EAD945012A129ba9350' --password node1/password.txt --mine --http.port 8545 --http --http.api "admin,eth,txpool,personal,web3" --ws.port 8546 --port 30303 --bootnodes 'enode://1472e9a4efd46449690d97eb248fdfa6208f94bef8389edaff0b7c43e15645292c0cb3167c824e8b1309f5396d8f97dc24fe7896c373e0f61d3064d7baf32f1d@127.0.0.1:0?discport=30301' --allow-insecure-unlock 2>>node1/eth_output.log &
#节点2
geth --datadir node2 --networkid 981027 --ipcdisable -unlock '0x136EbA275271Dd911000b914162632C31195898e' --password node1/password.txt --mine --http.port 8546 --http --http.api "admin,eth,txpool,personal,web3" --ws.port 8546 --port 30304 --bootnodes 'enode://1472e9a4efd46449690d97eb248fdfa6208f94bef8389edaff0b7c43e15645292c0cb3167c824e8b1309f5396d8f97dc24fe7896c373e0f61d3064d7baf32f1d@127.0.0.1:0?discport=30301' --allow-insecure-unlock console
当节点1启动节点2未启动时,日志会打印looking for peer,等待节点2的接入