Docker-compsoe部署prysm-beacon-chain + geth服务(geth版本v1.14.0)

发布于:2024-05-11 ⋅ 阅读:(163) ⋅ 点赞:(0)

1、创建目录结构

~ # mkdir -p /data/docker-compose/eth
~ # cd /data/docker-compose/eth
/data/docker-compose/eth# mkdir beacondata  eth  ethdata  prysm

2、编写prysm-beacon-chain Dockerfile和启动脚本文件

/data/docker-compose/eth# vim Dockerfile
/data/docker-compose/eth# vim beacon-start.sh
#!/bin/bash

/usr/local/bin/beacon-chain generate-auth-secret

/usr/local/bin/beacon-chain \
    --accept-terms-of-use \
    --execution-endpoint=http://eth:8545 \
    --jwt-secret=/data/prysm/jwt.hex \
    --checkpoint-sync-url=https://beaconstate.info \
    --genesis-beacon-api-url=https://beaconstate.info \
    --datadir /data/beacondata
# 使用 Ubuntu 20.04 作为基础镜像
FROM ubuntu:20.04

# 安装必要的系统库和工具
RUN apt-get update && \
    apt-get install -y curl && \
    apt-get clean

# 创建存储数据的目录
RUN mkdir -p /data/prysm
WORKDIR /data/prysm

# 下载 Prysm beacon chain 二进制文件并将其复制到 /usr/local/bin/beacon-chain
RUN curl -Lo /usr/local/bin/beacon-chain https://github.com/prysmaticlabs/prysm/releases/download/v5.0.3/beacon-chain-v5.0.3-linux-amd64 && \
    chmod +x /usr/local/bin/beacon-chain && \
    ls -l /usr/local/bin/beacon-chain

#拷贝启动脚本并赋予执行权限
COPY beacon-start.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/beacon-start.sh

# 设定容器启动时运行的命令
ENTRYPOINT ["/usr/local/bin/beacon-start.sh"]

3、编写eth对应的Dockerfile

/data/docker-compose/eth#vim eth/Dockerfile

打eth镜像Dockerfile文件

# 使用 Ubuntu 20.04 作为基础镜像
FROM ubuntu:20.04

# 安装必要的系统库和工具
RUN apt-get update && \
    apt-get install -y curl && \
    apt-get clean

# 创建存储数据的目录
RUN mkdir -p /data/ethdata
WORKDIR /data/ethdata

# 下载 eth 二进制文件并将其解压到 /usr/local/bin/geth
RUN curl -Lo /tmp/geth.tar.gz https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.14.0-87246f3c.tar.gz && \
    tar -xzf /tmp/geth.tar.gz -C /tmp/ && \
    mv /tmp/geth-linux-amd64-1.14.0-87246f3c/geth /usr/local/bin/ && \
    chmod +x /usr/local/bin/geth && \
    rm /tmp/geth.tar.gz

# 设定容器启动时运行的命令
ENTRYPOINT ["/usr/local/bin/geth"]

4、编写docker-compose.yaml文件

version: '3.8'

services:
  prysm-beacon-chain:
    build: 
      context: .
      dockerfile: Dockerfile
    container_name: prysm-beacon-chain
    volumes:
      - ./prysm:/data/prysm
      - ./beacondata:/data/beacondata
    ports:
      - "4000:4000"
    networks:
      - eth_network
    command: >
      sh -c "/usr/local/bin/beacon-start.sh"

  eth:
    build: 
      context: ./eth
      dockerfile: Dockerfile
    container_name: eth
    volumes:
      - ./prysm/:/data/prysm/:ro
      - ./ethdata:/data/ethdata
    ports:
      - "3545:3545"
      - "8545:8545"     
    networks:
      - eth_network
    command: --cache 4096 --http --http.api web3,eth,net,personal,txpool,engine,admin --http.addr 0.0.0.0 --http.port 3545  --datadir /data/ethdata   --allow-insecure-unlock --rpc.allow-unprotected-txs  --authrpc.addr 0.0.0.0 --authrpc.port 8545 --authrpc.vhosts localhost --maxpeers=300 --authrpc.jwtsecret /data/prysm/jwt.hex
