日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Hyperledger fabric1.4.0搭建环境

發布時間:2025/3/21 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Hyperledger fabric1.4.0搭建环境 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Hyperledger fabric1.4.0搭建環境
原創牧竹子 最后發布于2019-05-11 21:10:20 閱讀數 630 ?收藏
展開
Hyperledger fabric1.4.0搭建環境

版本
在Ubuntu 18.04上搭建Hyperledger fabric1.4.0環境
https://www.jianshu.com/p/4f58e0fcb9f9

https://blog.csdn.net/javaexploreroooo/article/details/71157902

https://blog.csdn.net/zgljl2012/article/details/52896372

https://blog.csdn.net/songfadan/article/details/80827446

環境和工具
操作系統 ubuntu14
go 1.11.1
docker 17.06.2-ce
docker-compose 1.23.1
curl組件for windows

常用的幾個vagrant命令

$ vagrant init ? ? ?# 初始化

$ vagrant up ? ? ? ?# 啟動虛擬機
$ vagrant halt ? ? ?# 關閉虛擬機
$ vagrant reload ? ?# 重啟虛擬機
$ vagrant ssh ? ? ? # SSH 至虛擬機
$ vagrant suspend ? # 掛起虛擬機
$ vagrant resume ? ?# 喚醒虛擬機
$ vagrant status ? ?# 查看虛擬機運行狀態
$ vagrant destroy ? # 銷毀當前虛擬機


### box管理命令
$ vagrant box list ? ?# 查看本地box列表
$ vagrant box add ? ? # 添加box到列表

$ vagrant box remove ?# 從box列表移除?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
CURL命令安裝
下載地址curl 7.64.1 for Windows
https://curl.haxx.se/windows/

解壓配置到path下即可

查看window的PowerShell版本號
運行打開->powershell回車,在命令行窗口中輸入命令

$PSVersionTable.PSVersion
1
windows7,默認的powershell版本是2.0,而vargent需要的是powershell 3.0以上才可以使用,故而記錄一下我升級的歷程。

首先,win+r,輸入appwiz.cpl,點擊左側的已安裝的更新,看一下你的計算機中是否安裝了Microsoft Windows Management Framework 3.0 Beta (KB2506143),如果有的話就先把他卸載了(4.0的可以不用卸載,后面也不用下載安裝4.0了)。
然后在微軟官網上下載.NET 4.0或者.NET 4.5
最后安裝Microsoft Windows Management Framework 3.0的6.1內核版本安裝文件,
鏈接:http://download.microsoft.com/download/E/7/6/E76850B8-DA6E-4FF5-8CCE-A24FC513FD16/Windows6.1-KB2506143-x64.msu

安裝程序遇到錯誤0x80240037
把Windows6.1-KB2506143-x64.msu的后綴名msu改為cab,然后解壓,注意解壓到一個新的文件夾中,不要在本文件夾中解壓(例如:我的解壓在Windows6.1-KB2506143-x64文件夾中);
然后運行cmd(win鍵+R鍵)

dism /online /add-package /packagepath:"d:\Windows6.1-KB2506143-x64\Windows6.1-KB2506143-x64.cab"
1
然后詢問是否重啟,Y重啟即可

虛擬機安裝
安裝好go,box和vagrant之后

git拷貝fabric項目到本地

git clone https://github.com/hyperledger/fabric.git
cd gopath/src/fabric/devenv
vagrant up
1
2
3
默認會安裝Ubuntu14.4的鏡像虛擬機

