Hyperledger Fabric is a platform for distributed ledger solutions, underpinned by a modular architecture delivering high degrees of confidentiality, resiliency, flexibility and scalability.
项目 | 版本 | 备注 |
centos | 7.7 | CentOS Linux release 7.7.1908 (Core) |
Go运行环境 | 1.15.7 | PATH 环境变量:/usr/local/go/bin GOPATH环境变量:/home/admin/go 部署步骤参考文章:https://blog.csdn.net/jeikerxiao/article/details/106708145 |
docker环境 | 20.10.3 | 部署步骤参考文章:https://www.runoob.com/docker/centos-docker-install.html 镜像加速配置文章:https://www.runoob.com/docker/docker-mirror-acceleration.html |
docker-compose | 1.26.2 | 部署步骤参考文章:https://www.runoob.com/docker/docker-compose.html 安装1.28.0版本时遇到【Error loading Python lib '/tmp/_MEIDfblYM/libpython3.9.so.1.0': dlopen: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /tmp/_MEIDfblYM/libpython3.9.so.1.0)】的情况,需要升级glibc参考这篇文章:https://bbs.huaweicloud.com/blogs/238962 |
git | 1.8.3.1 | yum install -y git |
[root@localhost hyperledger]# pwd
/home/admin/go/src/github.com/hyperledger
[root@localhost hyperledger]# git clone https://github.com/hyperledger/fabric.git
Cloning into 'fabric'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 148391 (delta 1), reused 2 (delta 0), pack-reused 148384
Receiving objects: 100% (148391/148391), 119.59 MiB | 9.51 MiB/s, done.
Resolving deltas: 100% (102673/102673), done.
[root@localhost hyperledger]# cd fabric/
[root@localhost fabric]# git branch -a
* main
remotes/origin/HEAD -> origin/main
remotes/origin/main
remotes/origin/release-2.0
remotes/origin/release-2.1
remotes/origin/release-2.2
remotes/origin/release-2.3
[root@localhost fabric]# git checkout -b 2.2 origin/release-2.2
Branch 2.2 set up to track remote branch release-2.2 from origin.
Switched to a new branch '2.2'
参考文章:https://blog.csdn.net/qq_38591756/article/details/86486922
在搭建fabric环境前,确保先成功启动了docker:systemctl start docker
1、下载样例程序
运行bootstrap.sh脚本,会执行3个任务:下载fabric-samples代码,下载二进制文件(bin目录下的可执行文件),下载docker镜像
[root@localhost opt]# cd /home/admin/go/src/github.com/hyperledger/fabric/scripts/
[root@localhost scripts]# ./bootstrap.sh
Clone hyperledger/fabric-samples repo
===> Cloning hyperledger/fabric-samples repo and checkout v2.2.2
Cloning into 'fabric-samples'...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 7422 (delta 0), reused 1 (delta 0), pack-reused 7414
Receiving objects: 100% (7422/7422), 4.28 MiB | 816.00 KiB/s, done.
Resolving deltas: 100% (3846/3846), done.
Pull Hyperledger Fabric binaries
===> Downloading version 2.2.2 platform specific fabric binaries
===> Downloading: https://github.com/hyperledger/fabric/releases/download/v2.2.2/hyperledger-fabric-linux-amd64-2.2.2.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 649 0 649 0 0 791 0 --:--:-- --:--:-- --:--:-- 792
100 72.8M 100 72.8M 0 0 8930k 0 0:00:08 0:00:08 --:--:-- 11.1M
==> Done.
===> Downloading version 1.4.9 platform specific fabric-ca-client binary
===> Downloading: https://github.com/hyperledger/fabric-ca/releases/download/v1.4.9/hyperledger-fabric-ca-linux-amd64-1.4.9.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 652 100 652 0 0 869 0 --:--:-- --:--:-- --:--:-- 869
100 23.6M 100 23.6M 0 0 7081k 0 0:00:03 0:00:03 --:--:-- 11.1M
==> Done.
Pull Hyperledger Fabric docker images
FABRIC_IMAGES: peer orderer ccenv tools nodeenv baseos javaenv
===> Pulling fabric Images
====> hyperledger/fabric-peer:2.2.2
2.2.2: Pulling from hyperledger/fabric-peer
801bfaa63ef2: Pull complete
5bc9fae5953a: Pull complete
0085bc0926f7: Pull complete
6310f1edd507: Pull complete
7ea79d3b8d71: Pull complete
cbccd7bce594: Pull complete
Digest: sha256:640940fc59e262f2f4e5ec983f216811aa9521117abfdc17b3a68bd9e1e88bce
Status: Downloaded newer image for hyperledger/fabric-peer:2.2.2
docker.io/hyperledger/fabric-peer:2.2.2
====> hyperledger/fabric-orderer:2.2.2
2.2.2: Pulling from hyperledger/fabric-orderer
801bfaa63ef2: Already exists
5bc9fae5953a: Already exists
2f7396fe4275: Pull complete
e0ab78965caf: Pull complete
286c7ed7e24d: Pull complete
51f86d4301d9: Pull complete
f6d14db84e1f: Pull complete
Digest: sha256:aa3fe23fb03843a7b8d5e9655dab4f58f033734cc5643a1b9514d8c4e62d702d
Status: Downloaded newer image for hyperledger/fabric-orderer:2.2.2
docker.io/hyperledger/fabric-orderer:2.2.2
====> hyperledger/fabric-ccenv:2.2.2
2.2.2: Pulling from hyperledger/fabric-ccenv
188c0c94c7c5: Pull complete
0ef7d3d256c8: Pull complete
de9db76c5a1d: Pull complete
a99aea8d7e66: Pull complete
a5124c9860dc: Pull complete
93fa3eeb24a8: Pull complete
4d1d2d976974: Pull complete
e5befbaf164e: Pull complete
ee08b062ab60: Pull complete
Digest: sha256:4064cb795e90ad5090d097569ca3570dae1cecec9751f64a745fc2a89dd40e21
Status: Downloaded newer image for hyperledger/fabric-ccenv:2.2.2
docker.io/hyperledger/fabric-ccenv:2.2.2
====> hyperledger/fabric-tools:2.2.2
2.2.2: Pulling from hyperledger/fabric-tools
188c0c94c7c5: Already exists
0ef7d3d256c8: Already exists
de9db76c5a1d: Already exists
a99aea8d7e66: Already exists
a5124c9860dc: Already exists
078888f6c53b: Pull complete
7ac0e26e0430: Pull complete
6e5dd8a13d61: Pull complete
Digest: sha256:a149d463e8679ef8ed7499b81c55539067d0989c804070fe2a6ca744ac2b692d
Status: Downloaded newer image for hyperledger/fabric-tools:2.2.2
docker.io/hyperledger/fabric-tools:2.2.2
====> hyperledger/fabric-nodeenv:2.2.2
Error response from daemon: manifest for hyperledger/fabric-nodeenv:2.2.2 not found: manifest unknown: manifest unknown
Error response from daemon: No such image: hyperledger/fabric-nodeenv:2.2.2
Error response from daemon: No such image: hyperledger/fabric-nodeenv:2.2.2
====> hyperledger/fabric-baseos:2.2.2
2.2.2: Pulling from hyperledger/fabric-baseos
801bfaa63ef2: Already exists
5bc9fae5953a: Already exists
5014e9a430cc: Pull complete
Digest: sha256:570013a2fb2c7fd1238d0e4c8a7949870fe42c0d5eb59b205944716af8c28bf0
Status: Downloaded newer image for hyperledger/fabric-baseos:2.2.2
docker.io/hyperledger/fabric-baseos:2.2.2
====> hyperledger/fabric-javaenv:2.2.2
Error response from daemon: manifest for hyperledger/fabric-javaenv:2.2.2 not found: manifest unknown: manifest unknown
Error response from daemon: No such image: hyperledger/fabric-javaenv:2.2.2
Error response from daemon: No such image: hyperledger/fabric-javaenv:2.2.2
===> Pulling fabric ca Image
====> hyperledger/fabric-ca:1.4.9
1.4.9: Pulling from hyperledger/fabric-ca
b8f262c62ec6: Pull complete
db9dbc6799b3: Pull complete
9c5c884a6020: Pull complete
370868734ec0: Pull complete
cbce57ae4cad: Pull complete
fc00299dbf2c: Pull complete
a1e42212f1ce: Pull complete
add0e148da22: Pull complete
Digest: sha256:28f50c6aa4f4642842e706d3ae6dcee181921d03bd30ab2a8b09b66e0349d92f
Status: Downloaded newer image for hyperledger/fabric-ca:1.4.9
docker.io/hyperledger/fabric-ca:1.4.9
===> List out hyperledger docker images
hyperledger/fabric-tools 2.2 212bfff67240 7 weeks ago 436MB
hyperledger/fabric-tools 2.2.2 212bfff67240 7 weeks ago 436MB
hyperledger/fabric-tools latest 212bfff67240 7 weeks ago 436MB
hyperledger/fabric-peer 2.2 0db1edb6ddd8 7 weeks ago 55MB
hyperledger/fabric-peer 2.2.2 0db1edb6ddd8 7 weeks ago 55MB
hyperledger/fabric-peer latest 0db1edb6ddd8 7 weeks ago 55MB
hyperledger/fabric-orderer 2.2 89cac0d3ab9b 7 weeks ago 38.5MB
hyperledger/fabric-orderer 2.2.2 89cac0d3ab9b 7 weeks ago 38.5MB
hyperledger/fabric-orderer latest 89cac0d3ab9b 7 weeks ago 38.5MB
hyperledger/fabric-ccenv 2.2 989d60213726 7 weeks ago 502MB
hyperledger/fabric-ccenv 2.2.2 989d60213726 7 weeks ago 502MB
hyperledger/fabric-ccenv latest 989d60213726 7 weeks ago 502MB
hyperledger/fabric-baseos 2.2 0483f4bff906 7 weeks ago 6.85MB
hyperledger/fabric-baseos 2.2.2 0483f4bff906 7 weeks ago 6.85MB
hyperledger/fabric-baseos latest 0483f4bff906 7 weeks ago 6.85MB
hyperledger/fabric-ca 1.4 dbbc768aec79 5 months ago 158MB
hyperledger/fabric-ca 1.4.9 dbbc768aec79 5 months ago 158MB
hyperledger/fabric-ca latest dbbc768aec79 5 months ago 158MB
2、启动样例网络
[root@localhost test-network]# pwd
/home/admin/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network
[root@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.2.2
DOCKER_IMAGE_VERSION=2.2.2
/home/admin/go/src/github.com/hyperledger/fabric/scripts/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
/home/admin/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/bin/configtxgen
Generating Orderer Genesis block
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
2021-03-20 01:12:47.704 EDT [common.tools.configtxgen] main -> INFO 001 Loading configuration
2021-03-20 01:12:47.734 EDT [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2021-03-20 01:12:47.734 EDT [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
2021-03-20 01:12:47.734 EDT [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /home/admin/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/configtx/configtx.yaml
2021-03-20 01:12:47.736 EDT [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2021-03-20 01:12:47.737 EDT [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block
+ res=0
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.org1.example.com ... done
Creating peer0.org2.example.com ... done
Creating orderer.example.com ... done
Creating cli ... done
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f42945e83b29 hyperledger/fabric-tools:latest "/bin/bash" Less than a second ago Up Less than a second cli
bb4424c951b2 hyperledger/fabric-peer:latest "peer node start" 1 second ago Up Less than a second 0.0.0.0:7051->7051/tcp peer0.org1.example.com
637cb307ace6 hyperledger/fabric-peer:latest "peer node start" 1 second ago Up Less than a second 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com
1451be791c34 hyperledger/fabric-orderer:latest "orderer" 1 second ago Up Less than a second 0.0.0.0:7050->7050/tcp orderer.example.com
b2bbf3c11ff7 hello-world "/hello" 22 hours ago Exited (0) 22 hours ago zen_meninsky
分析此脚本执行过程:
1、判断子目录organizations\peerOrganizations是否存在,不存在则创建【组织】
2、构建并启动nignx容器【docker-compose -f docker/docker-compose-test-net.yaml up -d 2>&1】
3、判断是否启动失败【docker ps -a】
最终的效果:two Organization peers and an ordering service node.
容器没有成功启动
could not load a valid signer certificate from directory /etc/hyperledger/fabric/msp/signcerts
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
52acf30970da hyperledger/fabric-tools:latest "/bin/bash" About an hour ago Up About an hour cli
34d4c643459d hyperledger/fabric-peer:latest "peer node start" About an hour ago Exited (1) About an hour ago peer0.org2.example.com
6c61488258ee hyperledger/fabric-peer:latest "peer node start" About an hour ago Exited (1) About an hour ago peer0.org1.example.com
abba2acbaf39 hyperledger/fabric-orderer:latest "orderer" About an hour ago Exited (2) About an hour ago orderer.example.com
$ docker logs 34d4c643459d
2021-03-16 02:12:40.975 UTC [main] InitCmd ->
ERRO 001 Cannot run peer because error when setting up MSP of type bccsp from directory /etc/hyperledger/fabric/msp:
could not load a valid signer certificate from directory /etc/hyperledger/fabric/msp/signcerts:
stat /etc/hyperledger/fabric/msp/signcerts: no such file or directory
解决办法:重来一遍