移除geth目录,便于移除旧的无效数据,因为节点刚启动的时候,使用的是默认创世配置,而自定义的又不一样,因此需要移除。
sudo rm -rf ~/data/meitu/node1/geth sudo rm -rf ~/data/meitu/node2/geth sudo rm -rf ~/data/meitu/node3/geth 2. 拷贝创世配置到数据目录将创世配置拷贝到数据目录中,便于容器内能访问,至于这个目录跟docker-compose.yml映射的目录有关。
因此,命令也要相应的变更。
进入容器,并执行初始化命令。
# 节点1 docker exec -it meitu_node_1 /bin/sh geth init /root/.ethereum/genesis.json # 节点2 docker exec -it meitu_node_2 /bin/sh geth init /root/.ethereum/genesis.json # 节点3 docker exec -it meitu_node_3 /bin/sh geth init /root/.ethereum/genesis.json**loop:重复在node2、node3上分别执行init
6. 重启节点网络以下命令需要在docker-compose.yml文件的当前目录方可运行。
# 移除容器 docker-compose down # 启动容器 docker-compose up -d 7. 查看验证人是否设置成功 1. 进入容器 docker exec -it meitu_node_3 /bin/sh 2. 进入geth JavaScript控制台 geth attach ipc:/root/.ethereum/geth.ipc 3. 执行获取验证人列表命令 dpos.getValidators() ["0x849f9442198282fb21539351edb0378463e4c251", "0x2c08f54d5b324c0175ea53b997f5ce1f61a7e4ed", "0xc4118320f3d3c37a2ca8dad5c2f2a40f2a23ba02"] 8. 节点互联 1. 查看节点是否互联 admin.peers []返回的数据为[],说明节点之间没有互相发现。
2. 设置节点互联 1. 查看每个节点信息 admin.nodeInfo确认:enode都不一样,protocols都一样。
记下三个enode
执行查看网络信息命令后,会返回一下内容
[ { "Name": "docker_default", "Id": "984fabf7e51b07c1984114720f98f305cc61cc26546cf9da4bcbbbc36a591351", "Created": "2018-12-05T06:06:13.435067024Z", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.20.0.0/16", "Gateway": "172.20.0.1" } ] }, "Internal": false, "Attachable": true, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": { "263f1553108cc8ea00b76598adb6d66649287943c7d0f50d0be02963863ff45c": { "Name": "meitu_node_2", "EndpointID": "9f4114a81133bd490b501ac45fd50fe512309f9096b5468054bd074bad45a07d", "MacAddress": "02:42:ac:14:00:03", "IPv4Address": "172.20.0.3/16", "IPv6Address": "" }, "3acd943c8e0759dc241d7cc623b1a1ca45096480dcd2fd0daa8b951407eb40bf": { "Name": "meitu_node_3", "EndpointID": "0480296c4e8217862358143a084da2d1563cd4f60105e6020434f222320681a5", "MacAddress": "02:42:ac:14:00:04", "IPv4Address": "172.20.0.4/16", "IPv6Address": "" }, "416fe5eb074c24f032d5bd49a6be68cf293a30af17780133b9fa63663e4b7097": { "Name": "meitu_node_1", "EndpointID": "0dc00e9c6f63f844502525b34e87baf62f4de852ac46907951d4b689dd89635f", "MacAddress": "02:42:ac:14:00:02", "IPv4Address": "172.20.0.2/16", "IPv6Address": "" } }, "Options": {}, "Labels": { "com.docker.compose.network": "default", "com.docker.compose.project": "docker", "com.docker.compose.version": "1.23.1" } } ]找到不同容器中,相应的IP地址。
记录下每个节点的IP,也可以用127.0.0.1加节点映射到本机的不同网络端口。
进入节点1 geth JavaScript 控制台后,执行以下命令:
# 添加节点2的监视器 admin.addPeer("enode://6ab4f74058b9c1e43d2d0c6f55f538ea7f2f366dd9f8f560024f14603333f017d3404b9c9711538289fa76504fecf33cf0e36cce7b0414604f673abe93012413@[172.20.0.3]:30303") # 添加节点3的监视器 admin.addPeer("enode://e82fecab04e5e902a9e4ea491527ea958d2cdeb83383dfa36562e32a51eedb204a541e00ef0b497704ec0e91017799a73283e53f6dffdeef492a4230626b10b6@[172.20.0.4]:30303") 4.查看节点网络