部署流程
本次選用的Hyperledger-explorer版本為最新的release版本v0.3.9.1
github地址: https://github.com/hyperledger/blockchain-explorer
這里沒有寫如何部署Fabric網(wǎng)絡(luò) 以及 連接Fabric提供的例子: first-nework
, 后面可以考慮分享,直接使用的例子網(wǎng)上也蠻多的清寇,提供幾個(gè)參考鏈接:
https://medium.com/@thanawitsupinnapong/setting-up-hyperledger-explorer-on-fabric-5f1f7cda73b3
https://medium.com/coinmonks/hyperledger-explorer-quick-start-50a49c6d7957
這篇文章主要介紹安裝環(huán)境喘漏,部署運(yùn)行护蝶,及我的一些踩坑記錄华烟,有一些我也還沒有解決,如果你解決過持灰,感恩你跟我分享?盔夜。如果你有遇到其他的問題,也歡迎評論。
一喂链、安裝環(huán)境
安裝要求說明:
Requirements
The following are prerequisites for installing the required development tools.
nodejs 8.11.x (Note that v9.x is not yet supported)
PostgreSQL 9.5 or greater
Jq [https://stedolan.github.io/jq/]
Hyperledger Explorer works with Hyperledger Fabric 1.2. Install the following software dependencies to manage fabric network.
docker-ce [https://www.docker.com/community-edition]
docker-compose [https://docs.docker.com/compose/]
GO [https://golang.org/dl/]
我的環(huán)境:
# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
# node -v
v8.11.2
# npm -v
5.6.0
# git --version
git version 2.9.5
# jq --version
jq-1.5
# psql --version
psql (PostgreSQL) 9.2.24
那就按照要求安裝吧返十!
1. 安裝Git
步驟1. 安裝依賴包
Git 的工作需要調(diào)用 curl,zlib椭微,openssl洞坑,expat,libiconv 等庫的代碼蝇率,所以需要先安裝這些依賴工具迟杂。在有 yum 的系統(tǒng)上(比如 Fedora),可以用下面的命令安裝:
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install gcc perl-ExtUtils-MakeMaker
步驟2. 下載&解壓: 之后本慕,從下面的 Git 官方站點(diǎn)下載最新版本源代碼
cd /usr/src
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
tar -zxvf git-2.9.5.tar.gz
注意. 如果之前有安裝過舊版本git排拷,先刪除
yum remove git
步驟3. 安裝并添加環(huán)境變量
# cd git-2.9.5
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install
# vim /etc/profile
//添加一行
# export PATH=$PATH:/usr/local/git/bin
# source /etc/profile
步驟4. 查看git版本
# git --version
git version 2.9.5
2. 安裝nodejs
//1.下載
wget https://nodejs.org/download/release/v8.11.2/node-v8.11.2-linux-x64.tar.gz
//2.解壓
tar --strip-components 1 -xzvf node-v* -C /usr/local
//3.查看版本
# node –v
v8.11.2
3. 安裝PostgreSQL
- 安裝依賴
yum install postgresql-server postgresql-contrib
- 初始化DB
postgresql-setup initdb
- 啟動DB
systemctl start postgresql
- 暫停服務(wù)(可選)
systemctl enable postgresql
- 修改配置
/var/lib/pgsql/data/pg_hba.conf
信任指定服務(wù)器連接
將:
host all all 127.0.0.1/32 ident
修改為:
host all all 127.0.0.1/32 trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
后面增加
host all all 0.0.0.0/0 trust
- 開啟遠(yuǎn)程訪問
vi /var/lib/pgsql/data/postgresql.conf
修改#listen_addresses = 'localhost' 為 listen_addresses='*'
當(dāng)然,此處‘*’也可以改為任何你想開放的服務(wù)器IP
- 重啟PostgreSQL數(shù)據(jù)服務(wù)
systemctl restart postgresql
4. 安裝JQ
jq linux json格式化工具
1锅尘、添加epel源
>wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
>rpm -ivh epel-release-latest-7.noarch.rpm
>yum repolist
2监氢、安裝
yum install jq
- 查看版本
>jq --version
jq-1.5
二、開始部署
準(zhǔn)備代碼和工具:
我們需要的工具
? bin git:(bb39b6e) ? pwd
/fabric-samples/bin # 部署Fabric網(wǎng)絡(luò)的時(shí)候生成的藤违,在配置config.json的時(shí)候會用到: "configtxgenToolPath": "/data/fabric/bin", 把他都copy到需要使用的路徑下面浪腐,比如我這里是"/data/fabric/bin"
? bin git:(bb39b6e) ? tree
.
├── configtxgen
├── configtxlator
├── cryptogen
├── discover
├── fabric-ca-client
├── get-docker-images.sh
├── idemixgen
├── orderer
└── peer
把證書密鑰等相關(guān)內(nèi)容copy到本地,我這里是放到/data/fabric/crypto-config/
配置config.json
的時(shí)候需要使用纺弊。
[ansible@rocketmq-test-2 crypto-config]$ tree -L 3
.
├── ordererOrganizations
│ └── example.com
│ ├── ca
│ ├── msp
│ ├── orderers
│ ├── tlsca
│ └── users
└── peerOrganizations
├── org1.example.com
│ ├── ca
│ ├── msp
│ ├── peers
│ ├── tlsca
│ └── users
└── org2.example.com
├── ca
├── msp
├── peers
├── tlsca
└── users
2.1. 設(shè)置數(shù)據(jù)庫
vim blockchain-explorer/app/explorerconfig.json
你可以更新explorerconfig.json來更新postgresql的配置牛欢,我這邊先不改
{
"persistence": "postgreSQL",
"platforms": ["fabric"],
"postgreSQL": {
"host": "127.0.0.1",
"port": "5432",
"database": "fabricexplorer",
"username": "hppoc",
"passwd": "password"
},
"sync": {
"type": "local",
"platform": "fabric",
"blocksSyncTime": "3"
}
}
有些情況下,你需要給db/文件賦予權(quán)限 當(dāng)前目錄blockchain-explorer/
chmod -R 775 app/persistence/fabric/postgreSQL/db
執(zhí)行數(shù)據(jù)庫腳本
//切換到postgres淆游,在安裝postgresql的過程中就會默認(rèn)創(chuàng)建postgres用戶
sudo su - postgres
cd /data/fabric/blockchain-explorer-0.3.9.1/app/persistence/fabric/postgreSQL/db
./createdb.sh
查看創(chuàng)建數(shù)據(jù)
//退出postgres用戶
exit
//連接psql \l 查看數(shù)據(jù) \d 查看表格 \q退出
[ansible@rocketmq-test-2 blockchain-explorer-0.3.9.1]$ sudo -u postgres psql
psql (9.2.24)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
----------------+----------+----------+-------------+-------------+-----------------------
fabricexplorer | hppoc | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
嘗試連接成功
psql postgres://hppoc:password@127.0.0.1:5432/fabricexplorer
2.2. 修改配置文件config.json
當(dāng)前目錄blockchain-explorer/
vim app/platform/fabric/config.json
修改內(nèi)容
- 所有g(shù)rpcs 改為
grpc
- tlsEnable 從true 改為false //第1.2步都是因?yàn)檫B接的Fabric網(wǎng)絡(luò)禁用了Tls傍睹,如果使用first-network默認(rèn)是不禁用的,就不用改犹菱。
- path修改拾稳,修改成本地的證書密鑰路徑,我這里是
/data/fabric/crypto-config/
{
"network-configs": {
"network-1": {
"version": "1.0",
"clients": {
"client-1": {
"tlsEnable": false,
"organization": "Org1MSP",
"channel": "mychannel",
"credentialStore": {
"path": "./tmp/credentialStore_Org1/credential",
"cryptoStore": {
"path": "./tmp/credentialStore_Org1/crypto"
}
}
}
},
"channels": {
"mychannel": {
"peers": {
"peer0.org1.example.com": {}
},
"connection": {
"timeout": {
"peer": {
"endorser": "6000",
"eventHub": "6000",
"eventReg": "6000"
}
}
}
}
},
"organizations": {
"Org1MSP": {
"mspid": "Org1MSP",
"fullpath": false,
"adminPrivateKey": {
"path": "/data/fabric/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore"
},
"signedCert": {
"path": "/data/fabric/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts"
}
},
"OrdererMSP": {
"mspid": "OrdererMSP",
"adminPrivateKey": {
"path": "/data/fabric/crypto-config/ordererOrganizations/example.com/users/Admin@example.com/msp/keystore"
}
}
},
"peers": {
"peer0.org1.example.com": {
"tlsCACerts": {
"path": "/data/fabric/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
},
"url": "grpc://192.168.22.246:7051",
"eventUrl": "grpc://192.168.22.246:7053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com"
}
},
"peer0.org2.example.com": {
"url": "grpc://192.168.22.249:7051"
}
},
"orderers": {
"orderer.example.com": {
"url": "grpc://localhost:7050"
}
}
},
"network-2": {}
},
"configtxgenToolPath": "/data/fabric/bin",
"license": "Apache-2.0"
}
2.3. 編譯啟動
cd blockchain-explorer
npm install
cd blockchain-explorer/app/test
npm install
npm run test
cd client/
npm install
npm test -- -u --coverage
npm run build
2.4. 訪問服務(wù)
默認(rèn)訪問鏈接是:http://localhost:8080
如果8080被占用腊脱,想要修改端口號访得,可以修改/blockchain-explorer/appconfig.json
{
"host": "localhost",
"port": "8080", # 修改端口號
"license": "Apache-2.0"
}
也可以通過右上角開關(guān)切換顏色:
三、 那些我踩到的坑
3.1. gcc未安裝
make: Entering directory `/data/fabric/blockchain-explorer-0.3.9.1/node_modules/pkcs11js/build'
CXX(target) Release/obj.target/pkcs11/src/main.o
make: g++: Command not found
解決方案:
yum install -y gcc-c++
3.2. mlocate 未安裝
報(bào)錯:
[ansible@rocketmq-test-2 blockchain-explorer-0.3.9.1]$ tail -222f logs/console/console-2019-06-11.log
postgres://hppoc:password@127.0.0.1:5432/fabricexplorer
/bin/sh: locate: command not found
/bin/sh: locate: command not found
/bin/sh: locate: command not found
解決:
> yum install mlocate
> updatedb
注意:若用sudo install 那么updatedb 也需要用1sudo updatedb
測試:
> locate mysql
/usr/share/mysql/charsets/macce.xml
/usr/share/mysql/charsets/macroman.xml
/usr/share/mysql/charsets/swe7.xml
/usr/share/mysql/czech/errmsg.sys
/usr/share/mysql/danish/errmsg.sys
/usr/share/mysql/dutch/errmsg.sys
...
3.3. grpc未安裝
提示需要npm rebuild
解決方案:
npm rebuild
3.4. Fabric禁用tls,但是配置用了grpcs ,需要改為grpc
報(bào)錯:
(node:3648) DeprecationWarning: grpc.load: Use the @grpc/proto-loader module with grpc.loadPackageDefinition instead
E0606 06:13:02.106104472 3648 ssl_transport_security.cc:1227] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
E0606 06:13:03.106865936 3648 ssl_transport_security.cc:1227] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
E0606 06:13:04.647205386 3648 ssl_transport_security.cc:1227] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
2019-06-06T10:13:05.104Z - error: [Remote.js]: Error: Failed to connect before the deadline URL:grpcs://192.168.110.246:7051
2019-06-06T10:13:05.105Z - error: [Channel.js]: Error: Failed to connect before the deadline URL:grpcs://192.168.110.246:7051
<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
Error: Failed to discover ::Error: Failed to connect before the deadline URL:grpcs://192.168.110.246:7051
at Channel._initialize (/data/fabric/blockchain-explorer-0.3.9.1/node_modules/fabric-client/lib/Channel.js:347:11)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Received kill signal, shutting down gracefully
3.5. 配置了兩個(gè)節(jié)點(diǎn)陕凹,但是只顯示了一個(gè)節(jié)點(diǎn) - 未解決
3.6. Error: 2 UNKNOWN: Stream removed - 未解決
報(bào)錯信息如下悍抑,這個(gè)網(wǎng)上說有可能是grpc版本的問題,但是我替換了幾個(gè)grpc版本還是不行杜耙,而這在我另一臺服務(wù)器上是沒有問題的搜骡,所以我猜測很可能還是環(huán)境問題,具體的是哪個(gè)有問題佑女,網(wǎng)上找了下也沒有答案记靡。
? blockchain-explorer-0.3.9.1 tail -222f logs/console/console-2019-06-11.log
postgres://hppoc:password@127.0.0.1:5432/fabricexplorer
(node:20923) DeprecationWarning: grpc.load: Use the @grpc/proto-loader module with grpc.loadPackageDefinition instead
<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
{ Error: 2 UNKNOWN: Stream removed
at Object.exports.createStatusError (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/common.js:87:15)
at ClientDuplexStream._emitStatusIfDone (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client.js:235:26)
at ClientDuplexStream._receiveStatus (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client.js:213:8)
at Object.onReceiveStatus (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client_interceptors.js:1290:15)
at InterceptingListener._callNext (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client_interceptors.js:564:42)
at InterceptingListener.onReceiveStatus (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client_interceptors.js:614:8)
at /home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client_interceptors.js:1110:18
code: 2,
metadata: Metadata { _internal_repr: {} },
details: 'Stream removed' }
Received kill signal, shutting down gracefully
Closed out connections
3.7. TypeError: Channel's second argument must be a ChannelCredentials - 未解決
grpc版本是1.14.2時(shí)谈竿,報(bào)的錯誤是:UNKNOWN: Stream removed
把grpc版本降到1.7.1
之后報(bào)的錯誤是這個(gè)。而在我另一臺服務(wù)器上摸吠,grpc版本是1.14.2的時(shí)候空凸,是可以正常使用的,所以也不太清楚具體是什么原因寸痢。
<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
TypeError: Channel's second argument must be a ChannelCredentials
at ServiceClient.Client (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client.js:472:19)
at new ServiceClient (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client.js:884:12)
at new AdminPeer (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/app/platform/fabric/AdminPeer.js:65:30)
at FabricClient.newAdminPeer (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/app/platform/fabric/FabricClient.js:546:25)
at FabricClient.initializeChannelFromDiscover (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/app/platform/fabric/FabricClient.js:499:38)
at <anonymous>
Received kill signal, shutting down gracefully
Closed out connections
3.8. orderer節(jié)點(diǎn)url配置的是遠(yuǎn)程服務(wù)的地址呀洲,但是日志里面還是顯示訪問 grpc://localhost:7050 - 未解決
因?yàn)楸镜貨]有order服務(wù),所以這個(gè)問題沒解決啼止,目前是通過部署在Orderer服務(wù)上暫時(shí)啟動了這個(gè)服務(wù), 部署在orderer服務(wù)器上后两嘴,把url改為grpc://localhost:7050
是可以訪問的
我的Order url的配置是:
...
"peers": {
"peer0.org1.example.com": {
"tlsCACerts": {
"path": "/data/fabric/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
},
"url": "grpc://192.168.110.246:7051",
"eventUrl": "grpc://192.168.110.246:7053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com"
}
},
"peer0.org2.example.com": {
"url": "grpc://192.168.110.249:7051"
}
},
"orderers": {
"orderer.example.com": {
"url": "grpc://192.168.110.245:7050"
}
}
},
...