三、Fabric2.4.6 浏览器(ubuntu 22.04)
2023-11-22 本文已影响0人
一介书生独醉江湖
二、Fabric2.4.6 手工搭建网络(ubuntu 22.04)
# nodejs
ds@ds-virtual-machine:~/explorer$ sudo apt install nodejs
ds@ds-virtual-machine:~/explorer$ nodejs --version
v12.22.9
# 创建浏览器目录
ds@ds-virtual-machine:~$ cd ~
ds@ds-virtual-machine:~$ mkdir explorer
ds@ds-virtual-machine:~$ 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
# 将区块链网络中的证书文件的整个目录复制到区块链浏览器的项目中,并修改名字为organizations;
# ../raft-test 是我搭建的fabric网络的目录
ds@ds-virtual-machine:~/explorer$ cp -r ../raft-test/crypto-config ./
ds@ds-virtual-machine:~/explorer$ mv crypto-config/ organizations
# 截止目前,目录的文件结构如下:
ds@ds-virtual-machine:~/explorer$ ls
config.json connection-profile docker-compose.yaml organizations
ds@ds-virtual-machine:~/explorer/connection-profile$ ls
test-network.json
ds@ds-virtual-machine:~/explorer/organizations$ ls
ordererOrganizations peerOrganizations
#修改网络配置-org1
sudo gedit connection-profile/org1-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.supervisor.com": {},
"peer1.org1.supervisor.com": {}
}
}
},
"organizations": {
"Org1MSP": {
"mspid": "Org1MSP",
"adminPrivateKey": {
"path": "/tmp/crypto/peerOrganizations/org1.supervisor.com/users/Admin@org1.supervisor.com/msp/keystore/priv_sk"
},
"peers": ["peer0.org1.supervisor.com","peer1.org1.supervisor.com"],
"signedCert": {
"path": "/tmp/crypto/peerOrganizations/org1.supervisor.com/users/Admin@org1.supervisor.com/msp/signcerts/Admin@org1.supervisor.com-cert.pem"
}
}
},
"peers": {
"peer0.org1.supervisor.com": {
"tlsCACerts": {
"path": "/tmp/crypto/peerOrganizations/org1.supervisor.com/msp/tlscacerts/tlsca.org1.supervisor.com-cert.pem"
},
"url": "grpcs://peer0.org1.supervisor.com:7051"
},
"peer1.org1.supervisor.com": {
"tlsCACerts": {
"path": "/tmp/crypto/peerOrganizations/org1.supervisor.com/msp/tlscacerts/tlsca.org1.supervisor.com-cert.pem"
},
"url": "grpcs://peer1.org1.supervisor.com:8051"
}
}
}
#修改网络配置-org2
sudo gedit connection-profile/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.build.com": {},
"peer1.org2.build.com": {}
}
}
},
"organizations": {
"Org2MSP": {
"mspid": "Org2MSP",
"adminPrivateKey": {
"path": "/tmp/crypto/peerOrganizations/org2.build.com/users/Admin@org2.build.com/msp/keystore/priv_sk"
},
"peers": ["peer0.org2.build.com","peer1.org2.build.com"],
"signedCert": {
"path": "/tmp/crypto/peerOrganizations/org2.build.com/users/Admin@org2.build.com/msp/signcerts/Admin@org2.build.com-cert.pem"
}
}
},
"peers": {
"peer0.org2.build.com": {
"tlsCACerts": {
"path": "/tmp/crypto/peerOrganizations/org2.build.com/msp/tlscacerts/tlsca.org2.build.com-cert.pem"
},
"url": "grpcs://peer0.org2.build.com:9051"
},
"peer1.org2.build.com": {
"tlsCACerts": {
"path": "/tmp/crypto/peerOrganizations/org2.build.com/msp/tlscacerts/tlsca.org2.build.com-cert.pem"
},
"url": "grpcs://peer1.org2.build.com:10051"
}
}
}
#修改网络配置-org3
sudo gedit connection-profile/org3-network.json
{
"name": "org3-network",
"version": "1.0.0",
"client": {
"tlsEnable": true,
"adminCredential": {
"id": "exploreradmin",
"password": "exploreradminpw"
},
"enableAuthentication": true,
"organization": "Org3MSP",
"connection": {
"timeout": {
"peer": {
"endorser": "300"
},
"orderer": "300"
}
}
},
"channels": {
"mychannel": {
"peers": {
"peer0.org3.supplier.com": {},
"peer1.org3.supplier.com": {}
}
}
},
"organizations": {
"Org3MSP": {
"mspid": "Org3MSP",
"adminPrivateKey": {
"path": "/tmp/crypto/peerOrganizations/org3.supplier.com/users/Admin@org3.supplier.com/msp/keystore/priv_sk"
},
"peers": ["peer0.org3.supplier.com","peer1.org3.supplier.com"],
"signedCert": {
"path": "/tmp/crypto/peerOrganizations/org3.supplier.com/users/Admin@org3.supplier.com/msp/signcerts/Admin@org3.supplier.com-cert.pem"
}
}
},
"peers": {
"peer0.org3.supplier.com": {
"tlsCACerts": {
"path": "/tmp/crypto/peerOrganizations/org3.supplier.com/msp/tlscacerts/tlsca.org3.supplier.com-cert.pem"
},
"url": "grpcs://peer0.org3.supplier.com:11051"
},
"peer1.org3.supplier.com": {
"tlsCACerts": {
"path": "/tmp/crypto/peerOrganizations/org3.supplier.com/msp/tlscacerts/tlsca.org3.supplier.com-cert.pem"
},
"url": "grpcs://peer1.org3.supplier.com:12051"
}
}
}
#修改网络配置-org4
sudo gedit connection-profile/org4-network.json
{
"name": "org4-network",
"version": "1.0.0",
"client": {
"tlsEnable": true,
"adminCredential": {
"id": "exploreradmin",
"password": "exploreradminpw"
},
"enableAuthentication": true,
"organization": "Org4MSP",
"connection": {
"timeout": {
"peer": {
"endorser": "300"
},
"orderer": "300"
}
}
},
"channels": {
"mychannel": {
"peers": {
"peer0.org4.logistics.com": {},
"peer1.org4.logistics.com": {}
}
}
},
"organizations": {
"Org4MSP": {
"mspid": "Org4MSP",
"adminPrivateKey": {
"path": "/tmp/crypto/peerOrganizations/org4.logistics.com/users/Admin@org4.logistics.com/msp/keystore/priv_sk"
},
"peers": ["peer0.org4.logistics.com","peer1.org4.logistics.com"],
"signedCert": {
"path": "/tmp/crypto/peerOrganizations/org4.logistics.com/users/Admin@org4.logistics.com/msp/signcerts/Admin@org4.logistics.com-cert.pem"
}
}
},
"peers": {
"peer0.org4.logistics.com": {
"tlsCACerts": {
"path": "/tmp/crypto/peerOrganizations/org4.logistics.com/msp/tlscacerts/tlsca.org4.logistics.com-cert.pem"
},
"url": "grpcs://peer0.org4.logistics.com:13051"
},
"peer1.org4.logistics.com": {
"tlsCACerts": {
"path": "/tmp/crypto/peerOrganizations/org4.logistics.com/msp/tlscacerts/tlsca.org4.logistics.com-cert.pem"
},
"url": "grpcs://peer1.org4.logistics.com:14051"
}
}
}
sudo gedit 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"
},
"org3-network": {
"name": "org3-network",
"profile": "./connection-profile/org3-network.json"
},
"org4-network": {
"name": "org4-network",
"profile": "./connection-profile/org4-network.json"
}
},
"license": "Apache-2.0"
}
sudo gedit docker-compose.yaml
# SPDX-License-Identifier: Apache-2.0
version: '2.1'
volumes:
pgdata:
walletstore:
networks:
mynetwork.com:
name: ordersFabric_test
services:
explorerdb.mynetwork.com:
image: ghcr.io/hyperledger-labs/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: ghcr.io/hyperledger-labs/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
# 设置环境变量
export EXPLORER_CONFIG_FILE_PATH=./config.json
export EXPLORER_PROFILE_DIR_PATH=./connection-profile
export FABRIC_CRYPTO_PATH=./organizations
# 启动
ds@ds-virtual-machine:~/explorer$ docker-compose up -d
浏览器访问:http://127.0.0.1:8080/#/login
账号密码在 org1.network.json等文件的adminCredential属性中(对应id和password)
image.png
# 浏览器
# git地址:https://gitee.com/baihu_shusheng/explorer.git
四、Fabric2.4.6 智能合约(java)(ubuntu 22.04)
参考:
https://github.com/hyperledger-labs/blockchain-explorer
https://www.bilibili.com/video/BV1yQ4y1Z7sJ/?spm_id_from=333.337.search-card.all.click&vd_source=ef83736476a46166544cd38458b6b130
https://blog.csdn.net/qq_45808700/article/details/130183648