Hyperleder explorer 部署

该篇文档的前提是已经存在部署好的fabric网络, 并且在peer节点有运行的自定义链码

Explorer 区块链浏览器部署

区块链网络部署(前提)

在部署 Explorer项目前提前要有存在的区块链网络,这里说一下区块链网络部署时应该注意点的点

  1. 在区块链网络中启动操作服务器

    如果要使用区块链监控,在启动网络的时候应该加上如下环境变量

    1
    2
    3
    4
    - ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:8443  # operation RESTful API
    - ORDERER_METRICS_PROVIDER=prometheus # prometheus will pull metrics from orderer via /metrics RESTful API
    - CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:9443 # operation RESTful API
    - CORE_METRICS_PROVIDER=prometheus # prometheus will pull metrics from orderer via /metrics RESTful API
  2. 务必开启gossip

    开启gossip, 使区块链网络开启发现服务

    1
    2
    - CORE_PEER_GOSSIP_BOOTSTRAP=X.X.X.X:XXXX
    - CORE_PEER_GOSSIP_EXTERNALENDPOINT=X.X.X.X:XXXX

项目拉取

1
2
git clone https://github.com/hyperledger/blockchain-explorer.git
cd blockchain-explorer

安装数据库

配置prostgreSQL数据库

  1. 第一种配置方法

    cd blockchain-explorer/app 修改 explorerconfig.json

1
2
3
4
5
6
7
"postgreSQL": {
"host": "127.0.0.1",
"port": "5432",
"database": "fabricexplorer",
"username": "hppoc",
"passwd": "password"
}
  1. 第二种配置方法
1
2
3
4
5
export DATABASE_HOST=127.0.0.1
export DATABASE_PORT=5432
export DATABASE_DATABASE=fabricexplorer
export DATABASE_USERNAME=hppoc
export DATABASE_PASSWD=pass12345

给执行sql脚本的目录带执行权限

1
chomd -R 775 /blockchain-explorer/app/persistence/fabric/postgreSQL/db

执行数据库脚本

1
2
cd blockchain-explorer/app/persistence/fabric/postgreSQL/db
sudo -u postgres ./createdb.sh

配置身份认证

配置jwt

​ cd blockchain-explorer/app 修改explorerconfig.json 文件

1
2
3
4
"jwt": {
"secret" : "a secret phrase!!", # 用来签名payload的密钥
"expiresIn": "2 days" # token 过期时间 Eg: 60, "2 days", "10h", "7d".
}

配置explorer 链接到区块链网络

配置 explorer 链接区块链网络

  1. 配置网络文件位置: /blockchain-explorer/app/platform/fabric/config.json

  2. 配置链接文件位置: /blockchain-explorer/app/platform/fabric/connection-profile

配置 prometheus 链接到操作服务器

​ 1. 配置文件位置: app/platform/fabric/artifacts/operations/balance-transfer/prometheus.yml

安装并配置 grafana

  1. 配置文件位置: app/platform/fabric/artifacts/operations/balance-transfer/balance-transfer-grafana-dashboard.json
  2. 配置文件位置: app/platform/fabric/artifacts/operations/grafana_conf/provisioning/dashboards/dashboard.yaml
  3. 配置文件位置: app/platform/fabric/artifacts/operations/grafana_conf/provisioning/datasources/datasource.yaml

Build Explorer 项目

1
2
./main.sh clean
./main.sh install

运行Explorer项目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd blockchain-explorer/app  修改explorerconfig.json 同步频率 主机类型 区块同步时间的详细配置

# 普通方式运行和停止
cd blockchain-explorer/
./start.sh (it will have the backend up).
./start.sh debug (it will have the backend in debug mode).
./start.sh print (it will print help).
Launch the URL http(s)://localhost:8080 on a browser.
./stop.sh (it will stop the node server).

# Sync方式运行和停止
cd blockchain-explorer/
./syncstart.sh (it will have the sync node up).
./syncstop.sh (it will stop the sync node).

Explorer Docker 部署

前提:

  1. bash
  2. Docker
  3. Docker Compose

仓库地址:

区块链网络部署(前提)

在部署 Explorer项目前提前要有存在的区块链网络,这里说一下区块链网络部署时应该注意点的点

  1. 在区块链网络中启动操作服务器

    如果要使用区块链监控,在启动网络的时候应该加上如下环境变量

    1
    2
    3
    4
    - ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:8443  # operation RESTful API
    - ORDERER_METRICS_PROVIDER=prometheus # prometheus will pull metrics from orderer via /metrics RESTful API
    - CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:9443 # operation RESTful API
    - CORE_METRICS_PROVIDER=prometheus # prometheus will pull metrics from orderer via /metrics RESTful API
  2. 务必开启gossip

    开启gossip, 使区块链网络开启发现服务

    1
    2
    - CORE_PEER_GOSSIP_BOOTSTRAP=X.X.X.X:XXXX
    - CORE_PEER_GOSSIP_EXTERNALENDPOINT=X.X.X.X:XXXX

