您的位置:首页 > 运维架构 > Docker

基于Docker的以太坊私有环境搭建

2017-11-27 18:02 363 查看
1 以太坊网络

1) 生产环境网络:消耗以太币的真实以太坊环境

2) 测试网络:不消耗以太币的公网开发调试环境

3) 私有网络:私有网络的节点才允许使用的网络

2 执行命令及参数解析

1) 执行命令

docker run -it -d --name eth-node -p 30303:30303 -p 8545:8545 --network eth-network --ip 172.25.0.10 ethereum/client-go --rpc --rpcaddr "0.0.0.0" --rpcapi "admin,debug,eth,miner,net,personal,shh,txpool,web3" --nodiscover --networkid 15 --fast --cache=512 --dev console 2>>/tmp/eth.log


2) Docker参数

-it:交互式运行模式,-i 标准输入给容器,-t 分配一个虚拟终端

-d:以守护进程方式运行(后台)

-p:指定端口号

-P:随机分配端口号

--name:指定容器名称

--network:指定网络连接

--ip:分配ip地址

3) Ethereum参数

--rpc:启用HTTP-RPC服务

--rpcaddr:HTTP-RPC服务监听接口(默认:localhost)

--rpcapi:HTTP-RPC接口提供的api(默认:eth、net、web3)

--fast:快速同步模式启动Geth

--cache=512:内存容量分配

--dev:开发模式

--nodiscover:节点不被其它节点发现,允许手动连接

--networkid:设置隔离网络(主网络id为1)

console:进入JavaScript控制台

3 搭建以太坊私有网络的三种方式(当前最新版本:Geth 1.8.4)

1) docker run ethereum/client-go --dev参数

说明:

--dev参数提供coinbase账户和一定数目的以太币用于开发、调试、测试;

miner.start()开启挖矿,等待交易“waiting for transaction”;

miner.sendTransaction(),挖矿打包交易,区块增加;



2) docker-geth-dev资源

资源链接:https://github.com/pragmaticcoders/docker-geth-dev

说明:提供运行容器,搭建私有网络并预先提供创建账户和账户余额。

下载项目文件

$ git clone https://github.com/pragmaticcoders/docker-geth-dev.git /docker-geth-dev



构建自定义ethereum镜像

$ make build




启动容器节点

$ make rpc


测试节点运行

$ make test


注:当前最新版本Geth 1.8,按照说明步骤创建以太坊私有开发环境有问题,容器未成功运行。

3) Dockerfile自定义镜像

说明:通过编写创世文件genesis.json,打包自定义ethereum镜像。

步骤1:Dockerfile文件(自定义)

步骤2:Init.sh脚本文件(自定义)

步骤3:Genesis.json文件(自定义)

{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"nonce": "0x00006d6f7264656e",
"difficulty": "0x20000",
"mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
"coinbase": "0xde1e758511a7c67e7db93d1c23c1060a21db4615",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x2FEFD8",
"alloc": {
"de1e758511a7c67e7db93d1c23c1060a21db4615": {
"balance": "1000"
},
"27dc8de9e9a1cb673543bd5fce89e83af09e228f": {
"balance": "1100"
},
"d64a66c28a6ae5150af5e7c34696502793b91ae7": {
"balance": "900"
}
}
}


步骤4:创建镜像

$ docker build -t ethereum/client-go:1.0 .


步骤5:启动容器

$ docker run -d --name eth-node -p 30303:30303 -p 8545:8545 --net eth-network --ip 172.25.0.10 ethereum/client-go:1.0


步骤6:查看账户信息

curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' 172.25.0.10:8545




4 参考

https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options



https://github.com/ethereum/go-ethereum/wiki/Private-network

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: