Hyperledger Fabric项目搭建区块链浏览器Hyperledger-blockchain-explorer

Hyperledger Fabric项目搭建区块链浏览器

1.下载配置文件

区块链浏览器官网:https://github.com/hyperledger/blockchain-explorer

# 根据官网来部署
# 在项目目录创建文件夹
# org1部署区块浏览器
mkdir explorer
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
# 如果虚拟机没有联网,导致下载不下来,可以在官网点击三个配置文件,自己创建相对应名称,复制并保存,
# config.json与docker-compose.yaml直接放在explorer文件夹下,
# 但注意test-network.json,需要先新建connection-profile文件夹,然后将test-network.json放入connection-profile文件夹内

在这里插入图片描述
如果虚拟机没有联网,导致下载不下来,也可以前往Fabric-explorer附件下载进行下载,之后在本地根据需要修改,修改后上传到虚拟机

2.拷贝证书目录

mkdir organizations
cp -r ../crypto-config/* organizations
cd explorer

此时目录结构如下图所示
在这里插入图片描述

3.以两个组织,每个组织一个peer结点为例修改配置文件

3.1修改test-network.json—— 网络配置文件,包含身份的指定

# 先修改test-network.json文件为org1-network.json
mv test-network.json org1-network.json
# 进入修改org1-network.json中对应参数
vim org1-network.json
# 修改证书连接文件
# 将用户的证书替换为连接配置文件 (test-network.json) 中的管理员证书和机密(私钥)
修改前
"adminPrivateKey": {
    "path": "/tmp/crypto/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/priv_sk"
}
修改后,将User1@org1.example.com改为Admin@org1.example.com
"adminPrivateKey": {
    "path": "/tmp/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/priv_sk"
}
# 修改完毕保存退出

# 拷贝一份并命名为org2-network.json
cp org1-network.json org2-network.json
# 修改org2-network.json中对应参数
vim org2-network.json
#将所有的Org1修改文Org2,如下所示
Org1MSP -----> Org2MSP,org1 -----> org2
# 修改完毕保存退出
#或者使用sed
sed -i "s/org1/org2/g" org2-network.json
sed -i "s/Org1/Org2/g" org2-network.json

3.2.修改config.json——多网络配置文件

# config.json文件内只配置了一个组织的网络,所以需要添加第二个组织网络
vim config.json
# 修改为以下配置
{
        "network-configs": {
                "org1-network": {		// 需要和org1-network.json中的名称对应
                        "name": "org1-network",
                        "profile": "./connection-profile/org1-network.json"		// 对应配置文件
                },
                "org2-network": {		// 需要和org2-network.json中的名称对应
                        "name": "org2-network",
                        "profile": "./connection-profile/org2-network.json"		// 对应配置文件
                }
        },
        "license": "Apache-2.0"
}
# 修改完毕后退出

3.3修改docker-compose——部署配置文件

首先要找到fabric使用网络的名字,运行区块链项目,之后输入docker network ls找出区块链网络

docker network ls

在这里插入图片描述
之后输入

vim docker-compose.yaml

docker-compose.yaml修改后如下:

version: '2.1'

volumes:
  pgdata:
  walletstore:

networks:
  mynetwork.com:
    external:
      name: multinodes_default    # 修改为自己的fabric网络

services:

  explorerdb.mynetwork.com:
    image: hyperledger/explorer-db:latest
    container_name: explorerdb.mynetwork.com
    hostname: explorerdb.mynetwork.com
    ports:     # 暴露端口
      - 5432:5432
    restart: always    # 增加重启参数
    environment:
      - DATABASE_DATABASE=fabricexplorer  # db 库
      - DATABASE_USERNAME=exploreradmin   # db 账户
      - DATABASE_PASSWORD=exploreradminpw  # db 密码
    healthcheck:
      test: "pg_isready -h localhost -p 5432 -q -U postgres"
      interval: 30s
      timeout: 10s
      retries: 5
    volumes:
      - pgdata:/var/lib/postgresql/data
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime    # 与本机时间保持一致
      - /etc/hosts:/etc/hosts    # 映射hosts文件,否则会连接不了其它节点,或者添加extra_hosts参数
    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  # 与上方db 库、账号、密码保持一致
      - DATABASE_USERNAME=exploreradmin
      - DATABASE_PASSWD=exploreradminpw
      - LOG_LEVEL_APP=info
      - LOG_LEVEL_DB=info
      - LOG_LEVEL_CONSOLE=debug
      - LOG_CONSOLE_STDOUT=true
   		 # 浏览器是否开启远程访问, true表示只有部署的机器可以访问
      - DISCOVERY_AS_LOCALHOST=false
    volumes:
      - ./config.json:/opt/explorer/app/platform/fabric/config.json
      - ./connection-profile:/opt/explorer/app/platform/fabric/connection-profile
      - ../crypto-config:/tmp/crypto  # 映射证书目录
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
      - /etc/hosts:/etc/hosts
      - walletstore:/opt/explorer/wallet
    ports:
      - 8080:8080
    restart: always
    depends_on:
      explorerdb.mynetwork.com:
        condition: service_healthy
    networks:
      - mynetwork.com

4.启动区块链浏览器

docker-compose -f docker-compose.yaml up -d
# 如果是第一次启动,他会自动拉取浏览器镜像
# 如果虚拟机没有网络的话需要提前在外网拉取好explorer-db与explorer,然后导入到相应虚机
docker pull hyperledger/explorer-db:latest
docker pull hyperledger/explorer:latest

docker ps
#结果应该如下所示
CONTAINER ID   IMAGE                              COMMAND                  CREATED          STATUS                    PORTS                                       NAMES
72d7227b1306   hyperledger/explorer:latest        "docker-entrypoint.s…"   39 seconds ago   Up 3 seconds              0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   explorer.mynetwork.com
5ac9b1f927cb   hyperledger/explorer-db:latest     "docker-entrypoint.s…"   39 seconds ago   Up 36 seconds (healthy)   5432/tcp                                    explorerdb.mynetwork.com
6735ebc7baf2   hyperledger/fabric-orderer:2.4.2   "orderer"                22 hours ago     Up 48 minutes             0.0.0.0:7050->7050/tcp, :::7050->7050/tcp   orderer.example.com

若要关闭区块链浏览器需要在explorer路径下输入

docker-compose down -v(此处-v不能去掉,因为删除持久化数据才能在下一次启动区块链浏览器时启动成功)

5.访问区块链浏览器

可以直接在虚拟机内浏览器输入localhost:8080访问区块链浏览器,也可在宿主机输入虚拟机(服务器)ip:8080(需要开放端口)访问

explorer账号:exploreradmin
explorer密码:exploreradminpw
在这里插入图片描述
登录之后可以查看区块链网络、区块和交易等信息。
在这里插入图片描述

6.组织内多个peer结点的配置文件

若项目是组织内出现两个peer结点的网络,如果想要配置这种网络的配置文件,只需要将org1-network.json内所有出现peer0的位置同步加上peer1即可,多个peer结点同理多加几个peer即可,如下所示

{
	"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": {},
				//加上peer1
				"peer1.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"
			},
			//加上peer1
			"peers": ["peer0.org1.example.com","peer1.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"
		},
		//加上peer1
		"peer1.org1.example.com": {
			"tlsCACerts": {
				"path": "/tmp/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt"
			},
			"url": "grpcs://peer1.org1.example.com:9051"
		}
	}
}

7 部署问题

如果部署后出现FabricGateway - Failed to create wallet,pleasse check the configureration, and valide file path:{},如下图所示:
在这里插入图片描述
如果检查不出来有什么问题,可能是你的json文件格式在复制粘贴时出现了问题,可以前往Fabric-explorer附件进行下载,之后根据自己的fabric网络有几个组织、几个peer结点来修改json文件

  • 4
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
Hyperledger Fabric开源区块链分布式账本-学习参考资料合集,共37份。 一、Hyperledger开发资料 0. 票据背书详细介绍 1. 设置组织结构 2. 网络环境 3. 使用Fabric SDK Go 4.0. 链码开发_数据结构 4.1. 链码开发_票据相关请求处理 4.2. 链码开发_背书相关请求处理 4.3. 链码安装及实例化 5. 链码调用 6. 在网络应用程序中进行设置 GoWeb编程 二、Hyperledger技术资料 超级账本Hyperledger白皮书(中文版) 快速带你上手Hyperledger Fabric环境搭建+开发测试 性能基准测试和优化Hyperledger Fabric 区块链平台 An Introduction to Hyperledger Architecture of the Hyperledger Blockchain Fabric Cryptography and Protocols in Hyperledger Fabric FabNet- an Automatic Hyperledger Fabric Network Wizard Hyperledger 白皮书 Hyperledger 源码分析之 Fabric - 整体结构 Hyperledger Blockchain Performance Metrics Hyperledger Fabric - A Distributed Operating System for Permissioned Blockchains Hyperledger Fabric 实验指导 HyperLedger Fabric 在携程区块链平台中的应用实战 Hyperledger Fabric Access Control System for Internet of Things Layer in Blockchain-Based Applications Hyperledger Fabric Blockchain:Secure and Efficient Solution for Electronic Health Records Hyperledger fabric- towards scalable blockchain for business Hyperledger Fabric架构概览 hyperledger-fabricdocs Documentation-release-2.0 HyperLedgerFabric智能合约速成 Integrating Blockchain for Data Sharing and Collaboration Support in Scientific Ecosystem Platform Performance Analysis of Hyperledger Fabric Platforms Performance Benchmarking & Optimizing Hyperledger Fabric Blockchain Platform Performance Modeling & Analysis of Hyperledger Fabric (Permissioned Blockchain Network)-177页 Principle Foundations of Hyperledger Fabric Supporting Private Data on Hyperledger Fabric with Secure Multiparty Computation The privacy protection mechanism of Hyperledger Fabric and its application in supply chain finance
Hyperledger Explorer是一个用于浏览和分析Hyperledger区块链网络的开源项目。在Hyperledger Explorer的教程中,首先需要克隆Hyperledger Explorer的代码仓库。你可以使用以下命令进行克隆: ``` git clone https://github.com/hyperledger/blockchain-explorer.git ``` 接下来,你需要设置`configtxgenToolPath`路径,该路径指向Hyperledger Fabric的`configtxgen`工具的位置。该工具用于生成Fabric配置文件。 在克隆代码仓库之后,你可以根据教程的指导,按照特定的步骤进行安装和配置。这些步骤可能包括安装依赖项、设置配置文件、启动服务等等。具体的教程内容可以在Hyperledger Explorer的代码仓库中找到。 总结起来,Hyperledger Explorer的教程包括以下步骤: . 克隆Hyperledger Explorer的代码仓库:`git clone https://github.com/hyperledger/blockchain-explorer.git`。 2. 设置`configtxgenToolPath`路径,指向Hyperledger Fabric的`configtxgen`工具的位置。 3. 按照教程中的指导,进行安装和配置。具体步骤可在Hyperledger Explorer的代码仓库中找到。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Hyperledger Explorer 安装部署(pg版)](https://blog.csdn.net/weixin_29585583/article/details/114996279)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pistachiout

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值