Fabric区块链浏览器搭建

目录

    • 一、创建区块链浏览器相关目录
    • 二、配置docker-compose
    • 三、配置区块链浏览器
    • 四、启动区块链浏览器

书接这一回 Fabric二进制建链,在建好链之后,将为这条链部署一个区块链浏览器。

  • Hyperledger Fabric区块链浏览器地址:https://github.com/hyperledger-labs/blockchain-explorer

一、创建区块链浏览器相关目录

mkdir -p /home/songzehao/fabric/explorer/connection-profile

二、配置docker-compose

vim /home/songzehao/fabric/explorer/docker-compose.yaml

内容如下:

# SPDX-License-Identifier: Apache-2.0
version: '2.1'
​
volumes:
  pgdata:
  walletstore:
​
networks:
  mynetwork.com:
    external: false
    name: fabric_dev
​
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:
      - ./config.json:/opt/explorer/app/platform/fabric/config.json
      - ./connection-profile:/opt/explorer/app/platform/fabric/connection-profile
      - /home/songzehao/fabric/organizations:/tmp/crypto
      - walletstore:/opt/explorer/wallet
    ports:
      - ${PORT:-8080}:${PORT:-8080}
    depends_on:
      explorerdb.mynetwork.com:
        condition: service_healthy
    networks:
      - mynetwork.com

三、配置区块链浏览器

创建配置文件config.json

vim /home/songzehao/fabric/explorer/config.json

内容如下:

{
    "network-configs": {
        "fabric_dev": {
            "name": "Fabric for dev",
            "profile": "./connection-profile/fabric_dev.json"
        }
    },
    "license": "Apache-2.0"
}

继续配置节点证书相关fabric_dev.json

vim /home/songzehao/fabric/explorer/connection-profile/fabric_dev.json

内容如下:

{
    "name": "fabric_dev",
    "version": "1.0.0",
    "client": {
        "tlsEnable": true,
        "adminCredential": {
            "id": "exploreradmin",
            "password": "exploreradminpw"
        },
        "enableAuthentication": false,
        "organization": "Org1MSP",
        "connection": {
            "timeout": {
                "peer": {
                    "endorser": "300"
                },
                "orderer": "300"
            }
        }
    },
    "channels": {
        "channel1": {
            "peers": {
                "peer0.org1.example.com": {}
            }
        }
    },
    "organizations": {
        "Org1MSP": {
            "mspid": "Org1MSP",
            "adminPrivateKey": {
                "path": "/tmp/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/6ac25f833930b9ac48f4598ccc2f0b3c30868296accfd0bf6ca4d27082c1cfea_sk"
            },
            "peers": ["peer0.org1.example.com"],
            "signedCert": {
                "path": "/tmp/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/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://192.168.3.128:7051"
        }
    }
}

最终的目录:

/home/songzehao/fabric/explorer
├── config.json
├── connection-profile
│   └── fabric_dev.json
└── docker-compose.yaml
​
1 directory, 3 files

四、启动区块链浏览器

$ cd /home/songzehao/fabric/explorer && docker-compose -f docker-compose.yaml up -d
Creating network "fabric_dev" with the default driver
Creating explorerdb.mynetwork.com ... done
Creating explorer.mynetwork.com   ... done

启动完成,查看docker容器:

$ docker ps
CONTAINER ID   IMAGE                                            COMMAND                  CREATED          STATUS                    PORTS                                       NAMES
431be406c069   ghcr.io/hyperledger-labs/explorer:latest         "docker-entrypoint.s…"   27 seconds ago   Up 26 seconds             0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   explorer.mynetwork.com
59bc641d507e   ghcr.io/hyperledger-labs/explorer-db:latest      "docker-entrypoint.s…"   58 seconds ago   Up 57 seconds (healthy)   5432/tcp                                    explorerdb.mynetwork.com

打开区块链浏览器地址http://192.168.3.128:8080
Fabric区块链浏览器搭建_第1张图片

你可能感兴趣的:(区块链,fabric,区块链,Hyperledger,区块链浏览器)