Fabric1.4 在自己项目中安装区块链浏览器blockchain-explorer

Posted 杰西啊杰西

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Fabric1.4 在自己项目中安装区块链浏览器blockchain-explorer相关的知识,希望对你有一定的参考价值。

说在前面
由于项目时间不够了,所以这里直接安装现成的区块链浏览器,就不自己解析区块了,有时间再说
有两种使用方法,一种是采用docker镜像法,一种是本地安装数据库法,我使用的是docker镜像法
参考博客:https://www.freesion.com/article/58421254477/

上一篇:(四)Fabric1.4 Fabric-SDK-go及web应用

一、官方文档

官方文档yyds
https://github.com/hyperledger/blockchain-explorer

二、进入项目部署

1、在项目路径下新建文件夹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

2、由于需要区块链网络的那几个crypto文件,所以要不然copy,要不然建立软连接,这里我选择建立软连接(也就是建立快捷文件organizations)

ln -s /root/go/src/PerInfoChain/crypto-config organizations

3、添加.env文件,用来标识使用网络,docker网络可以使用命令docker network ls查看
.env文件

NETWORK=perinfo_network

4、根据自己的网络修改docker-compose.yaml文件


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

volumes:
  pgdata:
  walletstore:

networks:
  perinfo.com:
  external:
    name:  $NETWORK

services:

  explorerdb.perinfo.com:
    image: hyperledger/explorer-db:latest
    container_name: explorerdb.perinfo.com
    hostname: explorerdb.perinfo.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:
      - perinfo.com

  explorer.perinfo.com:
    image: hyperledger/explorer:latest
    container_name: explorer.perinfo.com
    hostname: explorer.perinfo.com
    environment:
      - DATABASE_HOST=explorerdb.perinfo.com
      - DATABASE_DATABASE=fabricexplorer
      - DATABASE_USERNAME=hppoc
      - DATABASE_PASSWD=password
      - LOG_LEVEL_APP=debug
      - LOG_LEVEL_DB=debug
      - LOG_LEVEL_CONSOLE=info
      - LOG_CONSOLE_STDOUT=true
      - DISCOVERY_AS_LOCALHOST=false
      #- DISCOVERY_AS_LOCALHOST=true
    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.perinfo.com:
        condition: service_healthy
    networks:
      - perinfo.com
    extra_hosts: #添加单机地址映射(私网),不然启动时找不到地址 
      - "orderer.perinfo.com:172.20.43.188"
      - "peer0.org1.perinfo.com:172.20.43.188"
      - "peer0.org2.perinfo.com:172.20.43.188"
      - "peer0.org3.perinfo.com:172.20.43.188"
      - "peer0.org4.perinfo.com:172.20.43.188"
      - "ca.org1.perinfo.com:172.20.43.188"
      - "ca.org2.perinfo.com:172.20.43.188"
      - "ca.org3.perinfo.com:172.20.43.188"
      - "ca.org4.perinfo.com:172.20.43.188"

5、编写config.json文件
(证书我删了一部分,看看自己的)


	"network-configs": 
		"perinfo_network": 
			"name": "perinfo_network",
			"profile": "./connection-profile/connection.json"
		
	,
	"license": "Apache-2.0"

