Hyperledger-Explorer实验教程

10/19 09:59
阅读数 24

Hyperledger-Explorer实验教程


区块链浏览器


一、简介


Hyperledger Explorer是一个简单,功能强大,易于使用,高度可维护的开源浏览器,用于查看底层区块链网络上的活动。

二、本机环境


系统:Ubuntu 16.04
docker: 19.03.12
docker-compose:1.26.2
node.js: v12.16.0
npm: 6.13.4
PostgreSQL:9.5.21
Hyperledger Explorer版本 支持的fabric版本 支持的NodeJS版本
v1.1.1(2020年7月17日) v1.4.0至v2.1.1 12.16.x
v1.1.0(2020年7月1日) v1.4.0至v2.1.1 12.16.x
v1.0.0(2020年4月9日) v1.4.0至v1.4.8 10.19.x
v1.0.0-rc3(2020年4月1日) v1.4.0至v1.4.6 10.19.x
v1.0.0-rc2(2019年12月10日) v1.4.0至v1.4.4 8.11.x
v1.0.0-rc1(2019年11月18日) v1.4.2 8.11.x
v0.3.9.5(2019年9月8日) v1.4.2 8.11.x

三、项目代码地址


https://github.com/hyperledger/blockchain-explorer

四、安装


1、安装PostgreSQL方法

https://www.jianshu.com/p/40e35ff27e41

2、安装node方法

安装nvm
$ sudo apt update
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.10/install.sh | bash

$ export NVM_DIR="$HOME/.nvm"
$ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" 
安装node
nvm install v12.16.0
npm换源
npm config set registry https://registry.npm.taobao.org   #换成淘宝的源

查看换源结果

npm config list

npm换源

3、安装docker以及docker-compose

安装docker(^v1.13)
curl -sSL https://get.daocloud.io/docker | sh
安装docker-compose(^1.8)
curl -L https://get.daocloud.io/docker/compose/releases/download/1.26.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

docker下载

