参考:https://github.com/hyperledger/blockchain-explorer
搭建方式有两种,一种是基于docker容器,一种是用代码库。
使用docker进行部署感觉方便很多。
- Docker
- Docker Compose
官方指导:Hyperledger Fabric official tutorial
这里默认你已经配置好了fabric测试网络。
3.1 从仓库获取配置文件
我这里直接在test-network 文件夹下面建立explorer文件夹:
mkdir explorer
有三个配置文件:
1.docker-compose.yaml
2.examples/net1/connection-profile/test-network.json
(如果是通过ca注册用户启动fabric网络,则需要这一个:examples/net1/connection-profile/test-network-ca.json)
3.examples/net1/config.json
三个文件参考:
blockchain-explorer搭建(Docker)_Demonwuwen的博客-CSDN博客_blockchain-explorer搭建方式有两种,一种是基于docker容器,一种是用代码库。使用docker进行部署感觉方便很多。一、使用docker部署1 准备条件:DockerDocker Compose2 启动fabric网络官方指导:Hyperledger Fabric official tutorial这里默认你已经配置好了fabric测试网络。3 配置文件3.1 从仓库获取配置文件我这里直接在test-network 文件夹下面建立explorer文件夹:mkdir explorer有三个.https://blog.csdn.net/weixin_44336181/article/details/117196701?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165063671116780366560611%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=165063671116780366560611&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-2-117196701.142^v9^pc_search_result_control_group,157^v4^control&utm_term=blockchain-explorer&spm=1018.2226.3001.4187我们在explorer文件夹中要有如下几个文件,把test-network中的organizations文件复制进来explorer,
docker-compose.yaml config.json connection-profile/test-network.json organizations/ordererOrganizations/ organizations/peerOrganizations/
3.3 修改docker-compose.yaml
networks:
mynetwork.com:
external:
name: net_test
...
services:
explorer.mynetwork.com:
...
volumes:
- ./config.json:/opt/explorer/app/platform/fabric/config.json
- ./connection-profile:/opt/explorer/app/platform/fabric/connection-profile
- ./organizations:/tmp/crypto
- walletstore:/opt/explorer/wallet
这儿的name不需要修改,我的是fabric_test,
如果explorer链接到fabric网络是通过bridge network(桥接模式),在environment中,DISCOVERY_AS_LOCALHOST=false
如果在后面遇到了端口冲突,也将8080:8080改为8090:8080,或者其他的与其对应即可。
修改后的docker- compose.yaml文件
# SPDX-License-Identifier: Apache-2.0
version: '2.1'
volumes:
pgdata:
walletstore:
networks:
mynetwork.com:
external:
name: fabric_test
services:
explorerdb.mynetwork.com:
image: hyperledger/explorer-db:latest
container_name: explorerdb.mynetwork.com
hostname: explorerdb.mynetwork.com
environment:
- DATABASE_DATABASE=fabricexplorer
- DATABASE_USERNAME=hppoc
- DATABASE_PASSWORD=password
healthcheck:
test: "pg_isready -h localhost -p 5432 -q -U postgres"
interval: 30s
timeout: 10s
retries: 5
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- mynetwork.com
explorer.mynetwork.com:
image: hyperledger/explorer:latest
container_name: explorer.mynetwork.com
hostname: explorer.mynetwork.com
environment:
- 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=false
volumes:
- ./config.json:/opt/explorer/app/platform/fabric/config.json
- ./connection-profile:/opt/explorer/app/platform/fabric/connection-profile
- ./organizations:/tmp/crypto
- walletstore:/opt/explorer/wallet
ports:
- 8080:8080
depends_on:
explorerdb.mynetwork.com:
condition: service_healthy
networks:
- mynetwork.com
3.4 修改connection profile文件夹下test-network.json
原先是:
"adminPrivateKey": {
"path": "/tmp/crypto/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/priv_sk"
}
修改后是:
"adminPrivateKey": {
"path": "/tmp/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/priv_sk"
}
注意priv_sk的名字,记得修改为和你对应文件夹的名字一样。如果你也是使用的ca证书,则不需要修改,直接使用原配置文件即可。
4 启动容器服务docker-compose up -d
如果需要清除容器,则使用命令
docker-compose down
如果需要清除容器和本地挂载的数据
docker-compose down -v5 访问使用explorer
在地址栏输入:http://localhost:8080/



