一、环境准备(本节是紧接着上一篇博客编写:https://note.youdao.com/share/?id=08cba7c7957649ad31049483b42f3067&type=note#/ )
参考官方文档:https://github.com/hyperledger/blockchain-explorer
1、nodejs安装(nodejs 8.11.x (Note that v9.x is not yet supported)),由于上一篇博客已经安装了nvm,所以只需用nvm安装指定版本即可(此处安装8.11.4版本)
root@ubuntu:~# nvm install 8.11.4
Downloading and installing node v8.11.4...
Downloading https://nodejs.org/dist/v8.11.4/node-v8.11.4-linux-x64.tar.xz...
################################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v8.11.4 (npm v5.6.0)
root@ubuntu:~# node -v
v8.11.4
root@ubuntu:~#
2、postgresql安装(PostgreSQL 9.5 or greater),这里以docker的形式进行安装
docker pull postgres:9.5
docker run --name postgres1 -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:9.5 #postgres镜像默认的用户名为postgres,设置一个密码postgres
3、安装jq
sudo apt-get install jq
二、具体步骤
1、下载blockchain-explorer源码
cd /root/demo
git clone https://github.com/hyperledger/blockchain-explorer.git
cd blockchain-explorer
2、数据库初始化
root@iZq0c7mivu8vrvZ:~# docker exec -it b88997d1aad3 /bin/bash #进入postgresql容器:b88997d1aad3
root@b88997d1aad3:/# su postgres #切换用户
postgres@b88997d1aad3:/$ psql #进入命令行客户端
psql (9.5.15)
Type "help" for help.
postgres=# CREATE DATABASE fabricexplorer owner postgres; #创建fabricexplorer数据库并指定用户fabricexplorer
数据库创建好后执行初始化sql语句(也可以用postgresql相关桌面客户端连接数据库),以下数据库脚本参考官方https://github.com/hyperledger/blockchain-explorer/blob/master/app/persistence/fabric/postgreSQL/db/explorerpg.sql:
-- ----------------------------
-- Table structure for `blocks`
-- ----------------------------
DROP TABLE IF EXISTS blocks;
CREATE TABLE blocks (
id SERIAL PRIMARY KEY,
blocknum integer DEFAULT NULL,
datahash character varying(256) DEFAULT NULL,
prehash character varying(256) DEFAULT NULL,
txcount integer DEFAULT NULL,
createdt Timestamp DEFAULT NULL,
prev_blockhash character varying(256) DEFAULT NULL,
blockhash character varying(256) DEFAULT NULL,
channel_genesis_hash character varying(256) DEFAULT NULL
);
ALTER table blocks owner to postgres;
-- ----------------------------
-- Table structure for `chaincodes`
-- ----------------------------
DROP TABLE IF EXISTS chaincodes;
CREATE TABLE chaincodes (
id SERIAL PRIMARY KEY,
name character varying(255) DEFAULT NULL,
version character varying(255) DEFAULT NULL,
path character varying(255) DEFAULT NULL,
chan