配置阿里云镜像加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
   
         
  "registry-mirrors": ["https://ttbxsd4q.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

docker镜像配置成功

4、安装git

apt install git

5、安装go

下载指定版本go
https://golang.google.cn/dl/go1.14.7.linux-amd64.tar.gz
#https://golang.google.cn/dl/
解压缩
tar -C /usr/local -xzf go1.14.7.linux-amd64.tar.gz
配置环境变量
vim /etc/profile

加入以下内容

export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export GOROOT=/usr/local/go
配置go mod
vim /etc/profile

加入以下内容

export GO111MODULE=on
export GOPROXY=https://mirrors.aliyun.com/goproxy/ 

五、操作步骤


0x01启动测试网络

1、下载fabric-samples

mkdir -p go/src/github.com/hyperledger
git clone -b v1.4.4 https://github.com/hyperledger/fabric-samples.git

2、安装fabric

https://github.com/hyperledger/fabric/releases/download/v1.4.4/hyperledger-fabric-linux-amd64-1.4.4.tar.gz

(下载到本地解压缩后放到hyperledger目录下)

export PATH/home/kxh/go/src/github.com/hyperledger:$PATH   #配置环境变量

3、启动测试网络

cd fabric-samples/first-network
 ./byfn.sh -m generate     #生成证书和秘钥
 ./byfn.sh -m up      # 启动网络

启动测试网络

0x02下载 blockchain-explorer

git clone -b v1.1.1 https://github.com/hyperledger/blockchain-explorer.git

0x03 数据库设置

cd blockchain-explorer/app

1、修改 app/explorer/config.json 更新数据库设置

"postgreSQL": {
    "host": "127.0.0.1",
    "port": "5432",          #可事先查看该端口有没有被占用,如果被占用换一个可用端口
    "database": "fabricexplorer",
    "username": "hppoc",
    "passwd": "password"
}

0x04更新fabric网络连接配置文件

1、修改app/platform/fabric/config.json定义fabric网络连接配置文件

{
   
          
    "network-configs": {
   
          
        "first-network": {
   
          
            "name": "firstnetwork",
            "profile": "./connection-profile/first-network.json",    #定义了连接配置文件的地址,十分重要
            "enableAuthentication": false
        }
    },
    "license": "Apache-2.0"
}

2、修改first-network.json

{
   
          
	
	"organizations": {
   
          
		"Org1MSP": {
   
          
			"mspid": "Org1MSP",
			"adminPrivateKey": {
   
          
				"path": "/home/kxh/go/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/8c800cc6a81e81162cabb954da90f3e71d2d9d41096fe0827ede935ca6f694c6_sk"
			},
			"peers": ["peer0.org1.example.com"],
			"signedCert": {
   
          
				"path": "/home/kxh/go/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem"
			}
		}
	},
	"peers": {
   
          
		"peer0.org1.example.com": {
   
          
			"tlsCACerts": {
   
          
				"path": "/home/kxh/go/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
			},
			"url": "grpcs://localhost:7051",
			"grpcOptions": {
   
          
				"ssl-target-name-override": "peer0.org1.example.com"
			}
		}
	},
	"certificateAuthorities": {
   
          
		"ca0": {
   
          
			"url": "https://localhost:7054",
			"httpOptions": {
   
          
				"verify": false
			},
			"tlsCACerts": {
   
          
				"path": "/home/kxh/go/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem"
			},
			"caName": "ca0-org1"
		}
	}
}

该文件需要根据本机具体环境修改其中的 path值,该文件定义了连接fabric网络的信息

0x05创建数据库

cd blockchain-explorer/app/persistence/fabric/postgreSQL/db
node processenv.js
sudo -u postgres ./createdb.sh  # 执行该命令之前,先将第六行的node processenv.js命令注释掉

1、连接 PostgreSQL数据库,运行数据库命令

$ sudo -u postgres psql -c '\l'
                                List of databases
      Name      |  Owner   | Encoding | Collate |  Ctype  |   Access privileges
----------------+----------+----------+---------+---------+-----------------------
 fabricexplorer | hppoc    | UTF8     | C.UTF-8 | C.UTF-8 |
 postgres       | postgres | UTF8     | C.UTF-8 | C.UTF-8 |
 template0      | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
                |          |          |         |         | postgres=CTc/postgres
 template1      | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
                |          |          |         |         | postgres=CTc/postgres
(4 rows)

$ sudo -u postgres psql fabricexplorer -c '\d'
                   List of relations
 Schema |           Name            |   Type   | Owner
--------+---------------------------+----------+-------
 public | blocks                    | table    | hppoc
 public | blocks_id_seq             | sequence | hppoc
 public | chaincodes                | table    | hppoc
 public | chaincodes_id_seq         | sequence | hppoc
 public | channel                   | table    | hppoc
 public | channel_id_seq            | sequence | hppoc
 public | orderer                   | table    | hppoc
 public | orderer_id_seq            | sequence | hppoc
 public | peer                      | table    | hppoc
 public | peer_id_seq               | sequence | hppoc
 public | peer_ref_chaincode        | table    | hppoc
 public | peer_ref_chaincode_id_seq | sequence | hppoc
 public | peer_ref_channel          | table    | hppoc
 public | peer_ref_channel_id_seq   | sequence | hppoc
 public | transactions              | table    | hppoc
 public | transactions_id_seq       | sequence | hppoc
 public | write_lock                | table    | hppoc
 public | write_lock_write_lock_seq | sequence | hppoc

0x06 构建Hyperledger Explorer

./main.sh install # 在blockchain-explorer目录下执行,改脚本文件负责安装依赖,运行test、构建项目

六、启动网络


./start.sh         # 在blockchain-explorer目录下执行

打开浏览器,输入:http://localhost:8080 进入区块链浏览器页面

七、效果演示


DASHBOARD
NETWORK
BLOCK
TRANSACTIONS1
transaction details
chaincodes
channels





展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部