6、进入connection-profile文件夹,复制一份test.network.json文件,根据自己网络进行配置


	"name": "perinfo_network",
	"version": "1.0.0",
	"client": 
		"tlsEnable": true,
		"caCredential": 
			"id": "admin",
			"password": "perinfo68"
		,
		"adminCredential": 
			"id": "exploreradmin",
			"password": "perinfo68"
		,
		"enableAuthentication": true,
		"organization": "Org1MSP",
		"connection": 
			"timeout": 
				"peer": 
					"endorser": "300"
				,
				"orderer": "300"
			
		
	,
	"channels": 
		"perinfo-channel": 
			"peers": 
				"peer0.org1.perinfo.com": 
			,
			"connection": 
				"timeout": 
					"peer": 
						"endorser": "6000",
						"eventHub": "6000",
						"eventReg": "6000"
					
				
			
		
	,
	"organizations": 
		"Org1MSP": 
			"mspid": "Org1MSP",
			"adminPrivateKey": 
				"path": "/tmp/crypto/peerOrganizations/org1.perinfo.com/users/Admin@org1.perinfo.com/msp/keystore/852200768328b80f1eb06934d00fae5b86678aa0f188ce0733d850c480d54308_sk"
			,
			"peers": ["peer0.org1.perinfo.com"],
			"certificateAuthorities": ["ca-org1"],
			"signedCert": 
				"path": "/tmp/crypto/peerOrganizations/org1.perinfo.com/users/Admin@org1.perinfo.com/msp/signcerts/Admin@org1.perinfo.com-cert.pem"
			
		,
		"Org2MSP": 
			"mspid": "Org2MSP",
			"adminPrivateKey": 
				"path": "/tmp/crypto/peerOrganizations/org2.perinfo.com/users/Admin@org2.perinfo.com/msp/keystore/0a41f9ad4a34d7f604f1e74b1283a3a09ae7f1135002499487dce2e844ae3d28_sk"
			,
			"peers": ["peer0.org2.perinfo.com"],
			"certificateAuthorities": ["ca-org2"],
			"signedCert": 
				"path": "/tmp/crypto/peerOrganizations/org2.perinfo.com/users/Admin@org2.perinfo.com/msp/signcerts/Admin@org2.perinfo.com-cert.pem"
			
		,
		"Org3MSP": 
			"mspid": "Org3MSP",
			"adminPrivateKey": 
				"path": "/tmp/crypto/peerOrganizations/org3.perinfo.com/users/Admin@org3.perinfo.com/msp/keystore/f74c115383c4360c69652d6a1196a35bc2f91d84d9082d4de456ce11e3e735ea_sk"
			,
			"peers": ["peer0.org3.perinfo.com"],
			"certificateAuthorities": ["ca-org3"],
			"signedCert": 
				"path": "/tmp/crypto/peerOrganizations/org3.perinfo.com/users/Admin@org3.perinfo.com/msp/signcerts/Admin@org3.perinfo.com-cert.pem"
			
		,
		"Org4MSP": 
			"mspid": "Org4MSP",
			"adminPrivateKey": 
				"path": "/tmp/crypto/peerOrganizations/org4.perinfo.com/users/Admin@org4.perinfo.com/msp/keystore/e2f986b66bf77cdabea4fd5e72a46c0646ef50dbef8a236e9864f2a7109b2144_sk"
			,
			"peers": ["peer0.org4.perinfo.com"],
			"certificateAuthorities": ["ca-org4"],
			"signedCert": 
				"path": "/tmp/crypto/peerOrganizations/org4.perinfo.com/users/Admin@org4.perinfo.com/msp/signcerts/Admin@org4.perinfo.com-cert.pem"
			
		

	,
	"peers": 
		"peer0.org1.perinfo.com": 
			"tlsCACerts": 
				"path": "/tmp/crypto/peerOrganizations/org1.perinfo.com/peers/peer0.org1.perinfo.com/tls/ca.crt",
				"pem": "-----BEGIN CERTIFICATE-----\\nMIICWDCCAf6gAwIBAgIRAOAfz3HS3UT20/LRS07ATXIwCgYIKoZIzj0EAwIwdjEL\\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\\ncmFuY2lzY28xGTAXBgNVBAoTEG9yZzEucGVyaW5mby5jb20xHzAdBgNVBAMTFnRs\\nc2NhLm9yZzEucGVyaW5mby5jb20wHhcNMjEwODExMTMyNzAwWhcNMzEwODA5MTMy\\nNzAwWjB2MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UE\\nBxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5wZXJpbmZvLmNvbTEfMB0G\\nA1UEAxMWdGxzY2Eub3JnMS5wZXJpbmZvLmNvbTBZMBMGByqGgYIKoZIzj0E\\nAwIDSAAwRQIhAKuB+yF6CgIksETlBlvZBqcj83aX9c3owbqyi0kEC6jBAiAwrX88\\nClTqUhJf3PDFusjVbMhfyXWqkkp8gHX9059CPQ==\\n-----END CERTIFICATE-----\\n"
			,
			"url": "grpcs://peer0.org1.perinfo.com:7051",
			"eventUrl": "grpcs://peer0.org1.perinfo.com:7053",
			"grpcOptions": 
				"ssl-target-name-override": "peer0.org1.perinfo.com"
			
		,
		"peer0.org2.perinfo.com": 
			"tlsCACerts": 
				"path": "/tmp/crypto/peerOrganizations/org2.perinfo.com/peers/peer0.org2.perinfo.com/tls/ca.crt",
				"pem": "-----BEGIN CERTIFICATE-----\\nMIICVzCCAf6gAwIBAgIRAKb+gdfgKw6iIMevIMkd56YwCgYIKoZIzj0EAwIwdjEL\\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\\ncmFuY2lzY28xGTAXBgNVBAoTEG9yZzIucGVyaW5mby5jb20xHzAdBgNVBAMTFnRs\\nc2NhLm9yZzIucGVyaW5mby5jb20wHhcNMjEwODExMTMyNzAwWhcNMzEwODA5MTMy\\nNzAwWjB2MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UE\\nBxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UE+Juy4P9LyFyLKMbiDuO6kVbKoxnTDETQF1sigbnkwCgYIKoZIzj0E\\nAwIDRwAwRAIgWTHazKzW6MicpBLAg5D+XWRLX1PUZrMP/q1WeifDiAICIHdq2MMJ\\nY44QJ8bDmnvMZ6tUIxPrKRsXeRBNgNX/kG4v\\n-----END CERTIFICATE-----\\n"
			,
			"url": "grpcs://peer0.org2.perinfo.com:8051",
			"eventUrl": "grpcs://peer0.org2.perinfo.com:8053",
			"grpcOptions": 
				"ssl-target-name-override": "peer0.org2.perinfo.com"
			
		,
		"peer0.org3.perinfo.com": 
			"tlsCACerts": 
				"path": "/tmp/crypto/peerOrganizations/org3.perinfo.com/peers/peer0.org3.perinfo.com/tls/ca.crt",
				"pem": "-----BEGIN CERTIFICATE-----\\nMIICVjCCAf2gAwIBAgIQI9D7Mo3txDa8Mj3J/P4h3DAKBggqhkjOPQQDAjB2MQsw\\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMy5wZXJpbmZvLmNvbTEfMB0GA1UEAxMWdGxz\\nY2Eub3JnMy5wZXJpbmZvLmNvbTAeFw0yMTA4MTExMzI3MDBaFw0zMTA4MDkxMzI3\\nMDBaMHYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH\\nEw1TYW4gRnJhbmNpc2NvMRkwFwYDVQQKExBvcmczLnBlcmluZm8uY29tMR8wHQYD\\nVQQDExZ0bHNjzbXYmif5p1wQRrOEAOnuqdqWIUI95FlELwGNjAKBggqhkjOPQQD\\nAgNHADBEAiAmY+3p5lSuVtaRRSrrRbQT5dyoxnHKYfelw/b/l15sgwIgeQuxOtOX\\niL/rBEqSDSTAi58nePSAPeDiz8cj2+UDDC0=\\n-----END CERTIFICATE-----\\n"
			,
			"url": "grpcs://peer0.org3.perinfo.com:9051",
			"eventUrl": "grpcs://peer0.org3.perinfo.com:9053",
			"grpcOptions": 
				"ssl-target-name-override": "peer0.org3.perinfo.com"
			
		,
		"peer0.org4.perinfo.com": 
			"tlsCACerts": 
				"path": "/tmp/crypto/peerOrganizations/org4.perinfo.com/peers/peer0.org4.perinfo.com/tls/ca.crt",
				"pem": "-----BEGIN CERTIFICATE-----\\nMIICVzCCAf2gAwIBAgIQb/GbYQgpzga1aROLDijX/TAKBggqhkjOPQQDAjB2MQsw\\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\\nYW5jaXNjbzEZMBcGA1UEChMQb3JnNC5wZXJpbmZvLmNvbTEfMB0GA1UEAxMWdGxz\\nY2Eub3JnNC5wZXJpbmZvLmNvbTAeFw0yMTA4MTExMzI3MDBaFw0zMTA4MDkxMzI3\\nMDBaMHYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH\\nEw1TYW4gRnJhbmNpc2NvMRkwFwYDVQQKExBvcmc0LnBlcmluZm8uY29tMR8wHQYD\\nVQQDExZ0bHNjYS5vcmc0LnBlcmluZm8uY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0D\\nAQcDQgAEoSNT5FRHwNRBvxa1DTAURYO08L+zKr1irPx3uPKK8lA8CIGopM6RB\\nfri5fsSrbN5RUSkpgpbfX4Oyhz69fMZGEO2N\\n-----END CERTIFICATE-----\\n"
			,
			"url": "grpcs://peer0.org4.perinfo.com:10051",
			"eventUrl": "grpcs://peer0.org4.perinfo.com:10053",
			"grpcOptions": 
				"ssl-target-name-override": "peer0.org4.perinfo.com"
			
		
	,
	"certificateAuthorities": 
		"ca-org1": 
			"url": "https://ca.org1.perinfo.com:7054",
			"caName": "ca-org1",
			"tlsCACerts": 
				"path": "/tmp/crypto/peerOrganizations/org1.perinfo.com/ca/ca.org1.perinfo.com-cert.pem"
			,
			"httpOptions": 
				"verify": false
			
		,
		"ca-org2": 
			"url": "https://ca.org2.perinfo.com:8054",
			"caName": "ca-org2",
			"tlsCACerts": 
				"path": "/tmp/crypto/peerOrganizations/org2.perinfo.com/ca/ca.org2.perinfo.com-cert.pem"
			,
			"httpOptions": 
				"verify": false
			
		,
		"ca-org3": 
			"url": "https://ca.org3.perinfo.com:9054",
			"caName": "ca-org3",
			"tlsCACerts": 
				"path": "/tmp/crypto/peerOrganizations/org3.perinfo.com/ca/ca.org3.perinfo.com-cert.pem"
			,
			"httpOptions": 
				"verify": false
			
		,
		"ca-org4": 
			"url": "https://ca.org4.perinfo.com:10054",
			"caName": "ca-org4",
			"tlsCACerts": 
				"path": "/tmp/crypto/peerOrganizations/org4.perinfo.com/ca/ca.org4.perinfo.com-cert.pem"
			,
			"httpOptions": 
				"verify": false
			
		
	


7、启动网络

docker-compose up

可以看到自己的网络信息了

8、另起终端关闭网络

docker-compose down

三、遇到的问题及解决方法

重新启动区块链浏览器时,会报channel已经存在的错误,这里清理docker环境即可
清理blockchain-explorer的docker环境:https://www.cnblogs.com/xwxz/p/14277840.html

番外篇:(六)beego连接docker mysql

以上是关于Fabric1.4 在自己项目中安装区块链浏览器blockchain-explorer的主要内容,如果未能解决你的问题,请参考以下文章

复现区块链Fabric1.4项目记录安装配置centos8虚拟机

Fabric1.4 搭建区块链网络

Fabric1.4.1视频教程即将推出

Fabric1.4 Fabric-SDK-go及web应用

区块链项目开发区块链影响社交媒体

Hyperledger Fabric - 如何在每次区块链网络测试后清除 DEV 环境?