部署流程
本次选用的Hyperledger-explorer版本为最新的release版本v0.3.9.1
github地址: https://github.com/hyperledger/blockchain-explorer
这里没有写如何部署Fabric网络 以及 连接Fabric提供的例子: first-nework
, 后面可以考虑分享,直接使用的例子网上也蛮多的,提供几个参考链接:
https://medium.com/@thanawitsupinnapong/setting-up-hyperledger-explorer-on-fabric-5f1f7cda73b3
https://medium.com/coinmonks/hyperledger-explorer-quick-start-50a49c6d7957
这篇文章主要介绍安装环境,部署运行,及我的一些踩坑记录,有一些我也还没有解决,如果你解决过,感恩你跟我分享❤。如果你有遇到其他的问题,也欢迎评论。
一、安装环境
安装要求说明:
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/]
我的环境:
# 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 的工作需要调用 curl,zlib,openssl,expat,libiconv 等库的代码,所以需要先安装这些依赖工具。在有 yum 的系统上(比如 Fedora),可以用下面的命令安装:
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install gcc perl-ExtUtils-MakeMaker
步骤2. 下载&解压: 之后,从下面的 Git 官方站点下载最新版本源代码
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. 安装并添加环境变量
# 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
- 暂停服务(可选)
systemctl enable postgresql
- 修改配置
/var/lib/pgsql/data/pg_hba.conf
信任指定服务器连接
将:
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
- 开启远程访问
vi /var/lib/pgsql/data/postgresql.conf
修改#listen_addresses = 'localhost' 为 listen_addresses='*'
当然,此处‘*’也可以改为任何你想开放的服务器IP
- 重启PostgreSQL数据服务
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
二、开始部署
准备代码和工具:
我们需要的工具
➜ bin git:(bb39b6e) ✗ pwd
/fabric-samples/bin # 部署Fabric网络的时候生成的,在配置config.json的时候会用到: "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
把证书密钥等相关内容copy到本地,我这里是放到/data/fabric/crypto-config/
配置config.json
的时候需要使用。
[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. 设置数据库
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/文件赋予权限 当前目录blockchain-explorer/
chmod -R 775 app/persistence/fabric/postgreSQL/db
执行数据库脚本
//切换到postgres,在安装postgresql的过程中就会默认创建postgres用户
sudo su - postgres
cd /data/fabric/blockchain-explorer-0.3.9.1/app/persistence/fabric/postgreSQL/db
./createdb.sh
查看创建数据
//退出postgres用户
exit
//连接psql \l 查看数据 \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
当前目录blockchain-explorer/
vim app/platform/fabric/config.json
修改内容
- 所有grpcs 改为
grpc
- tlsEnable 从true 改为false //第1.2步都是因为连接的Fabric网络禁用了Tls,如果使用first-network默认是不禁用的,就不用改。
- 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. 访问服务
默认访问链接是:http://localhost:8080
如果8080被占用,想要修改端口号,可以修改/blockchain-explorer/appconfig.json
{
"host": "localhost",
"port": "8080", # 修改端口号
"license": "Apache-2.0"
}
image.png
也可以通过右上角开关切换颜色:
image.png
三、 那些我踩到的坑
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
image.png解决方案:
yum install -y gcc-c++
3.2. mlocate 未安装
报错:
[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
image.png
解决:
> 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
报错:
(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. 配置了两个节点,但是只显示了一个节点 - 未解決
3.6. Error: 2 UNKNOWN: Stream removed - 未解決
报错信息如下,这个网上说有可能是grpc版本的问题,但是我替换了几个grpc版本还是不行,而这在我另一台服务器上是没有问题的,所以我猜测很可能还是环境问题,具体的是哪个有问题,网上找了下也没有答案。
➜ 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时,报的错误是:UNKNOWN: Stream removed
把grpc版本降到1.7.1
之后报的错误是这个。而在我另一台服务器上,grpc版本是1.14.2的时候,是可以正常使用的,所以也不太清楚具体是什么原因。
<<<<<<<<<<<<<<<<<<<<<<<<<< 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节点url配置的是远程服务的地址,但是日志里面还是显示访问 grpc://localhost:7050 - 未解决
因为本地没有order服务,所以这个问题没解决,目前是通过部署在Orderer服务上暂时启动了这个服务, 部署在orderer服务器上后,把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"
}
}
},
...
网友评论