Ubuntu18.04配置hyperledger fabric2.2.0环境

 

学习区块链,记录一下学习过程,文章有不对的地方,希望大佬指正,有不懂的地方乐于帮助

 

一、准备工作

1.安装curl     curl --version 查询版本

2.安装docker   docker --version 查询版本

3.安装docker-compose docker-compose --version 查询版本

4.安装go语言环境  go version  查询版本

5.安装node.js  node -v  查询版本

二、配置环境

1.创建一个目录

mkdir hyperledgerfabric #创建目录

cd hyperledger-fabric  #进入目录

2.下载并执行脚本

这个过程很慢,下载失败就再来一次,要有耐心。

curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s -- 2.2.0 1.4.7 0.4.10

下载好的导出是:

Clone hyperledger/fabric-samples repo

===> Cloning hyperledger/fabric-samples repo
正克隆到 'fabric-samples'...
remote: Enumerating objects: 20, done.
remote: Counting objects: 100% (20/20), done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 7386 (delta 2), reused 8 (delta 0), pack-reused 7366
接收对象中: 100% (7386/7386), 4.26 MiB | 22.00 KiB/s, 完成.
处理 delta 中: 100% (3823/3823), 完成.
===> Checking out v2.2.0 of hyperledger/fabric-samples

Pull Hyperledger Fabric binaries

===> Downloading version 2.2.0 platform specific fabric binaries
===> Downloading:  https://github.com/hyperledger/fabric/releases/download/v2.2.0/hyperledger-fabric-linux-amd64-2.2.0.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   649  100   649    0     0    511      0  0:00:01  0:00:01 --:--:--   511
100 72.7M  100 72.7M    0     0  81006      0  0:15:41  0:15:41 --:--:--  106k
==> Done.
===> Downloading version 1.4.7 platform specific fabric-ca-client binary
===> Downloading:  https://github.com/hyperledger/fabric-ca/releases/download/v1.4.7/hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   652  100   652    0     0    686      0 --:--:-- --:--:-- --:--:--   686
100 23.6M  100 23.6M    0     0  68041      0  0:06:03  0:06:03 --:--:-- 47732
==> Done.

接下来docker会拉取镜像文件,分别是:

hyperledger/fabric-tools       2.2.0        
hyperledger/fabric-peer        2.2.0    
hyperledger/fabric-orderer     2.2.0        
hyperledger/fabric-ccenv       2.2.0        
hyperledger/fabric-baseos      2.2.0       
hyperledger/fabric-nodeenv     2.2.0        
hyperledger/fabric-javaenv     2.2.0        
hyperledger/fabric-ca    1.4.7        
hyperledger/fabric-zookeeper   0.4.10       
hyperledger/fabric-kafka       0.4.10       
hyperledger/fabric-couchdb  0.4.10

这些文件我建议提前自己拉取好,这样就不会导致二进制文件好不容易下载好了,拉取镜像卡顿导致又得重新下载,搞人心态哦

在拉取镜像前要记得换国内源,方法在另一篇总结

例如:

docker pull hyperledger/fabric-tools:2.2.0

三、测试网络

cd fabric-samples
ls   #查看是否有test-network目录
ls
asset-transfer-abac               CHANGELOG.md         LICENSE
asset-transfer-basic              ci                   MAINTAINERS.md
asset-transfer-events             CODE_OF_CONDUCT.md   off_chain_data
asset-transfer-ledger-queries     CODEOWNERS           README.md
asset-transfer-private-data       commercial-paper     scripts
asset-transfer-sbe                config               SECURITY.md
asset-transfer-secured-agreement  CONTRIBUTING.md      test-application
auction                           fabcar               test-network
bin                               high-throughput      token-erc-20
chaincode                         interest_rate_swaps  token-utxo
cd test-network

启动测试网络

 sudo ./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.0
DOCKER_IMAGE_VERSION=2.2.0
/home/zhangxiushan/hyperledger-fabric/fabric-samples/test-network/../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/zhangxiushan/hyperledger-fabric/fabric-samples/test-network/../bin/configtxgen
Generating Orderer Genesis block
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
2021-02-25 05:47:23.810 EET [common.tools.configtxgen] main -> INFO 001 Loading configuration
2021-02-25 05:47:23.917 EET [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2021-02-25 05:47:23.917 EET [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-02-25 05:47:23.917 EET [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /home/zhangxiushan/hyperledger-fabric/fabric-samples/test-network/configtx/configtx.yaml
2021-02-25 05:47:23.921 EET [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2021-02-25 05:47:23.921 EET [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
28c8f7283ce7   hyperledger/fabric-tools:latest     "/bin/bash"         6 seconds ago    Up 1 second                                       cli
8f41c84eb8fb   hyperledger/fabric-peer:latest      "peer node start"   28 seconds ago   Up 6 seconds   0.0.0.0:7051->7051/tcp             peer0.org1.example.com
1031ad6ca3aa   hyperledger/fabric-peer:latest      "peer node start"   28 seconds ago   Up 6 seconds   7051/tcp, 0.0.0.0:9051->9051/tcp   peer0.org2.example.com
877e4cd6ff23   hyperledger/fabric-orderer:latest   "orderer"           28 seconds ago   Up 8 seconds   0.0.0.0:7050->7050/tcp             orderer.example.com

配置完成

关闭网络

./network.sh down
Stopping network
Stopping cli                    ... done
Stopping peer0.org1.example.com ... done
Stopping peer0.org2.example.com ... done
Stopping orderer.example.com    ... done
Removing cli                    ... done
Removing peer0.org1.example.com ... done
Removing peer0.org2.example.com ... done
Removing orderer.example.com    ... done
Removing network net_test
Removing volume net_orderer.example.com
Removing volume net_peer0.org1.example.com
Removing volume net_peer0.org2.example.com
Removing network net_test
WARNING: Network net_test not found.
Removing volume net_peer0.org3.example.com
WARNING: Volume net_peer0.org3.example.com not found.
No containers available for deletion
No images available for deletion

                                                                                                                               Ubuntu18.04配置hyperledger fabric2.2.0环境_第1张图片

 

感谢博主以及参考文章:

 https://blog.csdn.net/shengsikandan/article/details/107656060?spm=1001.2014.3001.5502

https://blog.csdn.net/aiwaston/article/details/108800937

 

你可能感兴趣的:(笔记,ubuntu,区块链,hyperledger,fabric)