SSH登陸虛擬機
?ssh -p 2222 vagrant@127.0.0.1
1
解決Docker pull鏡像速度過慢的問題
##使用阿里云鏡像加速器
[root@localhost ~]# mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
? "registry-mirrors": ["https://9cpn8tt6.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker

1
2
3
4
5
6
7
8
9
10
fabric-tools :是本地客戶端鏡像,主要用來執行 Peer 節 點中的相關操作,如頻道 、 智能合 約等。fabric-peer 是 Fabric 中網絡節點鏡像,從 1.0 版本開始, Fabric 的 Peer 不再提交數據, 全 部由客戶端完成,但 Peer 依然會對數據進行提交前的驗證和背書 。
fabric-couchdb :是第 三 方可插拔式數據庫鏡像 , fabric-couchdb 非必須,如果不使用 CouchDB,則會默認使用 LeveIDB,相比較而言使用 CouchDB 功能性更強一些。
fabric-ca 是服務器本地 CA Se凹er,可以執行 fabric-ca-client 中的相關操作,實現登陸、注 冊及吊銷等方法。
fabric-order:是Fabric的排序節點
fabric-kafka :fabric集群共識,單機版默認是solo,orderer節點排序必須要,如果是單機可以不配置kafka,使用solo即可滿足
fabric-zookeeper : 如果將共識從solo改為kafka則這個組件是必須的,主要為了解決分布式一致性的問題

編譯docker
cd $GOPATH/src/github.com/hyperledger/fabric
# 切換版本
make release
make docker
1
2
3
4
完成之后,輸入如下命令驗證:

cd /release/linux-amd64/bin
./peer version
./orderer version
./cryptogen version
./configtxgen version
./configtxlator version
1
2
3
4
5
6
拷貝到 ~/.local/bin目錄下

使用自帶的fabric-samples樣例快速體驗它的過程
進入$GOPATH/fabric/scripts目錄可以看到一個bootstrap.sh腳本(注意剛開始是沒有fabric-samples這個文件夾的,是執行腳本后生成的)

1.創建鏡像
直接執行bootstrap.sh腳本,就會自動進行fabric相關鏡像的下載 (時間有點久,如果出現長時間停頓,可能需要重啟虛擬機后重新執行腳本)

./bootstrap.sh
1
2.生成配置
進入fabric/scripts/fabric-samples/first-network/

?./byfn.sh -m generate -c jschannel
1
3.啟動網絡
執行以下命令啟動網絡

./byfn.sh -m up -c jschannel
1
通過top命令可以看到此時fabric網絡peer節點的運行情況

? PID USER ? ? ?PR ?NI ? ?VIRT ? ?RES ? ?SHR S ?%CPU %MEM ? ? TIME+ COMMAND
?3928 root ? ? ?20 ? 0 ?325728 ?42820 ?21804 S ? 1.7 ?1.1 ? 0:00.90 peer
?4038 root ? ? ?20 ? 0 ?399460 ?72792 ?22068 S ? 1.7 ?1.8 ? 0:00.93 peer
?3848 root ? ? ?20 ? 0 ?342120 ?42108 ?21664 S ? 1.3 ?1.0 ? 0:00.90 peer
?4055 root ? ? ?20 ? 0 ?333924 ?67720 ?21828 S ? 1.3 ?1.7 ? 0:01.01 peer
1
2
3
4
5
停止命令

./byfn.sh -m down
1
最后,讓我們把它全部停下來,這樣我們可以一步一步地探索網絡設置。以下操作將關閉你的容器,移除加密材料和4個配置信息,并且從Docker倉庫刪除chaincode鏡像。你將再一次被提示是否繼續,回答y:

快速體驗說明
它會創建兩個組織org1,org2
兩個組織各有兩個peer:net_peer0,net_peer1

在SRAT和END之間為測試程序的過程,通過打印的日志,我們可以知道它的經歷了哪幾個測試以及相關的命令參數

創建通道
Creating channel...
+ peer channel create -o orderer.example.com:7050 -c jschannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/go
path/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscace
rts/tlsca.example.com-cert.pem
1
2
3
4
peer加入通道
?peer channel join -b jschannel.block
1
手工實現方式如下
以上過程都是單個命令行就完成了,實際上它的手工操作過程相當繁瑣,同樣為上例結果,手動實現方式如下
https://blog.csdn.net/destiny_aqua/article/details/86595044
1.下載可執行文件:./bootstrap.sh會把相關執行文件下載到當前的bin目錄下
2. 創建證書
創建證書所需要的文件crypto-config.yaml,1.3.0版本之前(包括1.3.0)來自fabric目前下的example目錄下的e2e_cli示例;1.4.0版本來自fabric-sample目錄下的first-network

#1、當前目錄是/fabric/scripts/fabric-samples,進入第一個測試fabric網絡
cd first-network/
#2、使用bin/cryptogen工具創建證書文件,生成如下兩個組織(顯示域名)
#生成org1和org2兩個組織:org1.example.com和org2.example.com,放入crypto-config文件夾內。
../bin/cryptogen generate --config=./crypto-config.yaml?
1
2
3
4
5
3.創建創世區塊
1.4.0的快速測試中過程相同,在first-network/channel-artifacts文件夾中

#1 設置環境變量并創建channel-artifacts文件夾,目的是將創世區塊放入channel-artifacts文件夾內
#2 創建創世區塊,參考https://hyperledger-fabric.readthedocs.io/en/release-1.4/commands/configtxgen.html?highlight=configtxgen 該說明講解查看創世區塊中的內容
../bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
#3 設置通道的交易文件
export CHANNEL_NAME=mychannel ?&& ../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
#4 生成Org1MSP和Org2MSP的anchor peer(在org1組織下的節點提交交易信息的背書環節使用)
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP

1
2
3
4
5
6
7
8
9
4.啟動網絡
fabric網絡包含1個orderer和4個peer以及1個client。使用docker-compose運行docker節點。

#up-啟動;down-停止;-d參數表示后臺啟動,去掉-d參數可以查看日志
docker-compose -f docker-compose-cli.yaml up -d
#查看啟動的peer節點和orderer節點的docker,以及相關的ca、couchdb的docker(本示例沒有ca和couchdb)
docker ps -a
1
2
3
4
5.客戶端安裝鏈碼,實例化鏈碼

主要是客戶端操作具體內容了,這個過程其實就是上面快速測試時,START和END之間的部分
主要作用是:
1.創建channel
2.把peer加入channel 、anchor peer
3.加入anchor peer
4.實例化chaincode

docker exec -it cli bash
#下面是執行結果
root@138cc70a4bba:/opt/gopath/src/github.com/hyperledger/fabric/peer#

#1 創建channel channel.tx是2.1小節中生成的交易證書,cli客戶端通過裝載channel-artifacts文件夾獲得
# ca-cert是驗證TLS握手協議必須的證書文件,使用前需要設置CHANNEL_NAME
export CHANNEL_NAME=mychannel
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
#下面是執行結果
2019-01-22 07:41:30.487 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2019-01-22 07:41:30.566 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2019-01-22 07:41:30.570 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2019-01-22 07:41:30.600 UTC [cli.common] readBlock -> INFO 004 Received block: 0

#2 將peer加入channel中
peer channel join -b mychannel.block
#下面是執行結果
2019-01-22 07:43:24.007 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2019-01-22 07:43:24.049 UTC [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel

#3 peer0.org2加入channel中
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_LOCALMSPID="Org2MSP" CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt peer channel join -b mychannel.block
#下面是執行結果
2019-01-22 07:45:13.129 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2019-01-22 07:45:13.170 UTC [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel

#4 加入anchor peer
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
#下面是執行結果
2019-01-22 07:45:55.005 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2019-01-22 07:45:55.013 UTC [channelCmd] update -> INFO 004 Successfully submitted channel update

#5 peer0.org2加入anchor peer
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_LOCALMSPID="Org2MSP" CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
#下面是執行結果
2019-01-22 07:46:55.829 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2019-01-22 07:46:55.838 UTC [channelCmd] update -> INFO 004 Successfully submitted channel update

#6 安裝chaincode -P "AND ('Org1MSP.peer','Org2MSP.peer')"背書策略意味著需要兩個節點一起才能背書
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
#下面是執行結果
2019-01-22 07:47:47.851 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2019-01-22 07:47:47.851 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2019-01-22 07:47:50.488 UTC [chaincodeCmd] install -> INFO 005 Installed remotely response:<status:200 payload:"OK" >?

#7 peer0.org2安裝chaincode
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_LOCALMSPID="Org2MSP" CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/

2019-01-22 07:55:38.252 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2019-01-22 07:55:38.252 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2019-01-22 07:55:38.491 UTC [chaincodeCmd] install -> INFO 005 Installed remotely response:<status:200 payload:"OK" >?

#8 實例化chaincode
peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
#下面是執行結果
2019-01-22 07:49:10.480 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2019-01-22 07:49:10.480 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
參考資料
Windows 7 升級powershell 2 到 powershell 3
https://www.jianshu.com/p/16cd4b25249c

使用vagrant+VirtualBox搭建虛擬開發環境
https://blog.csdn.net/bluehawksky/article/details/80417845

安裝程序遇到錯誤0x80240037
https://blog.csdn.net/m0_37397536/article/details/79271709

Ubuntu 使用ssh免登陸~/.ssh/authorized_keys
https://blog.csdn.net/nmjhehe/article/details/81050713

Hyperledger Fabric開發實戰-01環境搭建
https://www.jianshu.com/p/0ec409f77fb3

centos7安裝配置Hyperledger fabric1.4.0
https://blog.csdn.net/asn_forever/article/details/86505376
手工實現自帶的快速樣例fabric-sample(first_network)
https://blog.csdn.net/destiny_aqua/article/details/86595044

fabric錯誤集 1
https://blog.csdn.net/david_shangyin/article/details/84348528

SDK和集群的搭建
https://www.jianshu.com/p/3185d1e57259

點贊
————————————————
版權聲明:本文為CSDN博主「牧竹子」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/zjcjava/article/details/90115079

總結

以上是生活随笔為你收集整理的Hyperledger fabric1.4.0搭建环境的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。