networks:
  eth_network:
    driver: bridge 

5、启动容器

/data/docker-compose/eth# docker-compose up -d
[+] Building 1.1s (12/12) FINISHED                                                                                                                                                                                                            
 => [internal] load build definition from Dockerfile                                                                                                                                                                                     0.0s
 => => transferring dockerfile: 1.13kB                                                                                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/ubuntu:20.04                                                                                                                                                                          0.9s
 => [internal] load .dockerignore                                                                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                                                                          0.0s
 => [1/7] FROM docker.io/library/ubuntu:20.04@sha256:874aca52f79ae5f8258faff03e10ce99ae836f6e7d2df6ecd3da5c1cad3a912b                                                                                                                    0.0s
 => [internal] load build context                                                                                                                                                                                                        0.0s
 => => transferring context: 388B                                                                                                                                                                                                        0.0s
 => CACHED [2/7] RUN apt-get update &&     apt-get install -y curl &&     apt-get clean                                                                                                                                                  0.0s
 => CACHED [3/7] RUN mkdir -p /data/prysm                                                                                                                                                                                                0.0s
 => CACHED [4/7] WORKDIR /data/prysm                                                                                                                                                                                                     0.0s
 => CACHED [5/7] RUN curl -Lo /usr/local/bin/beacon-chain https://github.com/prysmaticlabs/prysm/releases/download/v5.0.3/beacon-chain-v5.0.3-linux-amd64 &&     chmod +x /usr/local/bin/beacon-chain &&     ls -l /usr/local/bin/beaco  0.0s
 => [6/7] COPY beacon-start.sh /usr/local/bin/                                                                                                                                                                                           0.0s
 => [7/7] RUN chmod +x /usr/local/bin/beacon-start.sh                                                                                                                                                                                    0.2s
 => exporting to image                                                                                                                                                                                                                   0.0s
 => => exporting layers                                                                                                                                                                                                                  0.0s
 => => writing image sha256:55bbc4ebf584ed73c90d2e57dc5eaff32f3152f238e6c566af48fcc14463797d                                                                                                                                             0.0s
 => => naming to docker.io/library/eth_prysm-beacon-chain                                                                                                                                                                                0.0s
[+] Running 3/3
 ⠿ Network eth_eth_network       Created                                                                                                                                                                                                 0.1s
 ⠿ Container eth                 Started                                                                                                                                                                                                 0.3s
 ⠿ Container prysm-beacon-chain  Started

6、验证
1)查询容器运行情况

/data/docker-compose/eth# docker-compose ps
NAME                 COMMAND                  SERVICE              STATUS              PORTS
eth                  "/usr/local/bin/geth…"   eth                  running             0.0.0.0:3545->3545/tcp, 0.0.0.0:8545->8545/tcp, :::3545->3545/tcp, :::8545->8545/tcp
prysm-beacon-chain   "/usr/local/bin/beac…"   prysm-beacon-chain   running             0.0.0.0:4000->4000/tcp, :::4000->4000/tcp

2)查询目录结构图

/data/docker-compose/eth# tree -L 2
.
├── beacondata
│   ├── beaconchaindata
│   ├── blobs
│   ├── metaData
│   └── tosaccepted
├── beacon-start.sh
├── docker-compose.yaml
├── Dockerfile
├── eth
│   └── Dockerfile
├── ethdata
│   ├── geth
│   ├── geth.ipc
│   └── keystore
└── prysm
    └── jwt.hex

8 directories, 8 files

4)进入eth控制台查询同步情况

/data/docker-compose/eth# docker exec -it eth /bin/bash
root@44f580801f7c:/data/ethdata# geth attach /data/ethdata/geth.ipc 
Welcome to the Geth JavaScript console!

instance: Geth/v1.14.0-stable-87246f3c/linux-amd64/go1.22.2
at block: 0 (Thu Jan 01 1970 00:00:00 GMT+0000 (UTC))
 datadir: /data/ethdata
 modules: admin:1.0 debug:1.0 engine:1.0 eth:1.0 miner:1.0 net:1.0 rpc:1.0 txpool:1.0 web3:1.0

