Hyperledger Explorer 区块链浏览器与已搭建fabric网络结合

折腾了一下午,终于吧Hyperledger Explorer与现有的fabric网络结合起来。其实也挺简单,主要是踩了权限的坑。

Hyperledger Explorer介绍

hyperledger explorer主要是为Hyperledger的区块链网络搭建可视化的环境,可以通过浏览器查看网络中的信息,包括网络拓扑、区块信息、链码信息等等。 现在支持 fabric 和cello。
本文是在fabric v1.1版本以及explorer 3.5版本下的部署,操作系统为CentOS 7。
源码地址:
https://github.com/hyperledger/blockchain-explorer
依赖:

  • nodejs 8.11.x
  • PostgreSQL 9.5 or greater [https://www.postgresql.org/]
  • Jq [https://stedolan.github.io/jq/]
  • docker 17.06.2-ce [https://www.docker.com/community-edition]
  • docker-compose 1.14.0 [https://docs.docker.com/compose/]

部署过程

下载explorer代码并切换到3.5版本

  • git clone https://github.com/hyperledger/blockchain-explorer.git.
  • git checkout -b release-3.5 origin/release-3.5

数据库设置

  • cd blockchain-explorer.
  • cd blockchain-explorer/app/persistence/postgreSQL/db
  • 更改pgconfig.json文件,可以自己定义,后续脚本会生成对应用户
    "pg": {
                "host": "127.0.0.1",
                "port": "5432",
                "database": "fabricexplorer",
                "username": "hppoc",
                "passwd": "password"
        }
  • 更改脚本权限 chmod -R 775 ./*
  • 创建用户 ./createdb.sh
  • 连接数据库 sudo -u postgres psql

Fabric 网络部署

根据已经部署好的fabric网络更改配置文件:
blockchain-explorer/app/platform/fabric/config.json

{
  "network-config": {
    "org1": {
      "name": "GylOrg1MSP",
      "mspid": "GylOrg1MSP",
      "peer1": {
        "requests": "grpcs://10.254.186.164:7051",
        "events": "grpcs://10.254.186.164:7053",
        "server-hostname": "peer0.org1.gyl.com",
        "tls_cacerts":
          "/home/dc2-user/kongli/gyl/certs/peerOrganizations/org1.gyl.com/peers/peer0.org1.gyl.com/tls/ca.crt"
      },
      "admin": {
        "key":
          "/home/dc2-user/kongli/gyl/certs/peerOrganizations/org1.gyl.com/users/[email protected]/msp/keystore",
        "cert":
          "/home/dc2-user/kongli/gyl/certs/peerOrganizations/org1.gyl.com/users/[email protected]/msp/signcerts"
      }
    },
      "org3": {
      "name": "GylOrg3MSP",
      "mspid": "GylOrg1MSP",
      "peer1": {
        "requests": "grpcs://10.254.207.154:7051",
        "events": "grpcs://10.254.207.154:7053",
        "server-hostname": "peer0.org3.gyl.com",
        "tls_cacerts":
          "/home/dc2-user/kongli/gyl/certs/peerOrganizations/org3.gyl.com/peers/peer0.org3.gyl.com/tls/ca.crt"
      },
      "admin": {
        "key":
          "/home/dc2-user/kongli/gyl/certs/peerOrganizations/org3.gyl.com/users/[email protected]/msp/keystore",
        "cert":
          "/home/dc2-user/kongli/gyl/certs/peerOrganizations/org3.gyl.com/users/[email protected]/msp/signcerts"
      }
    },
    "org2": {
      "name": "GylOrg2MSP",
      "mspid": "GylOrg2MSP",
      "peer1": {
        "requests": "grpcs://10.254.247.165:7051",
        "events": "grpcs://10.254.247.165:7053",
        "server-hostname": "peer0.org2.gyl.com",
        "tls_cacerts":
          "/home/dc2-user/kongli/gyl/certs/peerOrganizations/org2.gyl.com/peers/peer0.org2.gyl.com/tls/ca.crt"
      },
      "admin": {
        "key":
          "/home/dc2-user/kongli/gyl/certs/peerOrganizations/org2.gyl.com/users/[email protected]/msp/keystore",
        "cert":
          "/home/dc2-user/kongli/gyl/certs/peerOrganizations/org2.gyl.com/users/[email protected]/msp/signcerts"
      }
    }
  },
  "channel": "gylchannel",
  "orderers": [
    {
      "mspid": "OrdererMSP",
      "server-hostname": "orderer.gyl.com",
      "requests": "grpcs://10.254.186.164:7050",
      "tls_cacerts":
        "/home/dc2-user/kongli/gyl/certs/ordererOrganizations/gyl.com/orderers/orderer.gyl.com/tls/ca.crt"
    }
  ],
  "keyValueStore": "/tmp/fabric-client-kvs",
  "configtxgenToolPath": "/user/bin",
  "SYNC_START_DATE_FORMAT": "YYYY/MM/DD",
  "syncStartDate": "2018/11/01",
  "eventWaitTime": "30000",
  "license": "Apache-2.0",
  "version": "1.1"
}

构建Hyperledger Explorer

  • 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

以上没有错误证明搭建完成

运行 Hyperledger Explorer

  • cd blockchain-explorer/
  • ./start.sh (开启后台执行).
  • http://localhost:8080 查看结果.
  • ./stop.sh (关闭).
  • logs 文件夹下可以查看日志

效果

在这里插入图片描述

遇到的问题

  • locate: 无法执行 stat () `/var/lib/mlocate/mlocate.db': 没有那个文件或目录
    由于locate没装导致或者没启动错误,sudo yum install mlocate 安装且使用sudo updatedb执行更新。
  • db error { error: Ident authentication failed for user "postgres"
    权限问题,需要吧blockchain-explorer下载在非当前用户文件夹下,比如/tmp。
  • 执行createdb.sh的时候报错:could not change directory to "/home/dc2-user/kongli/blockchain-explorer/app/persistence/postgreSQL/db": 权限不够
    原因同上。

你可能感兴趣的:(Hyperledger Explorer 区块链浏览器与已搭建fabric网络结合)