hyperledger fabric explorer 超级账本区块链浏览器搭建-使用docker的方式快速搭建一个超级账本区块链浏览器

  • 区块链浏览器可以让用户更加直观地查看当前超级账本网络的情况,来观察整个区块链上的块数,节点数,通道,链码等;

  • 官方推荐的搭建区块链浏览器有两种方法,一种是docker的方式,一种是用代码在自己本地的方式搭建,这里我们选择docker的方式搭建;

官方的github项目地址:

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

Quick start (using Docker)

1、配置文件

# 新建文件夹,用于存放区块链浏览器搭建过程中的配置文件mkdir explorercd explorer# wget配置文件,由于被墙,可能无法直接获取wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/config.jsonwget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/connection-profile/test-network.json -P connection-profilewget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/docker-compose.yaml# 解决方法,手动创建配置文件,并通过访问下面网址,将配置文件内容复制进去

2、将区块链网络的证书文件整个目录复制到 explorer下,并重命名为organizations:

cd /root/block/geneg/twonodes/cp -r crypto-config ../explorer/organizations

3、配置文件存放目录结构如下:

# 因为我们有两个peer节点,org1和org2explorer|___docker-compose.yaml|___config.json|___connection-profile |___org1-network.json |___org2-network.json
root@aa:~/block/geneg# cd /root/block/geneg/root@aa:~/block/geneg# pwd/root/block/genegroot@aa:~/block/geneg# lstwonodesroot@aa:~/block/geneg# mkdir explorerroot@aa:~/block/geneg# lsexplorertwonodesroot@aa:~/block/geneg# cd explorerroot@aa:~/block/geneg/explorer# mkdir connection-profileroot@aa:~/block/geneg/explorer# lsconnection-profile

(1)新文件:docker-compose.yaml,内容如下

​ https://github.com/hyperledger/blockchain-explorer/blob/main/docker-compose.yaml

networks:mynetwork.com:external:name: fabric_test# 这个地方要改成自己的网络名称
# 修改成自己的文件挂载路径volumes:- ${EXPLORER_CONFIG_FILE_PATH}:/opt/explorer/app/platform/fabric/config.json- ${EXPLORER_PROFILE_DIR_PATH}:/opt/explorer/app/platform/fabric/connection-profile- ${FABRIC_CRYPTO_PATH}:/tmp/crypto- walletstore:/opt/explorer/wallet# 后面又提到,先往后找一找
# SPDX-License-Identifier: Apache-2.0version: '2.1'volumes:pgdata:walletstore:networks:mynetwork.com:external:name: twonodes_testservices:explorerdb.mynetwork.com:image: hyperledger/explorer-db:latestcontainer_name: explorerdb.mynetwork.comhostname: explorerdb.mynetwork.comenvironment:- DATABASE_DATABASE=fabricexplorer- DATABASE_USERNAME=hppoc- DATABASE_PASSWORD=passwordhealthcheck:test: "pg_isready -h localhost -p 5432 -q -U postgres"interval: 30stimeout: 10sretries: 5volumes:- pgdata:/var/lib/postgresql/datanetworks:- mynetwork.comexplorer.mynetwork.com:image: hyperledger/explorer:latestcontainer_name: explorer.mynetwork.comhostname: explorer.mynetwork.comenvironment:- DATABASE_HOST=explorerdb.mynetwork.com- DATABASE_DATABASE=fabricexplorer- DATABASE_USERNAME=hppoc- DATABASE_PASSWD=password- LOG_LEVEL_APP=info- LOG_LEVEL_DB=info- LOG_LEVEL_CONSOLE=debug- LOG_CONSOLE_STDOUT=true- DISCOVERY_AS_LOCALHOST=falsevolumes:- ./config.json:/opt/explorer/app/platform/fabric/config.json- ./connection-profile:/opt/explorer/app/platform/fabric/connection-profile- ./organizations:/tmp/crypto- walletstore:/opt/explorer/walletports:- 8080:8080depends_on:explorerdb.mynetwork.com:condition: service_healthynetworks:- mynetwork.com

(2)新文件:org1-network.json,内容如下

​ https://github.com/hyperledger/blockchain-explorer/blob/main/examples/net1/connection-profile/test-network.json

“name”: “test-network”, 这一项可以自定义,但是在 config.json加载配置文件路径项

“profile”: “./connection-profile/test-network.json” 要对应上

{"name": "org1-network","version": "1.0.0","client": {"tlsEnable": true,"adminCredential": {"id": "exploreradmin","password": "exploreradminpw"},"enableAuthentication": true,"organization": "Org1MSP","connection": {"timeout": {"peer": {"endorser": "300"},"orderer": "300"}}},"channels": {"mychannel": {"peers": {"peer0.org1.example.com": {}}}},"organizations": {"Org1MSP": {"mspid": "Org1MSP","adminPrivateKey": {"path": "/tmp/crypto/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/priv_sk"},"peers": ["peer0.org1.example.com"],"signedCert": {"path": "/tmp/crypto/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/signcerts/User1@org1.example.com-cert.pem"}}},"peers": {"peer0.org1.example.com": {"tlsCACerts": {"path": "/tmp/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"},"url": "grpcs://peer0.org1.example.com:7051"}}}
# 这里的id和password为一会登录的账号和密码"adminCredential": {"id": "exploreradmin","password": "exploreradminpw"}

(3)新文件:org2-network.json,内容如下

{"name": "org2-network","version": "1.0.0","client": {"tlsEnable": true,"adminCredential": {"id": "exploreradmin","password": "exploreradminpw"},"enableAuthentication": true,"organization": "org2MSP","connection": {"timeout": {"peer": {"endorser": "300"},"orderer": "300"}}},"channels": {"mychannel": {"peers": {"peer0.org2.example.com": {}}}},"organizations": {"org2MSP": {"mspid": "org2MSP","adminPrivateKey": {"path": "/tmp/crypto/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/keystore/priv_sk"},"peers": ["peer0.org2.example.com"],"signedCert": {"path": "/tmp/crypto/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/signcerts/User1@org2.example.com-cert.pem"}}},"peers": {"peer0.org2.example.com": {"tlsCACerts": {"path": "/tmp/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"},"url": "grpcs://peer0.org2.example.com:7051"}}}

(4)新文件:config.json,内容如下

https://github.com/hyperledger/blockchain-explorer/blob/main/examples/net1/config.json

{"network-configs": {"org1-network": {"name": "org1-network","profile": "./connection-profile/org1-network.json"},"org2-network": {"name": "org2-network","profile": "./connection-profile/org2-network.json"}},"license": "Apache-2.0"}

4、docker-compose 跑起服务

root@kai:~/block/geneg# cd explorerroot@kai:~/block/geneg/explorer# pwd/root/block/geneg/explorerroot@kai:~/block/geneg/explorer# lsconfig.jsonconnection-profiledocker-compose.yamlorganizationsroot@kai:~/block/geneg/explorer# docker-compose up -dRecreating explorerdb.mynetwork.com ... doneCreating explorer.mynetwork.com ... doneroot@kai:~/block/geneg/explorer# docker ps -ahyperledger/explorer:latesthyperledger/explorer-db:latest

5、浏览器上访问:

云主机ip:8080账号 "exploreradmin",密码 "exploreradminpw"