最終環境說明:ubuntu環境、新建並進入名爲fabric的用戶,Composer和blockchain explorer都被安裝到了fabric用戶的~目錄
一、前置條件
1. 已安裝Hyperledger Fabric
2. 已安裝Hyperledger Composer
3. 已安裝nodejs 8.11.x (Note that v9.x is not yet supported)(如果安裝了Fabric,一般該項已安裝)
4. 已安裝docker 17.06.2-ce(如果安裝了Fabric,一般該項已安裝)
5. 已安裝docker-compose 1.14.0(如果安裝了Fabric,一般該項已安裝)
6. 已安裝PostgreSQL 9.5 or greater
如果沒有安裝PostgreSQL,則可按照以下教程按照
// 安裝PostgreSQL
sudo apt update
sudo apt-get install postgresql-9.5
教程https://blog.csdn.net/u013719339/article/details/84134586
二、下載blockchain explorer代碼並切換到3.5.1版本
進入到fabric用戶的~目錄,無論是git下載,還是壓縮包解壓,本文都放到了fabric用戶的~目錄。
1. git方式下載
git clone https://github.com/hyperledger/blockchain-explorer.git
git checkout -b release-3.5.1 origin/release-3.5.1
2. 源代碼壓縮包下載
https://github.com/hyperledger/blockchain-explorer/tags?after=v0.3.7.1
完成下載之後,目錄結構爲
下載後解壓的blockchain explore文件夾要給予權限
cd blockchain-explorer-0.3.5.1
chmod -R 775 ./*
三、初始化數據庫
1. 設置數據庫連接信息
cd blockchain-explorer-0.3.5.1
cd blockchain-explorer-0.3.5.1/app/persistence/postgreSQL/db
更改pgconfig.json文件,可以自己定義,後續腳本會生成對應用戶
"pg": {
"host": "127.0.0.1",
"port": "5432",
"database": "fabricexplorer",
"username": "hppoc",
"passwd": "password"
}
2.創建數據庫並連接數據庫
// 更改當前文件夾腳本權限
chmod -R 775 ./*
// 創建數據庫 (創建數據庫只用執行這一步,很多教程是執行了很多步,效果一樣)
./createdb.sh
// 連接數據庫
sudo -u postgres psql
四、保持狀態
1. 按照上面步驟,postgres數據庫處於連接狀態
2. 啓動HyperLedger Composer
可以通過瀏覽器進入http://localhost:3000到playground驗證是否啓動成功
五、修改blockchain explore連接fabric的配置文件
cd blockchain-explorer-0.3.5.1/app/platform/fabric/config.json
1. 配置文件中需要的信息來自《Hyperledger Composer 查看Fabric網絡連接配置信息》https://blog.csdn.net/u013288190/article/details/104318276
2. 如果連接的是非TLS的peer節點(TLS也可以理解爲https還是http的意思),則需要修改peer的URL協議(grpcs->grpc)和端口(9051->9050),然後刪除tls_cacerts。根據這個值,應用程序決定是採用TLS或者非TLS錄像訪問hyperledger網絡。
3. 下面貼出一份本文完整的配置文件以作參考
{
"network-config": {
"org1": {
"name": "peerOrg1",
"mspid": "Org1MSP",
"peer1": {
"requests": "grpc://127.0.0.1:7051",
"events": "grpc://127.0.0.1:7053",
"server-hostname": "peer0.org1.example.com",
"tls_cacerts":
"/home/fabric/fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
},
"admin": {
"key":
"/home/fabric/fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore",
"cert":
"/home/fabric/fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts"
}
}
},
"channel": "composerchannel",
"pg": {
"host": "127.0.0.1",
"port": "5432",
"database": "fabricexplorer",
"username": "hppoc",
"passwd": "password"
},
"orderers": [
{
"mspid": "OrdererMSP",
"server-hostname": "orderer.example.com",
"requests": "grpc://127.0.0.1:7050",
"tls_cacerts":
"/home/fabric/fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt"
}
],
"host":"localhost",
"port":"8081",
"keyValueStore": "/tmp/fabric-client-kvs",
"configtxgenToolPath": "/home/fabric/fabric-tools/fabric-scripts/hyperledger-fabric-linux-amd64-1.4.0/bin",
"SYNC_START_DATE_FORMAT": "YYYY/MM/DD",
"syncStartDate": "2018/01/01",
"eventWaitTime": "30000",
"license": "Apache-2.0",
"version": "1.1"
}
六、編譯blockchain explore的代碼
cd blockchain-explorer-0.3.5.1
npm install
cd blockchain-explorer-0.3.5.1/app/test
npm install
npm run test
cd blockchain-explorer-0.3.5.1/client/
npm install
npm test -- -u --coverage
npm run build
以上沒有錯誤證明搭建完成
七、運行 Hyperledger Explorer
cd blockchain-explorer-0.3.5.1/
// 開啓後臺執行
./start.sh
// http://localhost:8080 查看結果.
//關閉
./stop.sh
效果
參考文章
https://www.dazhuanlan.com/2019/10/16/5da70ea150386/