blockchain-explorer(pg版) 部署及配置详解

前置工具:

Git

Node.js  8.11.X 高版本暂不支持

PostgreSQL  9.5 以上 此处使用10

本篇部署环境:Ubuntu

准备环境:

安装git

sudo apt-get install git

安装node 8.11

因为版本限制,采用源码安装

#路径为 /usr/local

cd /usr/local

sudo wget https://npm.taobao.org/mirrors/node/latest-v8.x/node-v8.11.1-linux-x64.tar.xz

sudo tar xvf node-v8.11.1-linux-x64.tar.xz

cd node-v8.11.1-linux-x64/bin

./node -v  #此时显示 8.11.1

sudo vim ~/.bashrc

#在打开文件的最后一行添加

export PATH=/usr/local/node-v8.11.1-linux-x64/bin:$PATH

#打开一个新的终端node -v 验证

安装Postgresql

官网链接

#查看unbuntu版本 
cat /etc/issue

#参数YOUR_UBUNTU_VERSION_HERE为 xenial(16.04)/bionic(18.04)/trusty(14.04)
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ YOUR_UBUNTU_VERSION_HERE-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

#例,版本为16.04 => deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main

sudo apt-get install wget ca-certificates

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

sudo apt-get update

sudo apt-get install postgresql-10

psql --version    #验证版本

开始部署

下载代码

这里直接取用了master的代码

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

下载fabric工具

这里下载的目前最新的1.2版本,就是fabric configtxgen 之类的工具包,部署fabric时应该已下载。

VERSION=1.2.0

ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]' | sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')

curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/hyperledger-fabric-${ARCH}-${VERSION}.tar.gz | tar xz

postgresql配置成可访问并开启服务

先启动pg


$sudo systemctl enable postgresql

$sudo systemctl start postgresql
//检查是否启动成功
$sudo systemctl status postgresql

ubuntu@ubuntu00:~$ sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since Fri 2018-08-03 14:12:16 CST; 4h 22min ago
 Main PID: 10398 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/postgresql.service

Aug 03 14:12:16 ubuntu00 systemd[1]: Starting PostgreSQL RDBMS...
Aug 03 14:12:16 ubuntu00 systemd[1]: Started PostgreSQL RDBMS.
Aug 03 14:12:28 ubuntu00 systemd[1]: Started PostgreSQL RDBMS.
Aug 03 18:34:24 ubuntu00 systemd[1]: Started PostgreSQL RDBMS.
#绿色则启动成功

再进入pg执行代码中的数据库脚本 (老版本)

$ cd blockchain-explorer/
# 进入控制台
$ sudo -u postgres psql
#变成这样子

ubuntu@ubuntu00:~$ cd blockchain-explorer/
ubuntu@ubuntu00:~/blockchain-explorer$ sudo -u postgres psql
psql (10.4 (Ubuntu 10.4-2.pgdg16.04+1))
Type "help" for help.
#执行语句,这里是相对路径
postgres=# \i app/persistence/postgreSQL/db/explorerpg.sql
#上一句执行完会进入此数据库,再执行
fabricexplorer=# \i app/persistence/postgreSQL/db/updatepg.sql
#查看已有数据库
\l
#查看已创建表
\d
#退出
\q

-----------------------------------2018.8.16更新-------------------------------------------------

官方更新了release3.5的代码,更新了创建数据库脚本,新步骤如下,仍可用上一步得方法查看脚本执行结果。

$sudo apt-get install jq 

$cd blockchain-explorer/app/persistence/postgreSQL/db

$./createdb.sh 

修改pg访问权限,重启pg

//进入配置文件目录
$ cd /etc/postgresql/10/main
//修改访问控制文件
$ sudo vi postgresql.conf
把这里原来的注释取消掉
listen_addresses = 'localhost' 

$ sudo vi pg_hba.conf
在此处插入一行或直接在最上面
# TYPE  DATABASE        USER            ADDRESS                 METHOD

host    all             all             0.0.0.0/0               md5

$ systemctl restart postgresql

修改数据库配置

$cd blockchain-explorer/app/persistence/postgreSQL/db
$vi pgconfig.json
{
        "pg": {
                "host": "127.0.0.1",
                "port": "5432",
                "database": "fabricexplorer",
                "username": "hppoc",
                "passwd": "password"
        }
}
#若在本机,一般无需改动

配置fabric网络

