代码拉取完成,页面将自动刷新
搭建 docker 的 ethereum 节点
docker version
docker run --rm -it ethereum/client-go version
Version: 1.8.18-unstable
本人使用golang编程,所以:目录设置为 $GOPATH/src/github.com/ikaiguang/docker-ethereum
你可以自定义工作目录
cd path/to/your_path
git clone https://github.com/ikaiguang/docker-ethereum.git
# work path
cd path/to/your_path/docker-ethereum
docker network create --subnet 172.200.0.0/16 ethereum-node
# docker 网路
docker network create --subnet 172.200.0.0/16 ethereum-node
# 工作目录
cd $GOPATH/src/github.com/ikaiguang/docker-ethereum
# 节点目录
cd alone_node
# 启动
docker run -itd --restart=always \
--name ethereum-node \
--network ethereum-node --ip 172.200.0.30 \
-v $(pwd)/ethereum_conf:/ethereum_conf \
-v $(pwd)/ethereum_data:/ethereum_data \
-p "58545:18545" \
-p "58546:18546" \
-p "50303:10303" \
ethereum/client-go \
--datadir "/ethereum_data" \
--identity "node1" \
--nodiscover \
--dev --dev.period 1 \
--networkid 147852369 \
--ipcdisable \
--rpcport 18545 \
--wsport 18546 \
--port 10303 \
--verbosity 6 \
--rpc --rpcaddr "0.0.0.0" \
--rpccorsdomain "*" \
--rpcapi "eth,net,web3,rpc,admin,personal,clique,debug,miner,shh,txpool" \
console
# 自动挖矿 : --dev --dev.period 1
# 限制 rpc api 选项 : --rpcapi "db,eth,net,web3,personal,admin"
# modules: admin:1.0 clique:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 web3:1.0
其他
# log
docker logs -f ethereum-node
# exec
docker exec -it ethereum-node /bin/sh
# restart
docker restart ethereum-node
# remove
docker rm -f ethereum-node
节点操作
# 连接节点
# docker 容器内
geth attach http://127.0.0.1:18545
# 宿主机
geth attach http://127.0.0.1:58545
# 其他连接示例
# geth attach ipc:<datadir>/geth.ipc
# geth attach ws://191.168.1.1:18546
# 节点id
admin.nodeInfo.enode
# 添加节点
# admin.addPeer("enode://node_id@ip:port")
# (ifconfig); (ifconfig|grep netmask|awk '{print $2}'); (ip a)
admin.addPeer
# 节点信息
net.listening
net.peerCount
admin.peers
# 账户
eth.accounts
# 余额
eth.getBalance
# work path
cd $GOPATH/src/github.com/ikaiguang/docker-ethereum/cluster_node1
# 创建账户 1
docker run --rm -it \
-v $(pwd)/ethereum_conf:/ethereum_conf \
-v $(pwd)/ethereum_data:/ethereum_data \
ethereum/client-go \
--datadir "/ethereum_data" \
account new
# 创建账户 2
docker run --rm -it \
-v $(pwd)/ethereum_conf:/ethereum_conf \
-v $(pwd)/ethereum_data:/ethereum_data \
ethereum/client-go \
--datadir "/ethereum_data" \
account new
# 修改所有节点的 ethereum_conf 目录下的 genesis.json 文件的 alloc 地址为创建的两个地址
90e440e8b7bb0ccc780b614c75956d475cef16a3
7c6262d1b3d8db591bafa71b716e44b5b298c669
搭建 3 个节点的集群
# docker 网路
docker network create --subnet 172.200.0.0/16 ethereum-node
# work path
cd $GOPATH/src/github.com/ikaiguang/docker-ethereum/cluster_node1
# init genesis.json
docker run --rm -it \
-v $(pwd)/ethereum_conf:/ethereum_conf \
-v $(pwd)/ethereum_data:/ethereum_data \
ethereum/client-go \
--datadir "/ethereum_data" \
init /ethereum_conf/genesis.json
# start
docker run -itd --restart=always \
--name ethereum-node-1 \
--network ethereum-node --ip 172.200.0.31 \
-v $(pwd)/ethereum_conf:/ethereum_conf \
-v $(pwd)/ethereum_data:/ethereum_data \
-p "18545:18545" \
-p "18546:18546" \
-p "10303:10303" \
ethereum/client-go \
--datadir "/ethereum_data" \
--identity "node1" \
--nodiscover \
--networkid 147852369 \
--ipcdisable \
--rpcport 18545 \
--wsport 18546 \
--port 10303 \
--verbosity 6 \
--rpc --rpcaddr "0.0.0.0" \
--rpccorsdomain "*" \
--rpcapi "eth,net,web3,rpc,admin,personal,clique,debug,miner,shh,txpool" \
console
# work path
cd $GOPATH/src/github.com/ikaiguang/docker-ethereum/cluster_node2
# init genesis.json
docker run --rm -it \
-v $(pwd)/ethereum_conf:/ethereum_conf \
-v $(pwd)/ethereum_data:/ethereum_data \
ethereum/client-go \
--datadir "/ethereum_data" \
init /ethereum_conf/genesis.json
# start
docker run -itd --restart=always \
--name ethereum-node-2 \
--network ethereum-node --ip 172.200.0.32 \
-v $(pwd)/ethereum_conf:/ethereum_conf \
-v $(pwd)/ethereum_data:/ethereum_data \
-p "28545:18545" \
-p "28546:18546" \
-p "20303:10303" \
ethereum/client-go \
--datadir "/ethereum_data" \
--identity "node2" \
--nodiscover \
--networkid 147852369 \
--ipcdisable \
--rpcport 18545 \
--wsport 18546 \
--port 10303 \
--verbosity 6 \
--rpc --rpcaddr "0.0.0.0" \
--rpccorsdomain "*" \
--rpcapi "eth,net,web3,rpc,admin,personal,clique,debug,miner,shh,txpool" \
console
# work path
cd $GOPATH/src/github.com/ikaiguang/docker-ethereum/cluster_node3
# init genesis.json
docker run --rm -it \
-v $(pwd)/ethereum_conf:/ethereum_conf \
-v $(pwd)/ethereum_data:/ethereum_data \
ethereum/client-go \
--datadir "/ethereum_data" \
init /ethereum_conf/genesis.json
# start
docker run -itd --restart=always \
--name ethereum-node-3 \
--network ethereum-node --ip 172.200.0.33 \
-v $(pwd)/ethereum_conf:/ethereum_conf \
-v $(pwd)/ethereum_data:/ethereum_data \
-p "48545:18545" \
-p "48546:18546" \
-p "40303:10303" \
ethereum/client-go \
--datadir "/ethereum_data" \
--identity "node3" \
--nodiscover \
--networkid 147852369 \
--ipcdisable \
--rpcport 18545 \
--wsport 18546 \
--port 10303 \
--verbosity 6 \
--rpc --rpcaddr "0.0.0.0" \
--rpccorsdomain "*" \
--rpcapi "eth,net,web3,rpc,admin,personal,clique,debug,miner,shh,txpool" \
console
# 节点1
docker exec -it ethereum-node-1 /bin/sh
geth attach http://127.0.0.1:18545
admin.nodeInfo.enode
# 节点2
docker exec -it ethereum-node-2 /bin/sh
geth attach http://127.0.0.1:18545
admin.nodeInfo.enode
# 节点3
docker exec -it ethereum-node-3 /bin/sh
geth attach http://127.0.0.1:18545
admin.nodeInfo.enode
static-nodes.json
节点id,ip地址,端口必须对应 : "enode://节点id@ip地址:端口"
[
"enode://1e9f4506fb9462fdcf33ae2a7af681324b1e97f033a4bffbb4a3263ce3739d7c144fa8e0406b54be90155550a1720f66360d053027ba7279a47e299384cb754f@172.200.0.31:10303",
"enode://9f9c3a79a6d2c00abb15d0ecfaa38cd4b73b070380f52388c27a6a814f5720f8d68659290913dd392a080e356773c982a45b1d178fb647afaa179a1c4645b3cf@172.200.0.32:10303",
"enode://99f7bb708dae6890221dfee0e22cecf4c27af7f14f341001b12d83a9b6cb1c16b2950b7cdfb8000d5fcad5407252754ec20386eef8c9e6d47885436c6f4ea888@172.200.0.33:10303"
]
static-nodes.json
到节点数据目录
cp static-nodes.json $GOPATH/src/github.com/ikaiguang/docker-ethereum/cluster_node1/ethereum_data
cp static-nodes.json $GOPATH/src/github.com/ikaiguang/docker-ethereum/cluster_node2/ethereum_data
cp static-nodes.json $GOPATH/src/github.com/ikaiguang/docker-ethereum/cluster_node3/ethereum_data
docker restart ethereum-node-1 ethereum-node-2 ethereum-node-3
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型