当前位置: 首页 > 工具软件 > Burrow > 使用案例 >

使用docker部署Hyperledger burrow

陆宾白
2023-12-01

环境

  • os:centos7.6
  • docker-ce 19.03.5

1. 获取镜像

1.1 方式一:根据源码构建

如果修改了代码,需要自己构建

git clone https://github.com/hyperledger/burrow.git
cd burrow
git checkout v0.30.2
make docker_build

查看已构建的镜像

docker images|grep burrow
hyperledger/burrow     0.30.2    b7c5643e3e31     26 seconds ago  54.4MB

Dockerfile

# For solc binary
FROM ethereum/solc:0.5.12 as solc-builder
# We use a multistage build to avoid bloating our deployment image with build dependencies
FROM golang:1.13-alpine3.11 as builder

RUN apk add --no-cache --update git bash make

ARG REPO=/src/burrow
COPY . $REPO
WORKDIR $REPO

# Build purely static binaries
RUN make build

# This will be our base container image
FROM alpine:3.11

# Variable arguments to populate labels
ARG USER=burrow
ARG INSTALL_BASE=/usr/local/bin

# Fixed labels according to container label-schema
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.name = "Burrow"
LABEL org.label-schema.vendor="Hyperledger Burrow Authors"
LABEL org.label-schema.description="Hyperledger Burrow is a permissioned Ethereum smart-contract blockchain node."
LABEL org.label-schema.license="Apache-2.0"
LABEL org.label-schema.vcs-url="https://github.com/hyperledger/burrow"

# Run burrow as burrow user; not as root user
ENV BURROW_PATH /home/$USER
RUN addgroup -g 101 -S $USER && adduser -S -D -u 1000 $USER $USER
WORKDIR $BURROW_PATH

# Copy binaries built in previous stage
COPY --from=builder /src/burrow/bin/burrow $INSTALL_BASE/
COPY --from=solc-builder /usr/bin/solc $INSTALL_BASE/

# Expose ports for 26656:peer; 26658:info; 10997:grpc
EXPOSE 26656
EXPOSE 26658
EXPOSE 10997

USER $USER:$USER
ENTRYPOINT [ "burrow" ]

使用了多阶段构建,从ethereum/solc:0.5.12拷贝了solc命令,在golang:1.13-alpine3.11里构建出burrow程序,最后在alpine:3.11中运行,工作目录在/home/burrow。

1.2 方式二:从docker hub拉取

https://hub.docker.com/r/hyperledger/burrow

docker pull hyperledger/burrow:0.30.3

2. 部署burrow单节点

2.1 生成burrow配置(burrow.toml和.key目录)

docker run  --rm hyperledger/burrow:0.30.3 spec -p1 -f1 \
 | docker run  --rm -v $(pwd)/.keys:/home/burrow/.keys hyperledger/burrow:0.30.3  configure -s- >burrow.toml

2.2 创建数据目录,并拷贝配置文件和私钥

mkdir  ~/burrow && cp burrow.toml ~/burrow && cp -r .keys ~/burrow

2.3 启动burrow容器

docker rm burrow
docker run --name burrow -d -e BURROW_CONFIG_FILE=/home/burrow/burrow.toml -v ~/burrow:/home/burrow -p 26656:26656 -p 26658:26658 -p 10997:10997 hyperledger/burrow:0.30.3 start -v0 

2.4 查看容器是否启动

docker ps|grep burrow

2.5 查看日志

docker logs -f burrow

3. 部署burrow多节点

3.1生成burrow配置

需要几个节点就将-f2 修改为-f几,这里搭建两个节点,注意不能像单节点那样使用管道命令(使用管道只能生成一个配置,原因不明),这里分两步先生成创世配置genesis-spec,再生成burrow配置文件。

docker run  --rm hyperledger/burrow:0.30.3 spec -f2 >genesis-spec.json

docker run  --rm -v $(pwd)/:/home/burrow hyperledger/burrow:0.30.3 configure --genesis-spec=genesis-spec.json --pool 

3.2 修改配置文件

注意:所有配置文件都要修改:burrow000.toml、burrow001.toml

增加控制台输出

[Logging]
  Trace = false
  NonBlocking = false
  [Logging.RootSink]
    [Logging.RootSink.Output]
      OutputType = "file"
      Format = "json"
      Path = "burrow000.log"
  [[Logging.RootSink.Sinks]]
    [Logging.RootSink.Sinks.Output]
      OutputType = "stdout"
      Format = "terminal"

修改PersistentPeers地址,将127.0.0.1修改为宿主机ip,端口都改为26656

[Tendermint]
  PersistentPeers = "tcp://3fc44d83eaa1a0f526680062765ccdb19754ae9e@yourip:26656,tcp://62a04fd2c943439c9981c820bc004d463125e344@yourip:26656"

将监听地址修改为"0.0.0.0",监听端口还原。容器端口可以保持固定,我们可以映射到宿主机的任何端口。
Tendermint(peer):26656

[Tendermint]
  ListenPort = "26656"
  ListenHost = "0.0.0.0"

info:26658,GRPC:10997 ,Web3:2660

[RPC]
  [RPC.Info]
    Enabled = true
    ListenHost = "0.0.0.0"
    ListenPort = "26658"
  [RPC.GRPC]
    Enabled = true
    ListenHost = "0.0.0.0"
    ListenPort = "10997"
  [RPC.Web3]
    Enabled = true
    ListenHost = "0.0.0.0"
    ListenPort = "26660"

3.3 创建数据目录,并拷贝配置文件、私钥、节点配置

mkdir  ~/burrow000 && cp burrow000.toml ~/burrow000 && cp -r .keys ~/burrow000 && cp -r .burrow000 ~/burrow000
mkdir  ~/burrow001 && cp burrow001.toml ~/burrow001 && cp -r .keys ~/burrow001 && cp -r .burrow001 ~/burrow001

3.4 启动第一个容器

docker rm -f burrow000
docker run --name burrow000 -d -e BURROW_CONFIG_FILE=/home/burrow/burrow000.toml -v ~/burrow000:/home/burrow -p 26656:26656 -p 26658:26658 -p 26660:26660 -p 10997:10997 hyperledger/burrow:0.30.3 start -v0 

3.5 启动第二个容器

注意:这里映射到宿主机的端口+1了,因为已经被第一个节点占用了,如果部署在不同的宿主机就不用修改了

docker rm -f burrow001
docker run --name burrow001 -d -e BURROW_CONFIG_FILE=/home/burrow/burrow001.toml -v ~/burrow001:/home/burrow -p 26657:26656 -p 26659:26658 -p 26661:26660 -p 10998:10997 hyperledger/burrow:0.30.3 start -v1 

3.6 检查两个节点是否连接

查看peers是否有节点信息

curl yourip:26658/consensus
curl yourip:26659/consensus

3.7 总结

不建议使用docker搭建多节点,不如二进制来得方便,这里只是提供一种思路,后面将多节点会部署在k8s或openshift上。

 类似资料: