Hyperledger fabric1.4.0搭建环境
Hyperledger fabric1.4.0搭建環(huán)境
原創(chuàng)牧竹子 最后發(fā)布于2019-05-11 21:10:20 閱讀數(shù) 630 ?收藏
展開
Hyperledger fabric1.4.0搭建環(huán)境
版本
在Ubuntu 18.04上搭建Hyperledger fabric1.4.0環(huán)境
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
環(huán)境和工具
操作系統(tǒng) ubuntu14
go 1.11.1
docker 17.06.2-ce
docker-compose 1.23.1
curl組件for windows
常用的幾個(gè)vagrant命令
$ vagrant init ? ? ?# 初始化
$ vagrant up ? ? ? ?# 啟動(dòng)虛擬機(jī)
$ vagrant halt ? ? ?# 關(guān)閉虛擬機(jī)
$ vagrant reload ? ?# 重啟虛擬機(jī)
$ vagrant ssh ? ? ? # SSH 至虛擬機(jī)
$ vagrant suspend ? # 掛起虛擬機(jī)
$ vagrant resume ? ?# 喚醒虛擬機(jī)
$ vagrant status ? ?# 查看虛擬機(jī)運(yùn)行狀態(tài)
$ vagrant destroy ? # 銷毀當(dāng)前虛擬機(jī)
### 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版本號(hào)
運(yùn)行打開->powershell回車,在命令行窗口中輸入命令
$PSVersionTable.PSVersion
1
windows7,默認(rèn)的powershell版本是2.0,而vargent需要的是powershell 3.0以上才可以使用,故而記錄一下我升級(jí)的歷程。
首先,win+r,輸入appwiz.cpl,點(diǎn)擊左側(cè)的已安裝的更新,看一下你的計(jì)算機(jī)中是否安裝了Microsoft Windows Management Framework 3.0 Beta (KB2506143),如果有的話就先把他卸載了(4.0的可以不用卸載,后面也不用下載安裝4.0了)。
然后在微軟官網(wǎng)上下載.NET 4.0或者.NET 4.5
最后安裝Microsoft Windows Management Framework 3.0的6.1內(nèi)核版本安裝文件,
鏈接:http://download.microsoft.com/download/E/7/6/E76850B8-DA6E-4FF5-8CCE-A24FC513FD16/Windows6.1-KB2506143-x64.msu
安裝程序遇到錯(cuò)誤0x80240037
把Windows6.1-KB2506143-x64.msu的后綴名msu改為cab,然后解壓,注意解壓到一個(gè)新的文件夾中,不要在本文件夾中解壓(例如:我的解壓在Windows6.1-KB2506143-x64文件夾中);
然后運(yùn)行cmd(win鍵+R鍵)
dism /online /add-package /packagepath:"d:\Windows6.1-KB2506143-x64\Windows6.1-KB2506143-x64.cab"
1
然后詢問是否重啟,Y重啟即可
虛擬機(jī)安裝
安裝好go,box和vagrant之后
git拷貝fabric項(xiàng)目到本地
git clone https://github.com/hyperledger/fabric.git
cd gopath/src/fabric/devenv
vagrant up
1
2
3
默認(rèn)會(huì)安裝Ubuntu14.4的鏡像虛擬機(jī)
SSH登陸虛擬機(jī)
?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 :是本地客戶端鏡像,主要用來執(zhí)行 Peer 節(jié) 點(diǎn)中的相關(guān)操作,如頻道 、 智能合 約等。fabric-peer 是 Fabric 中網(wǎng)絡(luò)節(jié)點(diǎn)鏡像,從 1.0 版本開始, Fabric 的 Peer 不再提交數(shù)據(jù), 全 部由客戶端完成,但 Peer 依然會(huì)對(duì)數(shù)據(jù)進(jìn)行提交前的驗(yàn)證和背書 。
fabric-couchdb :是第 三 方可插拔式數(shù)據(jù)庫(kù)鏡像 , fabric-couchdb 非必須,如果不使用 CouchDB,則會(huì)默認(rèn)使用 LeveIDB,相比較而言使用 CouchDB 功能性更強(qiáng)一些。
fabric-ca 是服務(wù)器本地 CA Se凹er,可以執(zhí)行 fabric-ca-client 中的相關(guān)操作,實(shí)現(xiàn)登陸、注 冊(cè)及吊銷等方法。
fabric-order:是Fabric的排序節(jié)點(diǎn)
fabric-kafka :fabric集群共識(shí),單機(jī)版默認(rèn)是solo,orderer節(jié)點(diǎn)排序必須要,如果是單機(jī)可以不配置kafka,使用solo即可滿足
fabric-zookeeper : 如果將共識(shí)從solo改為kafka則這個(gè)組件是必須的,主要為了解決分布式一致性的問題
編譯docker
cd $GOPATH/src/github.com/hyperledger/fabric
# 切換版本
make release
make docker
1
2
3
4
完成之后,輸入如下命令驗(yàn)證:
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樣例快速體驗(yàn)它的過程
進(jìn)入$GOPATH/fabric/scripts目錄可以看到一個(gè)bootstrap.sh腳本(注意剛開始是沒有fabric-samples這個(gè)文件夾的,是執(zhí)行腳本后生成的)
1.創(chuàng)建鏡像
直接執(zhí)行bootstrap.sh腳本,就會(huì)自動(dòng)進(jìn)行fabric相關(guān)鏡像的下載 (時(shí)間有點(diǎn)久,如果出現(xiàn)長(zhǎng)時(shí)間停頓,可能需要重啟虛擬機(jī)后重新執(zhí)行腳本)
./bootstrap.sh
1
2.生成配置
進(jìn)入fabric/scripts/fabric-samples/first-network/
?./byfn.sh -m generate -c jschannel
1
3.啟動(dòng)網(wǎng)絡(luò)
執(zhí)行以下命令啟動(dòng)網(wǎng)絡(luò)
./byfn.sh -m up -c jschannel
1
通過top命令可以看到此時(shí)fabric網(wǎng)絡(luò)peer節(jié)點(diǎn)的運(yùn)行情況
? 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
最后,讓我們把它全部停下來,這樣我們可以一步一步地探索網(wǎng)絡(luò)設(shè)置。以下操作將關(guān)閉你的容器,移除加密材料和4個(gè)配置信息,并且從Docker倉(cāng)庫(kù)刪除chaincode鏡像。你將再一次被提示是否繼續(xù),回答y:
快速體驗(yàn)說明
它會(huì)創(chuàng)建兩個(gè)組織org1,org2
兩個(gè)組織各有兩個(gè)peer:net_peer0,net_peer1
在SRAT和END之間為測(cè)試程序的過程,通過打印的日志,我們可以知道它的經(jīng)歷了哪幾個(gè)測(cè)試以及相關(guān)的命令參數(shù)
創(chuàng)建通道
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
手工實(shí)現(xiàn)方式如下
以上過程都是單個(gè)命令行就完成了,實(shí)際上它的手工操作過程相當(dāng)繁瑣,同樣為上例結(jié)果,手動(dòng)實(shí)現(xiàn)方式如下
https://blog.csdn.net/destiny_aqua/article/details/86595044
1.下載可執(zhí)行文件:./bootstrap.sh會(huì)把相關(guān)執(zhí)行文件下載到當(dāng)前的bin目錄下
2. 創(chuàng)建證書
創(chuàng)建證書所需要的文件crypto-config.yaml,1.3.0版本之前(包括1.3.0)來自fabric目前下的example目錄下的e2e_cli示例;1.4.0版本來自fabric-sample目錄下的first-network
#1、當(dāng)前目錄是/fabric/scripts/fabric-samples,進(jìn)入第一個(gè)測(cè)試fabric網(wǎng)絡(luò)
cd first-network/
#2、使用bin/cryptogen工具創(chuàng)建證書文件,生成如下兩個(gè)組織(顯示域名)
#生成org1和org2兩個(gè)組織:org1.example.com和org2.example.com,放入crypto-config文件夾內(nèi)。
../bin/cryptogen generate --config=./crypto-config.yaml?
1
2
3
4
5
3.創(chuàng)建創(chuàng)世區(qū)塊
1.4.0的快速測(cè)試中過程相同,在first-network/channel-artifacts文件夾中
#1 設(shè)置環(huán)境變量并創(chuàng)建channel-artifacts文件夾,目的是將創(chuàng)世區(qū)塊放入channel-artifacts文件夾內(nèi)
#2 創(chuàng)建創(chuàng)世區(qū)塊,參考https://hyperledger-fabric.readthedocs.io/en/release-1.4/commands/configtxgen.html?highlight=configtxgen 該說明講解查看創(chuàng)世區(qū)塊中的內(nèi)容
../bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
#3 設(shè)置通道的交易文件
export CHANNEL_NAME=mychannel ?&& ../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
#4 生成Org1MSP和Org2MSP的anchor peer(在org1組織下的節(jié)點(diǎn)提交交易信息的背書環(huán)節(jié)使用)
../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.啟動(dòng)網(wǎng)絡(luò)
fabric網(wǎng)絡(luò)包含1個(gè)orderer和4個(gè)peer以及1個(gè)client。使用docker-compose運(yùn)行docker節(jié)點(diǎn)。
#up-啟動(dòng);down-停止;-d參數(shù)表示后臺(tái)啟動(dòng),去掉-d參數(shù)可以查看日志
docker-compose -f docker-compose-cli.yaml up -d
#查看啟動(dòng)的peer節(jié)點(diǎn)和orderer節(jié)點(diǎn)的docker,以及相關(guān)的ca、couchdb的docker(本示例沒有ca和couchdb)
docker ps -a
1
2
3
4
5.客戶端安裝鏈碼,實(shí)例化鏈碼
主要是客戶端操作具體內(nèi)容了,這個(gè)過程其實(shí)就是上面快速測(cè)試時(shí),START和END之間的部分
主要作用是:
1.創(chuàng)建channel
2.把peer加入channel 、anchor peer
3.加入anchor peer
4.實(shí)例化chaincode
docker exec -it cli bash
#下面是執(zhí)行結(jié)果
root@138cc70a4bba:/opt/gopath/src/github.com/hyperledger/fabric/peer#
#1 創(chuàng)建channel channel.tx是2.1小節(jié)中生成的交易證書,cli客戶端通過裝載channel-artifacts文件夾獲得
# ca-cert是驗(yàn)證TLS握手協(xié)議必須的證書文件,使用前需要設(shè)置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
#下面是執(zhí)行結(jié)果
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
#下面是執(zhí)行結(jié)果
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
#下面是執(zhí)行結(jié)果
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
#下面是執(zhí)行結(jié)果
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
#下面是執(zhí)行結(jié)果
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')"背書策略意味著需要兩個(gè)節(jié)點(diǎn)一起才能背書
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
#下面是執(zhí)行結(jié)果
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 實(shí)例化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')"
#下面是執(zhí)行結(jié)果
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 升級(jí)powershell 2 到 powershell 3
https://www.jianshu.com/p/16cd4b25249c
使用vagrant+VirtualBox搭建虛擬開發(fā)環(huán)境
https://blog.csdn.net/bluehawksky/article/details/80417845
安裝程序遇到錯(cuò)誤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開發(fā)實(shí)戰(zhàn)-01環(huán)境搭建
https://www.jianshu.com/p/0ec409f77fb3
centos7安裝配置Hyperledger fabric1.4.0
https://blog.csdn.net/asn_forever/article/details/86505376
手工實(shí)現(xiàn)自帶的快速樣例fabric-sample(first_network)
https://blog.csdn.net/destiny_aqua/article/details/86595044
fabric錯(cuò)誤集 1
https://blog.csdn.net/david_shangyin/article/details/84348528
SDK和集群的搭建
https://www.jianshu.com/p/3185d1e57259
點(diǎn)贊
————————————————
版權(quán)聲明:本文為CSDN博主「牧竹子」的原創(chuàng)文章,遵循 CC 4.0 BY-SA 版權(quán)協(xié)議,轉(zhuǎn)載請(qǐng)附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/zjcjava/article/details/90115079
總結(jié)
以上是生活随笔為你收集整理的Hyperledger fabric1.4.0搭建环境的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hyperledger Fabric 1
- 下一篇: 简单记录一下fabric版本1.4的环境