本人使用的是本地虚拟机,centos7,镜像版本是mini版的(个人觉得系统自带的东西越少,个人操作的地方就越多,踩的坑也多,对后续解决问题有很大帮助)
安装docker1、使用root权限,更新yum(需要更新几百个依赖,比较慢,可以一边拉屎一边更新)
yum -y update
2、安装需要的软件包
yum install -y yum-utils device-mapper-persistent-data lvm2
3、设置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
4、安装(我安装的是17版本)
yum install -y docker-ce-17.12.0.ce
5、启动并加入开机自启
systemctl start docker systemctl enable docker
6、验证是否安装成功
[root@localhost ~]# docker version Client: Version: 17.12.0-ce API version: 1.35 Go version: go1.9.2 Git commit: c97c6d6 Built: Wed Dec 27 20:10:14 2017 OS/Arch: linux/amd64 Server: Engine: Version: 17.12.0-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.2 Git commit: c97c6d6 Built: Wed Dec 27 20:12:46 2017 OS/Arch: linux/amd64 Experimental: false安装GO环境
1、安装一些必要的依赖
yum -y install libtool libltdl-dev
2、下载go语言包,官网地址Go下载 - Go语言中文网 - Golang中文社区,我使用的是这个go1.16.7.linux-amd64.tar.gz版本,将下载下来的文件解压到/usr/local目录下
tar -zxvf go1.16.7.linux-amd64.tar.gz -C /usr/local/
3、 创建GO工作目录
mkdir /opt/gopath
4、编辑配置文件/etc/profile,然后添加如下内容
export PATH=$PATH:/usr/local/go/bin #是系统上安装GO软件包的位置
export GOPATH=/opt/gopath # 是工作目录的位置
5、保存,然后生效
source /etc/profile
6、检测是否安装成功(版本号可以正常显示)
[root@localhost soft]# go version go version go1.16.7 linux/amd64 [root@localhost soft]#docker-compose安装
1、下载安装包,可以从下面网站上找,下载特别慢,当前fabric版本要使用2.2版本以上的docker-compose,我使用的是2.2.3
https://github.com/docker/compose/releases/download
2、将下载下来的文件放机器上
[root@localhost soft]# ll total 150140 -rw-r--r--. 1 root root 24707072 Jan 18 01:19 docker-compose-linux-x86_64 -rw-r--r--. 1 root root 129034961 Jan 12 03:26 go1.16.7.linux-amd64.tar.gz [root@localhost soft]#
3、重命名成docker-compose到/usr/local/bin 下面即可
[root@localhost soft]# mv docker-compose-linux-x86_64 /usr/local/bin/ [root@localhost soft]# mv /usr/local/bin/docker-compose-linux-x86_64 /usr/local/bin/docker-compose
4、添加权限,并验证
chmod 755 /usr/local/bin/docker-compose [root@localhost soft]# docker-compose version Docker Compose version v2.2.3git安装
yum -y install gitfabric环境搭建
下载源码比较慢,我都是本地下载好了上传到虚拟机上的
1、创建fabric工作目录
mkdir -p /home/docker/github.com/hyperledger
2、准备好了源码,源码示例包,二进制文件
[root@localhost soft]# ll total 245524 -rw-r--r--. 1 root root 29061029 Jan 14 00:54 fabric-2.2.4.zip -rw-r--r--. 1 root root 1561391 Jan 14 00:54 fabric-samples-2.2.3.zip -rw-r--r--. 1 root root 26723281 Jan 12 03:53 hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz -rw-r--r--. 1 root root 65027561 Jan 12 04:50 hyperledger-fabric-linux-amd64-2.2.4.tar.gz
3、将源码解压到工作目录下,并将示例包解压到源码目录下的scripts下
unzip -d /home/docker/github.com/hyperledger/ fabric-2.2.4.zip unzip -d /home/docker/github.com/hyperledger/fabric-2.2.4/scripts/ fabric-samples-2.2.3.zip
4、将二进制文件解压到示例代码目录下
[root@localhost soft]# tar -zxvf hyperledger-fabric-linux-amd64-2.2.4.tar.gz -C /home/docker/github.com/hyperledger/fabric-2.2.4/scripts/fabric-samples-2.2.3/ bin/ bin/discover bin/peer bin/orderer bin/idemixgen bin/configtxlator bin/cryptogen bin/configtxgen config/ config/core.yaml config/orderer.yaml config/configtx.yaml [root@localhost soft]# tar -zxvf hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz -C /home/docker/github.com/hyperledger/fabric-2.2.4/scripts/fabric-samples-2.2.3/ bin/ bin/fabric-ca-server bin/fabric-ca-client [root@localhost soft]#
会看到/home/docker/github.com/hyperledger/fabric-2.2.4/scripts/fabric-samples-2.2.3目录下多了bin和config俩目录
5、将二进制文件添加到环境变量中
[root@localhost ~]# vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH=$PATH:/home/docker/github.com/hyperledger/fabric-2.2.4/scripts/fabric-samples-2.2.3/bin
export PATH=$PATH:/home/docker/github.com/hyperledger/fabric-2.2.4/scripts/fabric-samples-2.2.3/config
export PATH
保存后生效文件
[root@localhost ~]# source .bash_profile
6、下载镜像
在/home/docker/github.com/hyperledger/fabric-2.2.4/scripts目录下执行./bootstrap.sh -sb (-sb表示跳过下载示例文件和二进制文件)
[root@localhost scripts]# ./bootstrap.sh -sb Pull Hyperledger Fabric docker images FABRIC_IMAGES: peer orderer ccenv tools nodeenv baseos javaenv ===> Pulling fabric Images ====> hyperledger/fabric-peer:2.2.4 2.2.4: Pulling from hyperledger/fabric-peer a0d0a0d46f8b: Pull complete 39f5dde72e6c: Pull complete c60458617bd9: Pull complete f03acaa6cd97: Pull complete 83c51587c9f2: Pull complete ae7d6a041376: Pull complete Digest: sha256:340025eb11f6537d71efd2820f2a643eb6f48708b0954b0f1592c87e8ce868d2 Status: Downloaded newer image for hyperledger/fabric-peer:2.2.4 ====> hyperledger/fabric-orderer:2.2.4 2.2.4: Pulling from hyperledger/fabric-orderer a0d0a0d46f8b: Already exists 39f5dde72e6c: Already exists 2fd7f2d0154d: Pull complete f6fd9cda1337: Pull complete 7d80072c1a36: Pull complete 8bb955f8010f: Pull complete f743c8ee18d0: Pull complete Digest: sha256:12331afb762b431b520aec8b3e1fd7b83d5a1b3700deddb86e93a44c3fc2a9d7 Status: Downloaded newer image for hyperledger/fabric-orderer:2.2.4 ====> hyperledger/fabric-ccenv:2.2.4 2.2.4: Pulling from hyperledger/fabric-ccenv a0d0a0d46f8b: Already exists 31adcdaf11c8: Pull complete b8b176561691: Pull complete ffa5077b735b: Pull complete 2e51fde7a4ad: Pull complete 88ec7036a0f0: Pull complete 300acd46ee50: Pull complete 921211ec1e72: Pull complete 665fbc77bd34: Pull complete Digest: sha256:4ec70e9e41084635db80cc38357dfd6dcaa6fe7b40d84f16ab6366439358bab4 Status: Downloaded newer image for hyperledger/fabric-ccenv:2.2.4 ====> hyperledger/fabric-tools:2.2.4 2.2.4: Pulling from hyperledger/fabric-tools a0d0a0d46f8b: Already exists 31adcdaf11c8: Already exists b8b176561691: Already exists ffa5077b735b: Already exists 2e51fde7a4ad: Already exists ca55bf76b621: Pull complete fcc465d926d3: Pull complete 025eefba8376: Pull complete Digest: sha256:a5f691808466e90942af3f5f72d697cdaa4e545acfc1f645a553986423ef7ea5 Status: Downloaded newer image for hyperledger/fabric-tools:2.2.4 ====> hyperledger/fabric-nodeenv:2.2.4 Error response from daemon: manifest for hyperledger/fabric-nodeenv:2.2.4 not found Error response from daemon: No such image: hyperledger/fabric-nodeenv:2.2.4 Error response from daemon: No such image: hyperledger/fabric-nodeenv:2.2.4 ====> hyperledger/fabric-baseos:2.2.4 2.2.4: Pulling from hyperledger/fabric-baseos a0d0a0d46f8b: Already exists 39f5dde72e6c: Already exists bdbe3e81e212: Pull complete Digest: sha256:d668bbd0f544eba72e98202236c2ed91b4001f4876be6d90f25e4f6b9b4e421c Status: Downloaded newer image for hyperledger/fabric-baseos:2.2.4 ====> hyperledger/fabric-javaenv:2.2.4 Error response from daemon: manifest for hyperledger/fabric-javaenv:2.2.4 not found Error response from daemon: No such image: hyperledger/fabric-javaenv:2.2.4 Error response from daemon: No such image: hyperledger/fabric-javaenv:2.2.4 ===> 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 4 months ago 69.8MB hyperledger/fabric-ca 1.5.2 4ea287b75c63 4 months ago 69.8MB hyperledger/fabric-ca latest 4ea287b75c63 4 months ago 69.8MB hyperledger/fabric-tools 2.2 d32b30082179 4 months ago 429MB hyperledger/fabric-tools 2.2.4 d32b30082179 4 months ago 429MB hyperledger/fabric-tools latest d32b30082179 4 months ago 429MB hyperledger/fabric-peer 2.2 4a3aed7a742c 4 months ago 51.8MB hyperledger/fabric-peer 2.2.4 4a3aed7a742c 4 months ago 51.8MB hyperledger/fabric-peer latest 4a3aed7a742c 4 months ago 51.8MB hyperledger/fabric-orderer 2.2 abf523e91319 4 months ago 35.2MB hyperledger/fabric-orderer 2.2.4 abf523e91319 4 months ago 35.2MB hyperledger/fabric-orderer latest abf523e91319 4 months ago 35.2MB hyperledger/fabric-ccenv 2.2 96b8a8b006b4 4 months ago 502MB hyperledger/fabric-ccenv 2.2.4 96b8a8b006b4 4 months ago 502MB hyperledger/fabric-ccenv latest 96b8a8b006b4 4 months ago 502MB hyperledger/fabric-baseos 2.2 fb6d7b238996 4 months ago 6.87MB hyperledger/fabric-baseos 2.2.4 fb6d7b238996 4 months ago 6.87MB hyperledger/fabric-baseos latest fb6d7b238996 4 months ago 6.87MB
待显示所有的镜像后,下载完毕(如果网络不好可以自行下载,自行下载的话注意版本号一定要对应上,docker官网,https://hub.docker.com/)
7、用例测试
切换到fabric-samples-2.2.3/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.2.4 DOCKER_IMAGE_VERSION=2.2.4 /home/docker/github.com/hyperledger/fabric-2.2.4/scripts/fabric-samples-2.2.3/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 /home/docker/github.com/hyperledger/fabric-2.2.4/scripts/fabric-samples-2.2.3/bin/configtxgen Generating Orderer Genesis block + configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block 2022-01-18 01:48:13.978 EST [common.tools.configtxgen] main -> INFO 001 Loading configuration 2022-01-18 01:48:14.004 EST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft 2022-01-18 01:48:14.004 EST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 2022-01-18 01:48:14.004 EST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /home/docker/github.com/hyperledger/fabric-2.2.4/scripts/fabric-samples-2.2.3/test-network/configtx/configtx.yaml 2022-01-18 01:48:14.006 EST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block 2022-01-18 01:48:14.006 EST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block + res=0 WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string. WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string. [+] Running 8/8 ⠿ Network docker_test Created 0.3s ⠿ Volume "docker_peer0.org1.example.com" Created 0.0s ⠿ Volume "docker_peer0.org2.example.com" Created 0.0s ⠿ Volume "docker_orderer.example.com" Created 0.0s ⠿ Container peer0.org1.example.com Started 1.6s ⠿ Container peer0.org2.example.com Started 1.4s ⠿ Container orderer.example.com Started 1.6s ⠿ Container cli Started 2.1s CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES afd75ec73842 hyperledger/fabric-tools:latest "/bin/bash" 2 seconds ago Up Less than a second cli 2753cd632896 hyperledger/fabric-peer:latest "peer node start" 2 seconds ago Up Less than a second 0.0.0.0:7051->7051/tcp peer0.org1.example.com 26af79e8ead7 hyperledger/fabric-orderer:latest "orderer" 2 seconds ago Up Less than a second 0.0.0.0:7050->7050/tcp orderer.example.com 0f9f4fbb21c4 hyperledger/fabric-peer:latest "peer node start" 2 seconds ago Up 1 second 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com



