Hyperledger Fabric project builds blockchain browser
1. Download the configuration file
Blockchain browser website: https://github.com/hyperledger/blockchain-explorer
# 根据官网来部署
# 在项目目录创建文件夹
# org1部署区块浏览器
mkdir explorer
cd explorer
# 下载配置文件
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
# 如果虚拟机没有联网,导致下载不下来,可以在官网点击三个配置文件,自己创建相对应名称,复制并保存,
# config.json与docker-compose.yaml直接放在explorer文件夹下,
# 但注意test-network.json,需要先新建connection-profile文件夹,然后将test-network.json放入connection-profile文件夹内
2. Copy the certificate directory
mkdir organizations
cp -r ../crypto-config/* organizations
cd explorer
At this point, the directory structure is shown in the figure below
3. Take two organizations, each with a peer node as an example, to modify the configuration file
3.1 Modify test-network.json - network configuration file, including identity specification
# 先修改test-network.json文件为org1-network.json
mv test-network.json org1-network.json
# 进入修改org1-network.json中对应参数
vim org1-network.json
# 修改证书连接文件
# 将用户的证书替换为连接配置文件 (test-network.json) 中的管理员证书和机密(私钥)
修改前
"adminPrivateKey": {
"path": "/tmp/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/priv_sk"
}
修改后,将[email protected]改为[email protected]
"adminPrivateKey": {
"path": "/tmp/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/priv_sk"
}
# 修改完毕保存退出
# 拷贝一份并命名为org2-network.json
cp org1-network.json org2-network.json
# 修改org2-network.json中对应参数
vim org2-network.json
#将所有的Org1修改文Org2,如下所示
Org1MSP -----> Org2MSP,org1 -----> org2
# 修改完毕保存退出
#或者使用sed
sed -i "s/org1/org2/g" org2-network.json
sed -i "s/Org1/Org2/g" org2-network.json
3.2. Modify config.json - multi-network configuration file
# config.json文件内只配置了一个组织的网络,所以需要添加第二个组织网络
vim config.json
# 修改为以下配置
{
"network-configs": {
"org1-network": {
// 需要和org1-network.json中的名称对应
"name": "org1-network",
"profile": "./connection-profile/org1-network.json" // 对应配置文件
},
"org2-network": {
// 需要和org2-network.json中的名称对应
"name": "org2-network",
"profile": "./connection-profile/org2-network.json" // 对应配置文件
}
},
"license": "Apache-2.0"
}
# 修改完毕后退出
3.3 Modify docker-compose - deployment configuration file
First find the name of the network used by the fabric, run the blockchain project, and then enter docker network ls to find the blockchain network
docker network ls
then enter
vim docker-compose.yaml
The modified docker-compose.yaml is as follows:
version: '2.1'
volumes:
pgdata:
walletstore:
networks:
mynetwork.com:
external:
name: multinodes_default # 修改为自己的fabric网络
services:
explorerdb.mynetwork.com:
image: hyperledger/explorer-db:latest
container_name: explorerdb.mynetwork.com
hostname: explorerdb.mynetwork.com
ports: # 暴露端口
- 5432:5432
restart: always # 增加重启参数
environment:
- DATABASE_DATABASE=fabricexplorer # db 库
- DATABASE_USERNAME=exploreradmin # db 账户
- DATABASE_PASSWORD=exploreradminpw # db 密码
healthcheck:
test: "pg_isready -h localhost -p 5432 -q -U postgres"
interval: 30s
timeout: 10s
retries: 5
volumes:
- pgdata:/var/lib/postgresql/data
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime # 与本机时间保持一致
- /etc/hosts:/etc/hosts # 映射hosts文件,否则会连接不了其它节点,或者添加extra_hosts参数
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 # 与上方db 库、账号、密码保持一致
- DATABASE_USERNAME=exploreradmin
- DATABASE_PASSWD=exploreradminpw
- LOG_LEVEL_APP=info
- LOG_LEVEL_DB=info
- LOG_LEVEL_CONSOLE=debug
- LOG_CONSOLE_STDOUT=true
# 浏览器是否开启远程访问, true表示只有部署的机器可以访问
- DISCOVERY_AS_LOCALHOST=false
volumes:
- ./config.json:/opt/explorer/app/platform/fabric/config.json
- ./connection-profile:/opt/explorer/app/platform/fabric/connection-profile
- ../crypto-config:/tmp/crypto # 映射证书目录
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
- /etc/hosts:/etc/hosts
- walletstore:/opt/explorer/wallet
ports:
- 8080:8080
restart: always
depends_on:
explorerdb.mynetwork.com:
condition: service_healthy
networks:
- mynetwork.com
4. Start the blockchain browser
docker-compose -f docker-compose.yaml up -d
# 如果是第一次启动,他会自动拉取浏览器镜像
# 如果虚拟机没有网络的话需要提前在外网拉取好explorer-db与explorer,然后导入到相应虚机
docker pull hyperledger/explorer-db:latest
docker pull hyperledger/explorer:latest
docker ps
#结果应该如下所示
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
72d7227b1306 hyperledger/explorer:latest "docker-entrypoint.s…" 39 seconds ago Up 3 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp explorer.mynetwork.com
5ac9b1f927cb hyperledger/explorer-db:latest "docker-entrypoint.s…" 39 seconds ago Up 36 seconds (healthy) 5432/tcp explorerdb.mynetwork.com
6735ebc7baf2 hyperledger/fabric-orderer:2.4.2 "orderer" 22 hours ago Up 48 minutes 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp orderer.example.com
To close the blockchain browser, you need to enter in the explorer path
docker-compose down -v(此处-v不能去掉,因为删除持久化数据才能在下一次启动区块链浏览器时启动成功)
5. Access the blockchain browser
You can directly enter localhost:8080 in the browser in the virtual machine to access the blockchain browser, or you can enter the virtual machine (server) ip: 8080 (need to open the port) in the host machine to access
explorer account: exploreradmin
explorer password: exploreradminpw
After logging in, you can view blockchain network, block and transaction information.
6. Configuration files of multiple peer nodes in the organization
If the project is a network with two peer nodes in the organization, if you want to configure the configuration file of this network, you only need to add peer1 to all the positions where peer0 appears in org1-network.json. In the same way, just add a few more peers, as shown below
{
"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": {
},
//加上peer1
"peer1.org1.example.com": {
}
},
"connection": {
"timeout": {
"peer": {
"endorser": "6000",
"eventHub": "6000",
"eventReg": "6000"
}
}
}
}
},
"organizations": {
"Org1MSP": {
"mspid": "Org1MSP",
"adminPrivateKey": {
"path": "/tmp/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/priv_sk"
},
//加上peer1
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
"signedCert": {
"path": "/tmp/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]"
}
}
},
"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"
},
//加上peer1
"peer1.org1.example.com": {
"tlsCACerts": {
"path": "/tmp/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt"
},
"url": "grpcs://peer1.org1.example.com:9051"
}
}
}