To exit, press ctrl-d or type exit
> eth.blockNumber
0
> eth.syncing
{
  currentBlock: 0,
  healedBytecodeBytes: 0,
  healedBytecodes: 0,
  healedTrienodeBytes: 0,
  healedTrienodes: 0,
  healingBytecode: 0,
  healingTrienodes: 0,
  highestBlock: 0,
  startingBlock: 0,
  syncedAccountBytes: 0,
  syncedAccounts: 0,
  syncedBytecodeBytes: 0,
  syncedBytecodes: 0,
  syncedStorage: 0,
  syncedStorageBytes: 0,
  txIndexFinishedBlocks: 0,
  txIndexRemainingBlocks: 1
}

5)日志查询
eth容器的日志查询

root@iZt4ndiwb4prb26wx84bsuZ:/data/docker-compose/eth# docker logs -f --tail 10 eth 
INFO [05-07|07:08:58.617] Looking for peers                        peercount=0 tried=111 static=0
INFO [05-07|07:09:08.638] Looking for peers                        peercount=0 tried=155 static=0
WARN [05-07|07:09:13.459] Post-merge network, but no beacon client seen. Please launch one to follow the chain!
INFO [05-07|07:09:18.754] Looking for peers                        peercount=1 tried=217 static=0
INFO [05-07|07:09:28.754] Looking for peers                        peercount=2 tried=86  static=0
INFO [05-07|07:09:38.757] Looking for peers                        peercount=2 tried=181 static=0
INFO [05-07|07:09:48.764] Looking for peers                        peercount=1 tried=192 static=0
INFO [05-07|07:09:58.801] Looking for peers                        peercount=1 tried=138 static=0
INFO [05-07|07:10:08.878] Looking for peers                        peercount=1 tried=171 static=0
INFO [05-07|07:10:18.956] Looking for peers                        peercount=2 tried=55  static=0
INFO [05-07|07:10:39.090] Looking for peers                        peercount=2 tried=124 static=0
INFO [05-07|07:10:49.112] Looking for peers                        peercount=2 tried=234 static=0
INFO [05-07|07:10:59.149] Looking for peers                        peercount=2 tried=204 static=0

beacon-chain日志查询

/data/docker-compose/eth# docker logs -f --tail 10 prysm-beacon-chain 
time="2024-05-07 07:11:09" level=error msg="Could not connect to execution client endpoint" error="403 Forbidden: invalid host specified
: 403 Forbidden: invalid host specified
" prefix=execution
time="2024-05-07 07:11:14" level=info msg="Processing blocks" batchSize=63 blocksPerSecond=3.1 estimatedTimeRemaining=1m39s latestProcessedSlot/currentSlot="9019841/9020154" peers=57 prefix=initial-sync startingFrom=0xbacdf551...
time="2024-05-07 07:11:23" level=warning msg="Skip processing batched blocks" error="could not process block in batch: got an unexpected error in JSON-RPC response: 403 Forbidden: invalid host specified
: received an undefined execution engine error" prefix=initial-sync
time="2024-05-07 07:11:23" level=warning msg="Skip processing batched blocks" error="beacon node doesn't have a parent in db with root: 0x7b382457f4227a872fd1cd583cb3e676cf606c4f0fa661f2b7f3c968f6543810 (in processBatchedBlocks, slot=9019905)" prefix=initial-sync
time="2024-05-07 07:11:23" level=warning msg="Skip processing batched blocks" error="beacon node doesn't have a parent in db with root: 0xcbd1a46c0325b4cb82b2f76f4cb5c4772de1d2769fd1a5fbc41c3571bb9b991e (in processBatchedBlocks, slot=9019969)" prefix=initial-sync
time="2024-05-07 07:11:23" level=warning msg="Skip processing batched blocks" error="beacon node doesn't have a parent in db with root: 0x08eff305d908b90e38b4f4ef82d77b2c23ceadf6a5b2546da144a0701e54f60b (in processBatchedBlocks, slot=9020033)" prefix=initial-sync
time="2024-05-07 07:11:40" level=info msg="Peer summary" activePeers=49 inbound=0 outbound=49 prefix=p2p