参考博文
https://www.jianshu.com/p/2d4673567ff8?utm_campaign=haruki
https://www.jianshu.com/p/58ade73fc68c
https://github.com/hyperledger/blockchain-explorer
https://blog.csdn.net/oafzzl/article/details/103878692?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-2

准备工作

1、 安装Nodejs 10.19.0

wget https://nodejs.org/download/release/v10.19.0/node-v10.19.0-linux-x64.tar.gz
tar -xvf node-v10.19.0-linux-x64.tar.gz
sudo ln -s /home/ubuntu/node-v10.19.0-linux-x64/bin/node
/usr/local/bin/node
sudo ln -s /home/ubuntu/node-v10.19.0-linux-x64/bin/npm
/usr/local/bin/npm
mv /home/ubuntu/node-v8.14.0-linux-x64  /home/ubuntu/node
vim /etc/profile  #修改profile加入下面内容
export PATH="$PATH:/home/ubuntu/node/bin"

2、 PostgreSQL 9.5以上,我用的是10
更新 apt 包索引

sudo apt-get update

安装数据库,安装后会自动添加postgres 的操作系统用户,密码是随机的

sudo apt-get install postgresql

打开客户端工具 psql

sudo -u postgres psql

修改 postgres 数据库用户的密码为123456

postgres=# ALTER USER postgres WITH
PASSWORD '123456'; 

退出 psql

postgres=# \q

修改 ubuntu 操作系统的 postgres 用户的密码

sudo passwd -d postgres
sudo -u postgres passwd

修改配置实现远程访问

vi /etc/postgresql/10/main/postgresql.conf

修改连接权限

#listen_addresses = 'localhost' 改为 listen_addresses = '*'

设置所有用户可连接

vi /etc/postgresql/10/main/pg_hba.conf

在最后一行插入以下内容

host all all 0.0.0.0/0 md5

重启服务

/etc/init.d/postgresql restart

3、安装 Jq

sudo apt-get install jq

验证版本

jq -V

4、 Docker CE 18.09.2 or later
5、 Docker Compose 1.14.0
6、 保证first-network可以运行

开始搭建
拉取项目

git clone https://github.com/hyperledger/blockchain-explorer.git
#太慢的话用码云

进入目录

cd blockchain-explorer

修改配置文件

进入目录blockchain-explorer/app,默认配置就好,其实不需要修改

vim explorerconfig.json
cd blockchain-explorer/app/persistence/fabric/PostgreSQL
chmod -R 775 db/
cd db

查看是否创建成功
连接 postgresSQL

sudo -u postgres psql

查看已有数据库

\l

创建表

\d

退出

\q

修改配置文件

cd blockchain-explorer/app
"jwt": {
"secret" : "a secret phrase!!",
"expiresIn": "2 days"
}

启动first-network

./byfn.sh up

修改first-network.json配置文件

(1) 把搭建Fabric网络时生成的crypto-config复制到blockchain-explorer目录下任意位置。

(2) 替换organizations和peers下的证书位置,最好使用全路径。使用全路径时,需要把fullpath设为true.

XXXX为修改部分

{
"name": "aberic",
"version": "1.0.0",
"license": "Apache-2.0",
"client": {
"tlsEnable": true,
"adminUser": "admin",
"adminPassword": "adminpw",
"enableAuthentication": false,
"organization": "Org1",
"connection": {
"timeout": {
                "peer": {
                    "endorser":"300"
                },
                "orderer":"300"
}
}
},
"channels": {
"mychannel": {
"peers": {
"peer0.org1.example.com": {}
},
"connection": {
                "timeout": {
                    "peer": {
                        "endorser":"6000",
                        "eventHub":"6000",
                        "eventReg": "6000"
                    }
                }
}
}
},
"organizations": {
"Org1MSP": {
"mspid": "Org1MSP",
"fullpath": true,
"adminPrivateKey": {
                "path": "XXX/blockchain-explorer/app/platform/fabric/fixtures/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/XXXX"
#换成自己的sk     
},
"signedCert": {
                "path":
"XXX/blockchain-explorer/app/platform/fabric/fixtures/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":
"XXX/blockchain-explorer/app/platform/fabric/fixtures/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"      
},
   "url":
"grpcs://XXX",
"eventUrl": "grpcs://XXX",
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com"
}
}
    }
}

构建Hyperledger Explorer

cd ~
cd blockchain-explorer/
./main.sh install
./main.sh test

运行

cd ~
cd blockchain-explorer/
./start.sh

可能出现的错误

./createdb.sh
could not change
directory to "/home/dc2-user/kongli/blockchain-explorer/app/persistence/postgreSQL/db":
权限不够

需要把blockchain-explorer下载在非当前用户文件夹下,比如/tmp

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