fabric|Hyperledger Explorer(区块链浏览器) 环境搭建

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

软件安装 安装Node
下载tar包
fabric|Hyperledger Explorer(区块链浏览器) 环境搭建
文章图片

解压
tar -xvf node-v12.16.2-linux-x64.tar.xz
mv node-v12.16.2-linux-x64 node-v12.16.2
fabric|Hyperledger Explorer(区块链浏览器) 环境搭建
文章图片


配置全局使用
ln -s /usr/local/node-v12.16.2/bin/node /usr/local/bin/node
ln -s /usr/local/node-v12.16.2/bin/npm /usr/local/bin/npm
fabric|Hyperledger Explorer(区块链浏览器) 环境搭建
文章图片

安装PostgreSQL
apt-get install postgresql
启动服务
/etc/init.d/postgresql start

修改用户密码:
su - postgres 切换用户,执行后提示符会变为 '-bash-4.2$'
psql -U postgres 登录数据库,执行后提示符变为 'postgres=#'
ALTER USER postgres WITH PASSWORD 'postgres'; 设置postgres用户密码为postgres
\q 退出数据库
exit 退出命令行界面

卸载
apt-get --purge remove postgresql*
apt-get --purge remove postgis*

安装jq
apt install jq

安装gcc
apt install gcc

gcc --version

Hyperledger Explorer下载 【fabric|Hyperledger Explorer(区块链浏览器) 环境搭建】cd /opt/gopath/src/github.com/hyperledger
git clone https://github.com/hyperledger/blockchain-explorer.git

创建数据库
我们使用默认版本,进行数据库创建:
cd blockchain-explorer/app
vi explorerconfig.json
修改配置如下:

{"persistence": "postgreSQL","platforms": ["fabric"],"postgreSQL": {"host": "127.0.0.1","port": "5432","database": "fabricexplorer","username": "postgres","passwd": "postgres"},"sync": {"type": "local","platform": "fabric","blocksSyncTime": "1"},"jwt": {"secret": "a secret phrase!!","expiresIn": "2h"}}

fabric|Hyperledger Explorer(区块链浏览器) 环境搭建
文章图片


运行创建数据库的脚本
cd /opt/gopath/src/github.com/hyperledger/blockchain-explorer/app/persistence/fabric/postgreSQL/db

./createdb.sh
fabric|Hyperledger Explorer(区块链浏览器) 环境搭建
文章图片

查看数据库状态指令:
sudo -u postgres psql -c '\l'
sudo -u postgres psql fabricexplorer -c '\d'
fabric|Hyperledger Explorer(区块链浏览器) 环境搭建
文章图片


定义fabric网络连接参数
cd /opt/gopath/src/github.com/hyperledger/blockchain-explorer/app/platform/fabric/
vim config.json
设置enableAuthentication属性false,用于关闭登录认证
{
"network-configs": {
"first-network": {
"name": "firstnetwork",
"profile": "./connection-profile/first-network.json",
"enableAuthentication": false
}
},
"license": "Apache-2.0"
}
fabric|Hyperledger Explorer(区块链浏览器) 环境搭建
文章图片

设置first-network.json配置

继续进行设置(Fabric网络环境要处于正常启动的状态,不然下述路径的文件是不存在的)
cd /opt/gopath/src/github.com/hyperledger/blockchainexplorer/app/platform/fabric/connection-profile/
vim first-network.json

重点设置如下几项:
{"name": "first-network","version": "1.0.0","license": "Apache-2.0","client": {"tlsEnable": true,"caCredential": {"id": "admin","password": "adminpw"},"adminCredential": {"id": "admin","password": "123456","affiliation": "org1.department1"},"enableAuthentication": true,"organization": "Org1MSP","connection": {"timeout": {"peer": {"endorser": "300"},"orderer": "300"}}},"channels": {"zmeduchannel": {"peers": {"peer0.org1.example.com": {}},"connection": {"timeout": {"peer": {"endorser": "6000","eventHub": "6000","eventReg": "6000"}}}}},"organizations": {"Org1MSP": {"mspid": "Org1MSP","adminPrivateKey": {"path": "/opt/gopath/src/github.com/hyperledger/fabric/example/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/9ccc1d5b3baae6d7a0aa697d6cae8009ad55c12cbdba34cdaeaaf7ab15d96ab0_sk"},"peers": ["peer0.org1.example.com"],"signedCert": {"path": "/opt/gopath/src/github.com/hyperledger/fabric/example/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": "/opt/gopath/src/github.com/hyperledger/fabric/example/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"},"url": "grpcs://peer0.org1.example.com:7051","grpcOptions": {"ssl-target-name-override": "peer0.org1.example.com"}}},"certificateAuthorities": {"ca0": {"url": "https://peer0.org1.example.com:7054","httpOptions": {"verify": false},"tlsCACerts": {"path": "/opt/gopath/src/github.com/hyperledger/fabric/example/crypto-config/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem"},"caName": "ca0"}}}

  1. adminCredential 设置浏览器登录的用户密码
  2. channels 设置通道名、peer0名
  3. organizations 设置证书路径
  4. peers 设置peer-ca证书路径
  5. certificateAuthorities 设置ca证书路径

注:需要说明一点,这两个 "tlsCACerts" 并不在一个字典中,配置时要特别注意,还有就是以自己的文件路径为主。

编译 cd /opt/gopath/src/github.com/hyperledger/blockchain-explorer
npm install --unsafe-perm

cd /opt/gopath/src/github.com/hyperledger/blockchain-explorer/client
npm install --unsafe-permnpm run build --unsafe-perm

cd /opt/gopath/src/github.com/hyperledger/blockchain-explorer
npm run build --unsafe-perm


启动 cd /opt/gopath/src/github.com/hyperledger/blockchain-explorer
./start.sh


后台启动
nohup ./start.sh logs/log.log 2>&1 &


查看日志blockchain-explorer/logs/console/
fabric|Hyperledger Explorer(区块链浏览器) 环境搭建
文章图片

停止 ./stop.sh

访问 http://127.0.0.1:8080/
fabric|Hyperledger Explorer(区块链浏览器) 环境搭建
文章图片














    推荐阅读