博主最近在搭建Hyperledger Fabric区块链浏览器过程中也学习了很多博主的搭建流程,踩了很多雷,踩了很多
坑,现将成功搭建好的Hyperledger Fabric区块链浏览器详细流程分享如下,帮助大家避雷闭坑
fabric浏览器
Hyperledger Explorer 是一个简单,强大,易于使用,维护良好的开源实用程序,可浏览底层区块链网络上的活
动。用户可以在MacOS和Ubuntu上配置和构建Hyperledger Explorer。先要保证你之前项目已成功启动。
搭建Hyperledger Fabric区块链浏览器前提
1. 成功搭建部署好Hyperledger Fabric 2.4(2.x)网络
搭建目录结构
在 hyperledger 目录下 新建同级目录 explorer
然后进入 test-network 目录下启动网络 启动Fabric网络
./network.sh up createChannel -ca -s couchdb
将启动成功网络后生成的证书文件夹 organizations 复制到前面新建的 explorer 文件夹中
然后下载如下如下三个配置文件(官方推荐) 但是因为网络原因很难下载下来
docker-compose.yaml
config.json
test-network.json
wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/config.json
wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/connection-profile/test-network.json -P connection-profile
wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/docker-compose.yaml
所以推荐大家先把官方的区块链项目下载下来,然后将需要的三个配置文件放进 explorer 文件夹中
官方区块链浏览器项目地址 https://github.com/hyperledger-labs/blockchain-explorer
这里需要将 test-network.json 文件 放在 connection-profile 目录下,其它均在 explorer 目录中的同级目录下
至此启动区块链浏览器需要的完整目录结构如下:
docker-compose.yaml
config.json
connection-profile/test-network.json
organizations/ordererOrganizations/
organizations/peerOrganizations/
虚拟机中的目录结构图如下:
修改三个配置文件
找到docker网络
docker network ls
我们可以看到 本区块链浏览器的docker网络为 fabric_test 后面在修改配置文件的时候需要修改
config.json
{
"network-configs": {
"test-network": {
"name": "fabric_test",
"profile": "./connection-profile/test-network.json"
}
},
"license": "Apache-2.0"
}
test-network.json
{
"name": "fabric_test",
"version": "1.0.0",
"client": {
"tlsEnable": true,
"adminCredential": {
"id": "hhhh",
"password": "123456"
},
"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/Admin@org1.example.com/msp/keystore/priv_sk"
},
"peers": ["peer0.org1.example.com"],
"signedCert": {
"path": "/tmp/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@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"
}
}
}
docker-compose.yaml
# SPDX-License-Identifier: Apache-2.0
version: '2.1'
volumes:
pgdata:
walletstore:
networks:
mynetwork.com:
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
- PORT=${PORT:-8080}
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
ports:
- ${PORT:-8080}:${PORT:-8080}
depends_on:
explorerdb.mynetwork.com:
condition: service_healthy
networks:
- mynetwork.com
启动浏览器
依次执行如下命令
假如之前启动过 先停用镜像
sudo docker-compose down
在 docker-compose.yaml 中为持久性数据(Postgres 数据和用户钱包)分配了两个命名卷。如果要清除这些命名卷
sudo docker-compose down -v
一定要设置好下面三个环境变量,不然启动浏览器会报错!!!!!!!
export EXPLORER_CONFIG_FILE_PATH=./config.json
export EXPLORER_PROFILE_DIR_PATH=./connection-profile
export FABRIC_CRYPTO_PATH=./organizations
最后启动区块链浏览器
sudo docker-compose up -d
打开浏览器输入
http://127.0.0.1:8080
成功启动浏览器
默认登录名、密码如下
"id": exploreradmin
"password": exploreradminpw
也可以在 test-network.json 文件中修改登录名和密码
"adminCredential": {
},
出现如下界面表示启动成功 登录进入后可以看到fabric 浏览器详细信息:区块信息、通道信息、节点信息等等
发表评论