Hyperledger-fabric_麒麟系统_arm64搭建
Hyperledger-fabric_麒麟系统_arm64搭建
准备环境
服务器准备
自己没有麒麟系统没关系。花几十块钱去华为云上购买一个
规格: 鲲鹏通用计算增强型 | kc1.small.1 | 1vCPUs | 1GiB
镜像: CentOS 7.6 64bit with ARM
安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-18.06.3.ce docker-ce-cli-18.06.3.ce containerd.io
安装go
网站:https://studygolang.com/dl
查1.16版本arm64的go:
#wget https://studygolang.com/dl/golang/go1.16.15.linux-arm64.tar.gz
#tar zxvf go1.16.15.linux-arm64.tar.gz
#rm /usr/lib/golang/* -rf
#cp go/* /usr/lib/golang/ -rf
#go version 显示
go version go1.16.15 linux/arm64
下载go基础镜像
docker pull docker.io/golang:1.16.10
查看镜像:
制作镜像
制作镜像是参考官方网站进行修改。
目录结构
参考官方网站,创建目录,目录树如下:
/data/
├── build
│ └── images
└── images
├── fabric
│ ├── baseos
│ ├── ccenv
│ ├── orderer
│ ├── peer
│ └── tools
└── fabric-ca
准备源码
-
fabric源码
从官方网站:https://github.com/hyperledger/fabric拉取源码,版本是 v2.2.0
拉取后存放在/data/fabric
可以参考官方网站的dockerfile进行相应的修改
参考官方网站的/data/fabric/Makefile 文件进行修改进行本次/data/Makefile的编写 -
fabric-ca源码
下载:https://github.com/hyperledger/fabric-ca/archive/refs/tags/v1.5.2.tar.gz
解压安装包放在/data/fabric-ca
参考官方网站的fabric-ca/Makefile 文件进行本次/data/Makefile的编写。
参考官方网站的fabric-ca/images/fabric-ca/Dockerfile进行修改
mv /data/fabric-ca /data/images/fabric-ca/
编写Makefile
vi /data/Makefile
.DEFAULT_GOAL := all
DockerfileArch = Dockerfile
GO_VER ?= 1.14.4
BASE_VERSION = 2.2.0
ALPINE_VER ?= 3.11
# build tag
EXTRA_VERSION ?= $(shell cd src/fabric && git rev-parse --short HEAD) || true
PROJECT_VERSION=$(BASE_VERSION)-snapshot-$(EXTRA_VERSION)
BASE_DOCKER_LABEL=org.hyperledger.fabric
DOCKER_NS = arm64
TWO_DIGIT_VERSION = $(shell echo $(BASE_VERSION) | cut -d '.' -f 1,2)
ARCH=$(shell go env GOARCH)
DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION)
# fabric 1
RELEASE_IMAGES = baseos ccenv orderer peer tools
# fabric 2
RELEASE_EXES = orderer $(TOOLS_EXES)
TOOLS_EXES = configtxgen configtxlator cryptogen discover idemixgen peer
# fabric-ca
RELEASE_FABRIC-CA = fabric-ca
# fabric-ca
RELEASE_FABRIC-CA = fabric-ca-server fabric-ca-client
# build
BUILD_IMAGES_DIR ?= build
BUILD_DIR ?= build/bin/fabric
FABRIC_CA_BUILD_DIR ?= build/bin/fabric-ca
MINIO_BUILD_DIR ?= build/bin/minio
DBUILD = docker build --force-rm $(DOCKER_BUILD_FLAGS)
# defined in common/metadata/metadata.go
PKGFABRIC = github.com/hyperledger/fabric
pkgmapfabric.configtxgen := $(PKGFABRIC)/cmd/configtxgen
pkgmapfabric.configtxlator := $(PKGFABRIC)/cmd/configtxlator
pkgmapfabric.cryptogen := $(PKGFABRIC)/cmd/cryptogen
pkgmapfabric.discover := $(PKGFABRIC)/cmd/discover
pkgmapfabric.idemixgen := $(PKGFABRIC)/cmd/idemixgen
pkgmapfabric.orderer := $(PKGFABRIC)/cmd/orderer
pkgmapfabric.peer := $(PKGFABRIC)/cmd/peer
METADATA_VAR = Version=$(BASE_VERSION)
METADATA_VAR += CommitSHA=$(EXTRA_VERSION)
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
METADATA_VAR += DockerNamespace=$(DOCKER_NS)
# fabric-ca
PKGFABRIC-CA = github.com/hyperledger/fabric-ca
pkgmapfabficca.fabric-ca-client := $(PKGFABRIC-CA)/cmd/fabric-ca-client
pkgmapfabficca.fabric-ca-server := $(PKGFABRIC-CA)/cmd/fabric-ca-server
.PHONY: fabric
fabric: $(RELEASE_EXES)
.PHONY: $(RELEASE_EXES)
$(RELEASE_EXES): %: $(BUILD_DIR)/%
$(BUILD_DIR)/%: GO_LDFLAGS = $(METADATA_VAR:%=-X $(PKGFABRIC)/common/metadata.%)
$(BUILD_DIR)/%:
@echo "Building $(pkgmapfabric.$(@F)) => $@ "
@mkdir -p $(@D)
@cd src/fabric && GOBIN=$(abspath $(@D)) go install -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(pkgmapfabric.$(@F))
@touch $@
.PHONY: fabric-ca
fabric-ca: $(RELEASE_FABRIC-CA)
.PHONY: $(RELEASE_FABRIC-CA)
$(RELEASE_FABRIC-CA): %: $(FABRIC_CA_BUILD_DIR)/%
$(FABRIC_CA_BUILD_DIR)/%: GO_LDFLAGS = $(METADATA_VAR:%=-X $(PKGFABRIC-CA)/common/metadata.%)
$(FABRIC_CA_BUILD_DIR)/%:
@echo "Building $@"
@mkdir -p $(@D)
@cd src/fabric-ca && GOBIN=$(abspath $(@D)) go install -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(pkgmapfabficca.$(@F))
@touch build/images/fabric-ca || true
.PHONY: fabric-docker
fabric-docker: $(RELEASE_IMAGES:%=%-docker)
.PHONY: $(RELEASE_IMAGES:%=%-docker)
$(RELEASE_IMAGES:%=%-docker): %-docker: $(BUILD_IMAGES_DIR)/images/%/$(DUMMY)
$(BUILD_IMAGES_DIR)/images/ccenv/$(DUMMY): BUILD_CONTEXT=images/fabric/ccenv
$(BUILD_IMAGES_DIR)/images/baseos/$(DUMMY): BUILD_CONTEXT=images/fabric/baseos
$(BUILD_IMAGES_DIR)/images/peer/$(DUMMY): BUILD_ARGS=--build-arg GO_TAGS=${GO_TAGS}
$(BUILD_IMAGES_DIR)/images/orderer/$(DUMMY): BUILD_ARGS=--build-arg GO_TAGS=${GO_TAGS}
$(BUILD_IMAGES_DIR)/images/%/$(DUMMY):
@echo "Building Docker image $(DOCKER_NS)/fabric-$*"
@mkdir -p $(@D)
$(DBUILD) -f images/fabric/$*/$(DockerfileArch) \
--build-arg GO_VER=$(GO_VER) \
--build-arg ALPINE_VER=$(ALPINE_VER) \
$(BUILD_ARGS) \
-t $(DOCKER_NS)/fabric-$* ./$(BUILD_CONTEXT)
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(BASE_VERSION)
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(TWO_DIGIT_VERSION)
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(DOCKER_TAG)
@touch $@
.PHONY: fabric-ca-docker
fabric-ca-docker:
@echo "Building Docker image $@F"
$(DBUILD) -f images/fabric-ca/$(DockerfileArch) \
-t $(DOCKER_NS)/fabric-ca images/fabric-ca
docker tag $(DOCKER_NS)/fabric-ca:latest $(DOCKER_NS)/fabric-ca:1.0
@touch build/images/fabric-ca || true
.PHONY: clean-docker
clean-docker:
@echo "Building Docker image nacos"
-@rm -rf build/images/$* || true
.PHONY: all
all: fabric-docker fabric-ca-docker
PROJECT_VERSION=1.0
DOCKER_HUB_USERNAME=
DOCKER_HUB_PASSWORD=
RELEASE_IMAGES = baseos ccenv orderer peer tools fabric-ca
.PHONY: publish-images
publish-images: $(RELEASE_IMAGES:%=%-publish-images)
%-publish-images:
@docker login $(DOCKER_HUB_USERNAME) $(DOCKER_HUB_PASSWORD)
@docker push $(DOCKER_NS)/fabric-$*:$(PROJECT_VERSION)
编写Dockerfile
fabric-ca
参考官方网站:https://github.com/hyperledger/fabric-ca/blob/v1.5.2/images/fabric-ca/Dockerfile
修改Dockerfile:
FROM docker.io/golang:1.16.10 as builder
COPY ./fabric-ca $GOPATH/src/github.com/hyperledger/fabric-ca
WORKDIR $GOPATH/src/github.com/hyperledger
ARG GO_VER
ARG ALPINE_VER
ARG GO_LDFLAGS
ARG GO_TAGS
RUN apt-get update
RUN apt-get install -y gcc binutils-gold musl-dev
RUN cd $GOPATH/src/github.com/hyperledger/fabric-ca \
&& go install -tags "${GO_TAGS}" -ldflags "${GO_LDFLAGS}" \
github.com/hyperledger/fabric-ca/cmd/fabric-ca-server \
&& go install -tags "${GO_TAGS}" -ldflags "${GO_LDFLAGS}" \
github.com/hyperledger/fabric-ca/cmd/fabric-ca-client
FROM docker.io/golang:1.16.10
RUN apt-get install -y tzdata
ENV FABRIC_CA_HOME /etc/hyperledger/fabric-ca-server
COPY --from=builder /go/bin /usr/local/bin
EXPOSE 7054
CMD fabric-ca-server start -b admin:adminpw
fabric-baseos
vi /data/images/fabric/baseos/Dockerfile
#官方网站该处用了apline
FROM docker.io/golang:1.16.10 as base
RUN apt-get install -y tzdata \
&& addgroup --gid 500 chaincode && adduser --disabled-password --uid 500 --home /home/chaincode --ingroup chaincode chaincode;
USER chaincode
fabric-ccenv
vi /data/images/fabric/ccenv/Dockerfile
FROM docker.io/golang:1.16.10 as base
ENV GOPATH="/go"
RUN apt-get update
#RUN apt-get install -y g++ gcc git musl-dev go
RUN apt-get install -y g++ gcc musl-dev
RUN mkdir -p /chaincode/output /chaincode/input \
&& addgroup --gid 500 chaincode && adduser --disabled-password --uid 500 --home /home/chaincode --ingroup chaincode chaincode \
&& chown -R chaincode:chaincode /chaincode;
USER chaincode
fabric-orderer
vi /data/images/fabric/orderer/Dockerfile
FROM docker.io/golang:1.16.10 as base
RUN apt-get install -y tzdata
# set up nsswitch.conf for Go's "netgo" implementation
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
FROM docker.io/golang:1.16.10 as golang
COPY ./fabric $GOPATH/src/github.com/hyperledger/fabric
WORKDIR $GOPATH/src/github.com/hyperledger/fabric
RUN apt-get update
RUN apt-get install -y gcc musl-dev bash make
FROM golang as orderer
ARG GO_TAGS
RUN make orderer GO_TAGS=${GO_TAGS}
FROM base
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
VOLUME /etc/hyperledger/fabric
VOLUME /var/hyperledger
COPY --from=orderer /go/src/github.com/hyperledger/fabric/build/bin /usr/local/bin
COPY --from=orderer /go/src/github.com/hyperledger/fabric/sampleconfig/msp ${FABRIC_CFG_PATH}/msp
COPY --from=orderer /go/src/github.com/hyperledger/fabric/sampleconfig/orderer.yaml ${FABRIC_CFG_PATH}
COPY --from=orderer /go/src/github.com/hyperledger/fabric/sampleconfig/configtx.yaml ${FABRIC_CFG_PATH}
EXPOSE 7050
CMD ["orderer"]
fabric-peer
vi /data/images/fabric/peer/Dockerfile
FROM docker.io/golang:1.16.10 as peer-base
RUN apt-get install -y tzdata \
&& echo 'hosts: files dns' > /etc/nsswitch.conf;
# set up nsswitch.conf for Go's "netgo" implementation
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
FROM docker.io/golang:1.16.10 as golang
COPY ./fabric $GOPATH/src/github.com/hyperledger/fabric
WORKDIR $GOPATH/src/github.com/hyperledger/fabric
RUN apt-get update
RUN apt-get install -y bash gcc make musl-dev
RUN sed -i 's/rdev: s.Rdev/rdev: uint64(s.Rdev)/g' vendor/github.com/docker/docker/pkg/system/stat_linux.go
FROM golang as peer
ARG GO_TAGS
RUN make peer GO_TAGS=${GO_TAGS}
FROM peer-base
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
VOLUME /etc/hyperledger/fabric
VOLUME /var/hyperledger
COPY --from=peer /go/src/github.com/hyperledger/fabric/build/bin /usr/local/bin
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/msp ${FABRIC_CFG_PATH}/msp
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/core.yaml ${FABRIC_CFG_PATH}
EXPOSE 7051
CMD ["peer","node","start"]
fabric-tools
vi /data/images/fabric/tools/Dockerfile
FROM docker.io/golang:1.16.10 as golang
COPY ./fabric $GOPATH/src/github.com/hyperledger/fabric
WORKDIR $GOPATH/src/github.com/hyperledger/fabric
RUN apt-get update
RUN apt-get install -y \
bash \
gcc \
make \
musl-dev \
&& sed -i 's/rdev: s.Rdev/rdev: uint64(s.Rdev)/g' vendor/github.com/docker/docker/pkg/system/stat_linux.go;
FROM golang as tools
RUN make configtxgen configtxlator cryptogen peer discover idemixgen
FROM docker.io/golang:1.16.10
# git is required to support `go list -m`
RUN apt-get update
RUN apt-get install -y \
bash \
git \
jq \
tzdata;
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
VOLUME /etc/hyperledger/fabric
COPY --from=tools /go/src/github.com/hyperledger/fabric/build/bin /usr/local/bin
COPY --from=tools /go/src/github.com/hyperledger/fabric/sampleconfig ${FABRIC_CFG_PATH}
验证镜像
打镜像
cd /data
make all
验证
docker run -it --name peer1 arm64/fabric-peer:2.2.0 peer version
如图:
遇到的问题和解决办法
参考官方网站,orderer、peer、fabric-ca 的Dockerfile中使用了两个基础镜像:apline 和 golang
下载基础镜像
docker pull docker.io/golang:1.16.10
docker pull docker.io/apline:3.11
参考官方网站的dockerfile,比如peer的:
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
FROM docker.io/alpine:3.11 as peer-base
#FROM docker.io/golang:1.16.10 as peer-base
RUN apt-get install -y tzdata \
&& echo 'hosts: files dns' > /etc/nsswitch.conf;
# set up nsswitch.conf for Go's "netgo" implementation
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
FROM docker.io/golang:1.16.10 as golang
COPY ./fabric $GOPATH/src/github.com/hyperledger/fabric
WORKDIR $GOPATH/src/github.com/hyperledger/fabric
RUN apt-get update
RUN apt-get install -y bash gcc make musl-dev
RUN sed -i 's/rdev: s.Rdev/rdev: uint64(s.Rdev)/g' vendor/github.com/docker/docker/pkg/system/stat_linux.go
FROM golang as peer
ARG GO_TAGS
RUN make peer GO_TAGS=${GO_TAGS}
FROM peer-base
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
VOLUME /etc/hyperledger/fabric
VOLUME /var/hyperledger
COPY --from=peer /go/src/github.com/hyperledger/fabric/build/bin /usr/local/bin
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/msp ${FABRIC_CFG_PATH}/msp
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/core.yaml ${FABRIC_CFG_PATH}
EXPOSE 7051
CMD ["peer","node","start"]
打包出来的peer、orderer、fabric-ca 镜像会出现下面问题。
问题描述:orderer命令编译后在/usr/local/bin/orderer,但是在容器中不能使用。
报错提示:/bin/sh xxx :not found
docker run -it --name orderer arm64/fabric-orderer /bin/sh
原因:两个基础镜像底层shell环境不一致导致
解决方案:全都使用go基础镜像。上述文档中的Dockerfile都是改为使用go作为单一基础镜像制作的fabric镜像。
启动第一个网络:
待补充
go get 报错:
创建测试网络:
服务器资源不够。带不动: