返回

Hyperledger Explorer(三)

区块链浏览器

  • 可以在浏览器上观察整个区块链上的块数、节点数、通道、链码,用于浏览底层区块链网络上的活动
  • 安装方式有两种:
    1. docker
    2. 下载代码到本地
  • 项目地址

配置

  1. 拉取blockchain-explorer配置文件到本地explorer-twonodes文件夹下
1
2
3
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
  1. 复制twonodes网络中保存证书的文件夹crypto-configexplorer-twonodes文件夹下,文件夹改名为与官方一致organizations
  2. 由于twonodes网络中有两个组织,所以在connection-profile文件夹下新增一个json文件,一个json文件对应一个组织
  • org1-network.json
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{
    "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": {}
            },
            "connection":{
                "timeout":{
                    "peer":{
                        "endorser":"6000",
                        "eventHub":"6000",
                        "eventReg":"6000"
                    }
                }
            }
        }
    },
    "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"
        }
    }
}

org2-network.json

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{
    "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.example.com": {}
            },
            "connection":{
                "timeout":{
                    "peer":{
                        "endorser":"6000",
                        "eventHub":"6000",
                        "eventReg":"6000"
                    }
                }
            }
        }
    },
    "organizations": {
        "Org2MSP": {
            "mspid": "Org2MSP",
            "adminPrivateKey": {
                "path": "/tmp/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/priv_sk"
            },
            "peers": ["peer0.org2.example.com"],
            "signedCert": {
                "path": "/tmp/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts/Admin@org2.example.com-cert.pem"
            }
        }
    },
    "peers": {
        "peer0.org2.example.com": {
            "tlsCACerts": {
                "path": "/tmp/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
            },
            "url": "grpcs://peer0.org2.example.com:9051"
        }
    }
}
  1. 配置config.json文件
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
    "network-configs": {
        "org1-network": {
            "name": "org1-network",
            "profile": "./connection-profile/org1-network.json"
        },
        "org2-network": {
            "name": "org2-network",
            "profile": "./connection-profile/org2-network.json"
        }
    },
    "license": "Apache-2.0"
}
  1. 配置docker-compose文件,修改网络名和挂载目录即可
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

# SPDX-License-Identifier: Apache-2.0
version: '2.1'

volumes:
  pgdata:
  walletstore:

networks:
  mynetwork.com:
    name: twonodes_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=debug
      - LOG_LEVEL_DB=debug
      - 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

启动

  1. 进入twonodes目录启动区块链网络
1
docker-compose up -d
  1. 进入explorer-twonodes启动区块链浏览器,第一次启动的话,会自动拉起浏览器的docker镜像
1
docker-compose up -d

  1. 访问127.0.0.1:8080,用户名和密码在org1-network.json配置文件中

BUG1

登录org1-network只能看到peer0.org1.example.comorderer.example.com:7050,登录org1-network只能看到peer0.org2.example.comorderer.example.com:7050

解决:检查过配置文件、网络问题、修改过本地hosts文件使节点可以在本地互相感知到,都没有解决该BUG

2023.01.05 可能是更新锚节点步骤的问题,建议按照官方文档重新搭建一遍网络

2023.01.06 可能是Clash问题,改成direct试试

BUG2

1
【ERROR】 main - Error :  【  'Default client peer is down and no channel details available database'

解决:之前执行过docker volume prunechannel证书给删除了,所以实际异常根据日志是channel连接不上。重新加入通道、安装链码、调用链码即可

关闭

1
docker-compose down -v
Built with Hugo
Theme Stack designed by Jimmy