Explorer项目拉取

1
2
git clone https://github.com/hyperledger/blockchain-explorer.git
cd blockchain-explorer

配置Explorer

配置explorer和fabric网络的连接

参考配置文件位置:

  • examples/net1/config.json 连接的主配置文件
  • examples/net1/connection-profile 和 fabric 的连接配置
  • examples/net1/crypto 网络传输加密文件目录(如果有的话)

配置 prometheus

参考配置文件位置:

app/platform/fabric/artifacts/operations/balance-transfer/prometheus.yml

配置 grafana

参考配置文件位置:

app/platform/fabric/artifacts/operations/balance-transfer/balance-transfer-grafana-dashboard.json 一个dashboard的详细配置

app/platform/fabric/artifacts/operations/grafana_conf/provisioning/dashboards/dashboard.yaml dashboard的存储目录等基本配置

app/platform/fabric/artifacts/operations/grafana_conf/provisioning/datasources/datasource.yaml 数据源的配置

配置docker-compose 文件

配置网络

配置网络,可以指定已经存在的网络,如果和区块链网络在同一台机器上可以使用区块链网络

如果和区块链网络是分开部署的,可以指定一个其他的任意网络

1
2
3
4
networks:
mynetwork.com:
external:
name: net_byfn

配置数据库

1
2
3
4
5
6
7
environment:     # 配置数据库名称,用户密码等
- DATABASE_DATABASE=fabricexplorer
- DATABASE_USERNAME=hppoc
- DATABASE_PASSWORD=password
volumes: # 配置数据库创建监本位置; 配置数据库持久化的位置
- ./app/persistence/fabric/postgreSQL/db/createdb.sh:/docker-entrypoint-initdb.d/createdb.sh
- pgdata:/var/lib/postgresql/data

配置 explorer

1
2
3
4
5
6
7
8
9
10
environment:
- DATABASE_HOST=explorerdb.mynetwork.com # 连接的数据库配置
- DATABASE_USERNAME=hppoc
- DATABASE_PASSWD=password
- DISCOVERY_AS_LOCALHOST=false # 如果是通过桥接的方式连接到区块链浏览器,务必设置为false
volumes: # 引用的配置文件位置配置
- ./examples/net1/config.json:/opt/explorer/app/platform/fabric/config.json
- ./examples/net1/connection-profile:/opt/explorer/app/platform/fabric/connection-profile
- ./examples/net1/crypto:/tmp/crypto
- walletstore:/opt/wallet

配置 prometheus

1
2
3
volumes:
- ./app/platform/fabric/artifacts/operations/balance-transfer/prometheus.yml:/etc/prometheus/prometheus.yml # 引用的配置文件位置
- prometheus-storage:/prometheus # prometheus数据持久化的位置

配置 grafana

1
2
3
4
volumes:  # 配置引用配置文件的位置,以及数据持久化的文职
- ./app/platform/fabric/artifacts/operations/balance-transfer/balance-transfer-grafana-dashboard.json:/var/lib/grafana/dashboards/mydashboard.json
- ./app/platform/fabric/artifacts/operations/grafana_conf/provisioning:/etc/grafana/provisioning
- grafana-storage:/var/lib/grafana

docker-compose.yaml 文件的示例

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
59
60
61
62
63
64
65
66
67
68
69
70
version: '2.1'

volumes:
pgdata:
walletstore:
grafana-storage:
prometheus-storage:

networks:
mynetwork.com:
external:
name: net_byfn

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
volumes:
- ./app/persistence/fabric/postgreSQL/db/createdb.sh:/docker-entrypoint-initdb.d/createdb.sh
- 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_USERNAME=hppoc
- DATABASE_PASSWD=password
- DISCOVERY_AS_LOCALHOST=false
volumes:
- ./examples/net1/config.json:/opt/explorer/app/platform/fabric/config.json
- ./examples/net1/connection-profile:/opt/explorer/app/platform/fabric/connection-profile
- ./examples/net1/crypto:/tmp/crypto
- walletstore:/opt/wallet
command: sh -c "sleep 16&& node /opt/explorer/main.js && tail -f /dev/null"
ports:
- 8090:8080
networks:
- mynetwork.com

proms:
container_name: proms
image: prom/prometheus:latest
volumes:
- ./app/platform/fabric/artifacts/operations/balance-transfer/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus-storage:/prometheus
ports:
- '9090:9090'
networks:
- mynetwork.com

grafana:
container_name: grafana
image: grafana/grafana:latest
volumes:
- ./app/platform/fabric/artifacts/operations/balance-transfer/balance-transfer-grafana-dashboard.json:/var/lib/grafana/dashboards/mydashboard.json
- ./app/platform/fabric/artifacts/operations/grafana_conf/provisioning:/etc/grafana/provisioning
- grafana-storage:/var/lib/grafana
ports:
- '3000:3000'
networks:
- mynetwork.com

启动网络

1
docker-compose up -d
刘小恺(Kyle) wechat
如有疑问可联系博主