下载操作系统镜像,本文选择openEuler尝鲜
1.ubuntu下载地址 https://ubuntu.com/download/server 2.openEuler下载地址 https://www.openeuler.org/zh/download/二.虚拟机环境搭建
三.fabric用户规划虚拟机环境搭建参考
添加fabric用户
## 1.添加用户fabric [root@localhost ~]# useradd fabric ## 修改密码 [root@localhost ~]# passwd fabric 更改用户 fabric 的密码 。 新的密码: 重新输入新的密码: passwd:所有的身份验证令牌已经成功更新。 ## wumima-1 ## 设置sudo权限 [root@localhost ~]# visudo ## 在root下添加一行如下,保存退出 ## Allow root to run any commands anywhere root ALL=(ALL) ALL fabric ALL=(ALL) ALL ## fabric用户添加到docker组 [fabric@localhost opt]$ sudo usermod -a -G docker fabric ## 系统语言中文改成英文(若需要) [fabric@localhost fabric-samples]$ sudo localectl set-locale LANG=en_US.UTF8 或者 [fabric@localhost fabric-samples]$ sudo vi /etc/locale.conf 重启系统四.工具安装
将系统先安装ifconfig,后面使用远程工具连接
1.安装ifconfigyum search ifconfig
没找到则安装
yum -y install net-tools.x86_642.hyperledger fabric环境准备
参考资料: https://hyperledger-fabric.readthedocs.io/en/latest/prereqs.html#linux
##备份yum.repos.d
[fabric@localhost opt]$ sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.backup
[fabric@localhost opt]$ sudo yum -y update
## 这里已经安装了device-mapper-persistent-data lvm2
## yum-config-manager,device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2
#[fabric@localhost opt]$ sudo yum install -y yum-utils
# device-mapper-persistent-data
# lvm2
## 1.安装git
[root@localhost ~]$ su - fabric
[fabric@localhost ~]$ cd /opt
[fabric@localhost opt]$ sudo yum -y install git
[fabric@localhost opt]$ git --version
git version 2.33.0
## 2.安装curl(系统自带无需安装)
## 3.docker设置
## 设置稳定的docker仓库---跳过
#[fabric@localhost opt]$ sudo yum-config-manager
# --add-repo
# https://download.docker.com/linux/centos/docker-ce.repo
## 可查看---跳过
#[fabric@localhost opt]$ more /etc/yum.repos.d/docker-ce.repo
## docker 镜像加速
[fabric@localhost opt]$ sudo mkdir -p /etc/docker
[fabric@localhost opt]$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://hub-mirror.c.163.com/",
"https://reg-mirror.qiniu.com/",
"https://docker.mirrors.ustc.edu.cn/",
"https://registry.docker-cn.com/"
]
}
EOF
# 科大镜像:https://docker.mirrors.ustc.edu.cn/
# 网易:https://hub-mirror.c.163.com/
# 阿里云:https://<你的ID>.mirror.aliyuncs.com/
# 七牛云加速器:https://reg-mirror.qiniu.com/
# 检查镜像加速是否生效
[fabric@localhost opt]$ docker info
# 重启
[fabric@localhost opt]$ sudo systemctl daemon-reload
[fabric@localhost opt]$ sudo systemctl restart docker
[fabric@localhost opt]$ docker ps
# 安装docker
[fabric@localhost opt]$ yum -y install docker
[fabric@localhost opt]$ docker --version
Docker version 18.09.0, build aa1eee8
## 运行 hello-world
[fabric@localhost configtx]$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
## 4.安装docker-compose
[fabric@localhost opt]$ sudo yum -y install docker-compose
[fabric@localhost opt]$ docker-compose --version
docker-compose version 1.22.0, build f46880f
## 5.安装golang
[fabric@localhost opt]$ sudo yum -y install golang
[fabric@localhost opt]$ go version
go version go1.17.3 linux/amd64
## 6.安装jq
[fabric@localhost ~]$ sudo yum -y install jq
[fabric@localhost opt]$ jq --version
jq-1.6
## 7.安装libtoo
[fabric@localhost opt]$ sudo yum -y install libtool
[fabric@localhost opt]$ libtool --version
libtool (GNU libtool) 2.4.6
## 安装SoftHSM (TODO)
3.启动docker
启动docker,设置开启自启动
## 启动docker [fabric@localhost opt]$ sudo systemctl start docker [fabric@localhost opt]$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE ## docker开机启动 [fabric@localhost opt]$ sudo systemctl enable docker4.go环境变量配置
go的环境变量配置与验证
## 1. 设置go环境变量 [fabric@localhost opt]$ mkdir $HOME/go [fabric@localhost opt]$ mkdir -p $GOPATH/src/github.com/hyperledger ## 由于是yum安装,找到GOROOT,GOPATH [fabric@localhost opt]$ go env ## vi ~./bashrc [fabric@localhost opt] vi ~/.bashrc ## 在最下方插入 export GOROOT=/usr/lib/golang export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin:$GOPATH/bin ## 保存退出,生效环境变量 [fabric@localhost opt] source ~/.bashrc ## 环境变量查看 [fabric@localhost opt]$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/fabric/.cache/go-build" GOENV="/home/fabric/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/fabric/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/fabric/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/lib/golang" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.17.3" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2265102898=/tmp/go-build -gno-record-gcc-switches"5.设置go代理
设置代理,方便后续自动下载必要的文件
[fabric@localhost hyperledger]$ go env -w GO111MODULE=on [fabric@localhost hyperledger]$ go env -w GOPROXY=https://goproxy.cn,direct [fabric@localhost hyperledger]$ go env GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/home/fabric/.cache/go-build" GOENV="/home/fabric/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/fabric/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/fabric/go" GOPRIVATE="" GOPROXY="https://goproxy.cn,direct" GOROOT="/usr/lib/golang" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.17.3" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1767538281=/tmp/go-build -gno-record-gcc-switches" [fabric@localhost hyperledger]$6.拉取Hyperledger Fabric相关项目镜像
安装示例、二进制和 Docker镜像地址 https://hyperledger-fabric.readthedocs.io/zh_CN/latest/test_network.html
1.拉取 hyperledger/fabric-samples 仓库
2.检出适当的版本标签
3.将指定版本的 Hyperledger Fabric 平台特定二进制文件和配置文件安装到 fabric-samples 下的 /bin 和 /config 目录中
4.下载指定版本的 Hyperledger Fabric docker 镜像
本文使用的是Hyperledger Fabric 2.3.3相关版本
## 进入目录 [fabric@localhost opt]$ cd $GOPATH/src/github.com/hyperledger ## 1.拉取fabric镜像 [fabric@localhost hyperledger]$ git clone https://github.com/hyperledger/fabric.git [fabric@localhost fabric]$ cd fabric ## 查看远程分支 [fabric@localhost fabric]$ git branch -a [fabric@localhost fabric]$ git tag ## 切换分支git checkout tag_name 取得对应tag的代码 ## git checkout -b local_branch_name origin_branch_name ## 切换分支到2.3.3 [fabric@localhost fabric]$ git checkout v2.3.3 ## 2.拉取fabric-samples [fabric@localhost hyperledger]$ git clone https://github.com/hyperledger/fabric-samples.git [fabric@localhost hyperledger]$ cd fabric-samples [fabric@localhost fabric-samples]$ git checkout v2.3.0 ## 3.拉取fabric-ca [fabric@localhost hyperledger]$ git clone https://github.com/hyperledger/fabric-ca.git [fabric@localhost fabric-ca]$ git tag [fabric@localhost fabric-ca]$ git checkout v1.5.2 ## 4.下载fabric二进制文件 [fabric@localhost hyperledger] wget https://github.com/hyperledger/fabric/releases/download/v2.3.3/hyperledger-fabric-linux-amd64-2.3.3.tar.gz [fabric@localhost hyperledger]$ tar -xvf hyperledger-fabric-linux-amd64-2.3.3.tar.gz -C ./fabric-bin2.3/ ## 5.下载fabric-ca二进制文件 [fabric@localhost hyperledger]$ wget https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz [fabric@localhost hyperledger]$ tar -xvf hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz ## 6.将解压的文件复制到fabric-samples目录下 [fabric@localhost hyperledger]$ cp -r bin config ./fabric-samples/ ## 7.设置环境变量 [fabric@localhost hyperledger]$ vi ~/.bashrc ## 添加如下,保存退出 export PATH=$PATH:$GOPATH/src/github.com/hyperledger/fabric-samples/bin ## 生效 [fabric@localhost hyperledger]$ source ~/.bashrc ## 8.验证ca是否配置正确 [fabric@localhost hyperledger]$ fabric-ca-client version fabric-ca-client: Version: 1.5.2 Go version: go1.16.7 OS/Arch: linux/amd64 ## 9.拉取镜像,修改脚本 [fabric@localhost hyperledger]$ cd fabric/scripts/ [fabric@localhost scripts]$ vi bootstrap.sh ## true修改为false SAMPLES=false BINARIES=false #################### 下载镜像 ############### [fabric@localhost scripts]$ ./bootstrap.sh Pull Hyperledger Fabric docker images FABRIC_IMAGES: peer orderer ccenv tools baseos ===> Pulling fabric Images ====> hyperledger/fabric-peer:2.3.3 2.3.3: Pulling from hyperledger/fabric-peer a0d0a0d46f8b: Pull complete 48d00a7269f1: Pull complete cdc14355e7d6: Pull complete 56037e787534: Pull complete efac144e8b4c: Pull complete 4655b4117f02: Pull complete Digest: sha256:fc9a143aaf528e407817baf658aff3b258f632464ad32bcfd0d17054b352b782 Status: Downloaded newer image for hyperledger/fabric-peer:2.3.3 ====> hyperledger/fabric-orderer:2.3.3 2.3.3: Pulling from hyperledger/fabric-orderer a0d0a0d46f8b: Already exists 48d00a7269f1: Already exists d58aaefbb8a4: Pull complete 4d79536ff546: Pull complete 0cd49346219e: Pull complete e35c5a649c2f: Pull complete 12144512ae9a: Pull complete Digest: sha256:e5192e8619b9b0abd03ec6ce8babe65493d7db7e71faee3c1c8714bddf19b507 Status: Downloaded newer image for hyperledger/fabric-orderer:2.3.3 ====> hyperledger/fabric-ccenv:2.3.3 2.3.3: Pulling from hyperledger/fabric-ccenv a0d0a0d46f8b: Already exists 31adcdaf11c8: Pull complete b8b176561691: Pull complete ffa5077b735b: Pull complete 2e51fde7a4ad: Pull complete 5cc8e298dd15: Pull complete 2321141fd763: Pull complete fd5823e35fde: Pull complete 71974160e457: Pull complete Digest: sha256:e95a727aed88456b496a4e4b1ddbc77e81c26a0cc7ff234c7d3d085dafd637cd Status: Downloaded newer image for hyperledger/fabric-ccenv:2.3.3 ====> hyperledger/fabric-tools:2.3.3 2.3.3: Pulling from hyperledger/fabric-tools a0d0a0d46f8b: Already exists 31adcdaf11c8: Already exists b8b176561691: Already exists ffa5077b735b: Already exists 2e51fde7a4ad: Already exists fa96723f2624: Pull complete d34ad363c0cf: Pull complete ab37c24ec85b: Pull complete Digest: sha256:634c66833a264939b9920cfa0a47b028c20b39475d0bc7ca02841137ea2c4e86 Status: Downloaded newer image for hyperledger/fabric-tools:2.3.3 ====> hyperledger/fabric-baseos:2.3.3 2.3.3: Pulling from hyperledger/fabric-baseos a0d0a0d46f8b: Already exists 48d00a7269f1: Already exists 7fe902e02eda: Pull complete error pulling image configuration: Get "https://registry-1.docker.io/v2/hyperledger/fabric-baseos/blobs/sha256:b35a8ef578c0a59b029ee3fd16b2c8606de87bbf0a9167cbae97c417e32e94e4": read tcp 192.168.0.103:46602->50.17.53.181:443: read: connection timed out Error response from daemon: No such image: hyperledger/fabric-baseos:2.3.3 Error response from daemon: No such image: hyperledger/fabric-baseos:2.3.3 ===> Pulling fabric ca Image ====> hyperledger/fabric-ca:1.5.2 Error response from daemon: Get "https://registry-1.docker.io/v2/hyperledger/fabric-ca/manifests/1.5.2": Get "https://auth.docker.io/token?scope=repository%3Ahyperledger%2Ffabric-ca%3Apull&service=registry.docker.io": context deadline exceeded Error response from daemon: No such image: hyperledger/fabric-ca:1.5.2 Error response from daemon: No such image: hyperledger/fabric-ca:1.5.2 ===> List out hyperledger docker images hyperledger/fabric-tools 2.3 98fa0bfb0fd2 7 months ago 445MB hyperledger/fabric-tools 2.3.3 98fa0bfb0fd2 7 months ago 445MB hyperledger/fabric-tools latest 98fa0bfb0fd2 7 months ago 445MB hyperledger/fabric-peer 2.3 a491b5ab42f6 7 months ago 53.3MB hyperledger/fabric-peer 2.3.3 a491b5ab42f6 7 months ago 53.3MB hyperledger/fabric-peer latest a491b5ab42f6 7 months ago 53.3MB hyperledger/fabric-orderer 2.3 9e1952b8840d 7 months ago 35.4MB hyperledger/fabric-orderer 2.3.3 9e1952b8840d 7 months ago 35.4MB hyperledger/fabric-orderer latest 9e1952b8840d 7 months ago 35.4MB hyperledger/fabric-ccenv 2.3 56fa403e02ee 7 months ago 502MB hyperledger/fabric-ccenv 2.3.3 56fa403e02ee 7 months ago 502MB hyperledger/fabric-ccenv latest 56fa403e02ee 7 months ago 502MB ######################## 报错,重新执行 ###################### [fabric@localhost scripts]$ ./bootstrap.sh Pull Hyperledger Fabric docker images FABRIC_IMAGES: peer orderer ccenv tools baseos ===> Pulling fabric Images ====> hyperledger/fabric-peer:2.3.3 2.3.3: Pulling from hyperledger/fabric-peer Digest: sha256:fc9a143aaf528e407817baf658aff3b258f632464ad32bcfd0d17054b352b782 Status: Image is up to date for hyperledger/fabric-peer:2.3.3 ====> hyperledger/fabric-orderer:2.3.3 2.3.3: Pulling from hyperledger/fabric-orderer Digest: sha256:e5192e8619b9b0abd03ec6ce8babe65493d7db7e71faee3c1c8714bddf19b507 Status: Image is up to date for hyperledger/fabric-orderer:2.3.3 ====> hyperledger/fabric-ccenv:2.3.3 2.3.3: Pulling from hyperledger/fabric-ccenv Digest: sha256:e95a727aed88456b496a4e4b1ddbc77e81c26a0cc7ff234c7d3d085dafd637cd Status: Image is up to date for hyperledger/fabric-ccenv:2.3.3 ====> hyperledger/fabric-tools:2.3.3 2.3.3: Pulling from hyperledger/fabric-tools Digest: sha256:634c66833a264939b9920cfa0a47b028c20b39475d0bc7ca02841137ea2c4e86 Status: Image is up to date for hyperledger/fabric-tools:2.3.3 ====> hyperledger/fabric-baseos:2.3.3 2.3.3: Pulling from hyperledger/fabric-baseos a0d0a0d46f8b: Already exists 48d00a7269f1: Already exists 7fe902e02eda: Already exists Digest: sha256:3af16c343deaa5b837e2581b6b72523643e8572fd2981ed6bfea4a9fbf43bd20 Status: Downloaded newer image for hyperledger/fabric-baseos:2.3.3 ===> Pulling fabric ca Image ====> hyperledger/fabric-ca:1.5.2 1.5.2: Pulling from hyperledger/fabric-ca a0d0a0d46f8b: Already exists ac8258c0aeb1: Pull complete 6c802cf1fa97: Pull complete Digest: sha256:faa3b743d9ed391c30f518a7cc1168160bf335f3bf60ba6aaaf1aa49c1ed023e Status: Downloaded newer image for hyperledger/fabric-ca:1.5.2 ===> List out hyperledger docker images hyperledger/fabric-ca 1.5 4ea287b75c63 7 months ago 69.8MB hyperledger/fabric-ca 1.5.2 4ea287b75c63 7 months ago 69.8MB hyperledger/fabric-ca latest 4ea287b75c63 7 months ago 69.8MB hyperledger/fabric-tools 2.3 98fa0bfb0fd2 7 months ago 445MB hyperledger/fabric-tools 2.3.3 98fa0bfb0fd2 7 months ago 445MB hyperledger/fabric-tools latest 98fa0bfb0fd2 7 months ago 445MB hyperledger/fabric-peer 2.3 a491b5ab42f6 7 months ago 53.3MB hyperledger/fabric-peer 2.3.3 a491b5ab42f6 7 months ago 53.3MB hyperledger/fabric-peer latest a491b5ab42f6 7 months ago 53.3MB hyperledger/fabric-orderer 2.3 9e1952b8840d 7 months ago 35.4MB hyperledger/fabric-orderer 2.3.3 9e1952b8840d 7 months ago 35.4MB hyperledger/fabric-orderer latest 9e1952b8840d 7 months ago 35.4MB hyperledger/fabric-ccenv 2.3 56fa403e02ee 7 months ago 502MB hyperledger/fabric-ccenv 2.3.3 56fa403e02ee 7 months ago 502MB hyperledger/fabric-ccenv latest 56fa403e02ee 7 months ago 502MB hyperledger/fabric-baseos 2.3 b35a8ef578c0 7 months ago 6.87MB hyperledger/fabric-baseos 2.3.3 b35a8ef578c0 7 months ago 6.87MB hyperledger/fabric-baseos latest b35a8ef578c0 7 months ago 6.87MB [fabric@localhost scripts]$7.说明:二进制文件下载地址及版本
1.fabric二进制文件地址
https://github.com/hyperledger/fabric/releases
打开地址后,切换Tags找对应的版本,下载hyperledger-fabric-linux-amd64-2.3.3.tar.gz
2.fabric-ca二进制文件地址
https://github.com/hyperledger/fabric-ca/tags
打开地址后,切换Tags找对应的版本,下载hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz
## 进入fabric-samples的test-network目录 [fabric@localhost hyperledger]$ cd fabric-samples/test-network/ ## 启动 [fabric@localhost test-network]$ ./network.sh up Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen' LOCAL_VERSION=2.3.3 DOCKER_IMAGE_VERSION=2.3.3 /home/fabric/go/src/github.com/hyperledger/fabric-samples/bin/cryptogen Generating certificates using cryptogen tool Creating Org1 Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations org1.example.com + res=0 Creating Org2 Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations org2.example.com + res=0 Creating Orderer Org Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations + res=0 Generating CCP files for Org1 and Org2 Creating network "net_test" with the default driver Creating volume "net_orderer.example.com" with default driver Creating volume "net_peer0.org1.example.com" with default driver Creating volume "net_peer0.org2.example.com" with default driver Creating peer0.org2.example.com ... done Creating orderer.example.com ... done Creating peer0.org1.example.com ... done Creating cli ... done CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 33e9464f63e2 hyperledger/fabric-tools:latest "/bin/bash" 1 second ago Up Less than a second cli e7325d57f7b5 hyperledger/fabric-peer:latest "peer node start" 5 seconds ago Up 1 second 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com da7e82926c88 hyperledger/fabric-peer:latest "peer node start" 5 seconds ago Up 1 second 0.0.0.0:7051->7051/tcp peer0.org1.example.com 361537c6d991 hyperledger/fabric-orderer:latest "orderer" 5 seconds ago Up 2 seconds 0.0.0.0:7050->7050/tcp, 0.0.0.0:7053->7053/tcp orderer.example.com ## 查看运行的容器 [fabric@localhost test-network]$ docker ps -a ## 停止 [fabric@localhost test-network]$ ./network.sh down六.补充
go代理设置(如需要)
## 方式1 go env -w GOPROXY=https://goproxy.cn export GOPROXY=https://goproxy.cn ## 方式2 go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.cn,direct



