最终环境说明: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

Hyperledger Fabric Composer安装blockchain explorer_HyperLedger

完成下载之后,目录结构为

Hyperledger Fabric Composer安装blockchain explorer_区块链_02

下载后解压的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验证是否启动成功

Hyperledger Fabric Composer安装blockchain explorer_HyperLedger_03

 

五、修改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/Admin@org1.example.com/msp/keystore",
        "cert":
          "/home/fabric/fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/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 

 

效果

Hyperledger Fabric Composer安装blockchain explorer_HyperLedger_04

Hyperledger Fabric Composer安装blockchain explorer_区块链_05

Hyperledger Fabric Composer安装blockchain explorer_区块链_06

 

参考文章

https://www.dazhuanlan.com/2019/10/16/5da70ea150386/

https://blog.csdn.net/oXiaoBuDing/article/details/84993251

https://blog.csdn.net/qq_36793353/article/details/79089911