$vi blockchain-explorer/app/platform/fabric/config.json
#这里配置了两个order四个peer,可以视情况增删

 {
        "network-config": {
                "org1": {
                        "name": "org0",
                        "mspid": "Org0MSP",
                        "peer1": {
                                #注意,若未开启fabric网络未开启TLS,则将grpcs改成grpc,并可省略tls证书配置,下同。
                                "requests": "grpcs://xxx.xxx.xx.xxx:7051",
                                "events": "grpcs://xxx.xxx.xx.xxx:7053",
                                "server-hostname": "peer0.org0.supplyfinchain.com",
                                "tls_cacerts": "/home/ubuntu/supplychain-faas/fabric-network/crypto-config/peerOrganizations/org0.supplyfinchain.com/peers/peer0.org0.supplyfinchain.com/tls/ca.crt"
                        },
                        "peer2": {
                                "requests": "grpcs://xxx.xxx.xx.xxx:8051",
                                "events": "grpcs://xxx.xxx.xx.xxx:8053",
                                "server-hostname": "peer1.org0.supplyfinchain.com",
                                "tls_cacerts": "/home/ubuntu/supplychain-faas/fabric-network/crypto-config/peerOrganizations/org0.supplyfinchain.com/peers/peer1.org0.supplyfinchain.com/tls/ca.crt"
                        },
                        "admin": {
                                "key": "/home/ubuntu/supplychain-faas/fabric-network/crypto-config/peerOrganizations/org0.supplyfinchain.com/users/[email protected]/msp/keystore",
                                "cert": "/home/ubuntu/supplychain-faas/fabric-network/crypto-config/peerOrganizations/org0.supplyfinchain.com/users/[email protected]/msp/signcerts"
                        }
                },
               "org2": {
                        "name": "org1",
                        "mspid": "Org1MSP",
                        "peer1": {
                                "requests": "grpcs://xxx.xxx.xx.xxx:9051",
                                "events": "grpcs://xxx.xxx.xx.xxx:9053",
                                "server-hostname": "peer0.org1.supplyfinchain.com",
                                "tls_cacerts": "/home/ubuntu/supplychain-faas/fabric-network/crypto-config/peerOrganizations/org1.supplyfinchain.com/peers/peer0.org1.supplyfinchain.com/tls/ca.crt"
                        },
                        "peer2": {
                                "requests": "grpcs://xxx.xxx.xx.xxx:10051",
                                "events": "grpcs://xxx.xxx.xx.xxx:10053",
                                "server-hostname": "peer1.org1.supplyfinchain.com",
                                "tls_cacerts": "/home/ubuntu/supplychain-faas/fabric-network/crypto-config/peerOrganizations/org1.supplyfinchain.com/peers/peer1.org1.supplyfinchain.com/tls/ca.crt"
                        },
                        "admin": {
                                "key": "/home/ubuntu/supplychain-faas/fabric-network/crypto-config/peerOrganizations/org1.supplyfinchain.com/users/[email protected]/msp/keystore",
                                "cert": "/home/ubuntu/supplychain-faas/fabric-network/crypto-config/peerOrganizations/org1.supplyfinchain.com/users/[email protected]/msp/signcerts"
                        }
                }

        },
        "channel": "channel01", #需要监听的channel名称
        "orderers":[
                                {
                                "mspid": "OrdererMSP",
                                "server-hostname":"orderer0.supplyfinchain.com",
                                "requests":"grpcs://xxx.xxx.xx.xxx:7050",
                                "tls_cacerts":"/home/ubuntu/supplychain-faas/fabric-network/crypto-config/ordererOrganizations/supplyfinchain.com/orderers/orderer0.supplyfinchain.com/tls/ca.crt"
                                },
                                {
                                "mspid": "OrdererMSP",
                                "server-hostname":"orderer1.supplyfinchain.com",
                                "requests":"grpcs://xxx.xxx.xx.xxx:7050",
                                "tls_cacerts":"/home/ubuntu/supplychain-faas/fabric-network/crypto-config/ordererOrganizations/supplyfinchain.com/orderers/orderer1.supplyfinchain.com/tls/ca.crt"
                                }
                                ],
        "keyValueStore": "/tmp/fabric-client-kvs",
        "configtxgenToolPath": "/home/ubuntu/bin", #之前安装的fabric工具路径
        "SYNC_START_DATE_FORMAT":"YYYY/MM/DD",
        "syncStartDate":"2018/01/01",
        "eventWaitTime": "30000",
        "license": "Apache-2.0",
        "version": "1.1"
        }

启动

$sudo apt-get install make 
$sudo apt-get install g++ #可能有遗漏,就是安装一些C语言编译相关的插件,install时根据错误提示安装即可
$cd blockchain-explorer
$npm install
$cd blockchain-explorer/app/test
$npm install
$npm run test
$cd client/
$npm install
$npm test -- -u --coverage
#这一步可能非常慢,试了几次有的机器几分钟,有时一个小时
$npm run build


#表示返回
$cd blockchain-explorer
#端口配置在blockchain-explorer/appconfig.json文件,默认8080
$./start.sh
#看日志是否报错,有时候启动失败的话需要一定的时候才会打印错误日志
$cat logs/console/console-xxxxxxx.log
$./stop.sh

-----------------------------------2018.8.9更新-------------------------------------------------

若部署的是fabric1.2,目前不能用master版本代码,可切换release3.5版本,而且仍有BUG,对最新的fabric并不能完全兼容。

猜你喜欢

转载自blog.csdn.net/baidu_37379451/article/details/81385068