安装和使用 blockchain explorer 浏览器 - 文章教程

安装和使用 blockchain explorer 浏览器

发布于 2021-03-23 字数 5569 浏览 1215 评论 0

https://github.com/hyperledger/blockchain-explorer

先启动 Fabric,可以参考 Fabric 的 BYFN

安装 mysql:

apt install mysql-server

安装时会要求输入密码,默认用户名是 root。

克隆 explorer 源码:

git clone https://github.com/hyperledger/blockchain-explorer.git
cd blockchain-explorer

用exploer的sql对mysql进行初始化:

mysql -u root -p < db/fabricexplorer.sql

连接 BYFN 的配置文件

blockchain-explorer 安装目录是 ~/blockchain-explorer,blockchain-explorer 自带了一个 BYFN(first-network目录下)。 配置 config.json:

{
    "network-config": {
                "org1": {
                        "name": "peerOrg1",
                        "mspid": "Org1MSP",
                        "peer1": {
                                "requests": "grpcs://127.0.0.1:7051",
                                "events": "grpcs://127.0.0.1:7053",
                                "server-hostname": "peer0.org1.example.com",
                                "tls_cacerts": "./first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
                        },
                        "admin": {
                                "key": "./first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore",
                                "cert": "./first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts"
                        }
                }
        },
   "host":"localhost",
   "port":"8081",
   "channel": "mychannel",
   "GOPATH":"../artifacts",
   "keyValueStore":"/tmp/fabric-client-kvs",
   "eventWaitTime":"30000",
   "mysql":{
      "host":"127.0.0.1",
      "port":"3306",
      "database":"fabricexplorer",
      "username":"root",
      "passwd":"1"
   }
}

连接 Composer 开发环境(fabric-tools)的配置文件

fabric-tools的安装目录是~/fabric-tools,blockchain-explorer的安装目录是~/blockchain-explorer
config.json:

{
    "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": "../fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
                        },
                        "admin": {
                                "key": "../fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore",
                                "cert": "../fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts"
                        }
                }
        },
   "host":"localhost",
   "port":"8081",
   "channel": "composerchannel",
   "GOPATH":"../artifacts",
   "keyValueStore":"/tmp/fabric-client-kvs",
   "eventWaitTime":"30000",
   "mysql":{
      "host":"127.0.0.1",
      "port":"3306",
      "database":"fabricexplorer",
      "username":"root",
      "passwd":"1"
   }
}

曾经发现报告错误(原因是grpc://写成了grpcs://):

E0113 02:41:26.907444268   29526 ssl_transport_security.cc:976] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.

注意fabric-toolsfirst-network的差异。前者使用grpc,后者使用grpcs;前者通道名是composerchannel,后者通道名是mychannel

构建和启动 blockchain-explorer

npm install
./start.sh

环境是 ubuntu 虚拟机,宿主机是 windows,虚拟机管理是vagrant。要在windows下访问blockchain-explorer,需要用NAT将虚拟机的8081端口映射到windows。所以在Vagrantfile中增加了配置:

config.vm.network :forwarded_port, guest: 8081, host: 8081, id: "blockchain-explorer", host_ip: "localhost", auto_correct: true # blockchain-explorer

修改了vagrant配置后需要重新启动虚拟机新端口映射才能生效。然后,重新启动BYFN和blockchain-explorer。然后在浏览器中访问地址127.0.0.1:8081就是看到blockchain-explorer界面了。

停止 blockchain-explorer

从start.sh中看到,blockchain-explorer是通过执行node main.js的方式启动的。那么查看一下node相关进程:

$ ps -ef | grep node
root      7718     1  3 Jan08 pts/2    01:13:26 node main.js
root     10620 10602  3 00:32 ?        00:20:58 peer node start --peer-defaultchain=false
ubuntu   12652  2099  0 07:32 pts/0    00:00:36 node /usr/local/bin/composer-playground
root     15036 14825  0 11:39 pts/3    00:00:00 grep --color=auto node

第一个进程就是blockchain-explorer的进程,则:

kill 7718

重启 blockchain-explorer

当fabric重启后,原来的区块可能删除了。这时需要重新初始化blockchain-explorer:

mysql -u root -p < db/fabricexplorer.sql

然后发现blockchain-explorer就可以显示最新的区块信息了。

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!

关于作者

JSmiles

生命进入颠沛而奔忙的本质状态,并将以不断告别和相遇的陈旧方式继续下去。

2583 文章
29 评论
84935 人气
更多

推荐作者

清风夜微凉

文章 1 评论 0

为你鎻心

文章 2 评论 0

xxhui

文章 0 评论 0

1PKOH46yx8j0x

文章 0 评论 0

Arthur

文章 0 评论 0