fabric explorer区块链浏览器搭建教程

参考官方文档:https://github.com/hyperledger/blockchain-explorer

随着explorer项目的不断更新,其master分支一直在改变,我们根据自己部署的fabric1.0 或fabric1.1网络选择合适的分支版本,不同版本分支的explorer项目差别挺大,有些项目中自带了fabric网络,有些项目需要将路径指向本地已经启动的fabric网络。例如reactbranch分支,项目中是自带了fabric1.0网络,不需要前期自己配置。本文主要用的是最新的master分支作为示例。
(一)前提条件:
  1. nodejs 8.11.x (Note that v9.x is not yet supported)
  2. PostgreSQL 9.5 or greater
  3. docker 17.06.2-ce
  4. docker-compose 1.14.0

1. nodejs 8.11.3 安装 (资源链接:https://pan.baidu.com/s/1YLpNuIKbCgjQ2BDNkNY48g)

如果在虚拟机上的应该没有问题,如果在阿里云上的最好先创建一个普通用户,赋予sudo权限,因为在后面 npm install步骤中root管理员模型执行会报错。我这里创建了账户名为 lh 的普通用户,将下载的node-v8.11.3-linux-x64.tar 放到/home/lh 目录下,执行下列命令
node-v8.11.3-linux-x64.tar.gz
tar -xvf node-v8.11.3-linux-x64.tar.gz     //解压
ln -s /home/lh/node-v8.11.3-linux-x64/bin/node /usr/local/bin/node   //建立软链
ln -s /home/lh/node-v8.11.3-linux-x64/bin/npm /usr/local/bin/npm   //建立软链
node -v   
npm -v   //查看是否安装成功
2.PostgreSQL 安装
直接执行下列命令即可
sudo apt-get install postgresql
下载下来的直接就是 9.5.x 版本符合要求。

3. docker 17.06.2-ce 和 docker-compose 1.14.0
似乎docker向上兼容,docker18的版本也是可以的,但我为了保险,还是下了17.06.2的版本(下载特定版本方法直接看docker官网,需要fq),docker-compose1.14下载的特定版本比较方便,执行下列命令即可
curl -L https://get.daocloud.io/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose 
chmod +x /usr/local/bin/docker-compose

(2)下载项目源码

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

cd blockchain-explorer

要注意 master 可能会变化。

(3)数据库初始化

sudo -u postgres psql     //连接PosgreSQL database
\i app/persistance/postgreSQL/db/explorerpg.sql
\i app/persistance/postgreSQL/db/updatepg.sql     //执行数据库脚本

(4)运行启动你的一个Fabric 1.1网络

1. 进入go的path目录

cd $GOPATH

2.新建文件夹并进入到路径

mkdir -p src/github.com/hyperledger  
/opt/gopath/src/github.com/hyperledger

3.下载fabric 和 fabric-samples

git clone https://github.com/hyperledger/fabric.git
git clone https://github.com/hyperledger/fabric-samples.git

4.切换版本至1.1

cd fabric/
git checkout release-1.1    //切换版本
git branch -a      //查看当前版本
cd fabric-samples/
git checkout release-1.1
git branch -a
5. 下载镜像和要执行的二进制文件

如果能够访问外网,可以执行下列命令,下载所需的镜像和二进制文件

curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0

但大多数情况我们无法访问外面,可以进入到fabric目录下的scripts执行bootstrap.sh 

cd fabric/scripts/
./bootstrap.sh

进入到fabric-samples文件下载1.1.0版本所需的二进制文件

wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.1.0/hyperledger-fabric-linux-amd64-1.1.0.tar.gz

解压下载的文件,会多出bin 和config两个文件夹

tar -zxvf hyperledger-fabric-linux-amd64-1.1.0.tar.gz 

把bin配置到环境

cd bin/
pwd
vim /etc/profile    //加入环境变量
source /etc/profile   //使环境变量生效

在/etc/profile中加入


6.运行fabric1,1网络

cd fabric-samples/first-network/
./byfn.sh -m generate  //生成配置文件
./byfn.sh -m up    //启动网络

如果在阿里云中运行,一定要修改  /etc/resolv.conf 配置,将 options timeout:2 attempts:3 rotate single-request-reopen   这行内容注释。

(5)修改配置文件

cd 到  blockchain-explorer/app/platform/fabric  这个路径 修改config.json文件。

修改一下配置文件中 "tls_cacerts", "key", "cert" 的路径,这个路径是你启动fabric 1.1 网络的绝对路径。

再在 “channel”: "mychannel"下添加数据库的信息,由于我们直接通过PostgreSQL 命令生成的数据库数据表,用户名和密码都是自带默认的,不需要我们修改。详情可见 explorerpg.sql 

"channel": "mychannel",
 "pg": {
		"host": "127.0.0.1",
		"port": "5432",
		"database": "fabricexplorer",
		"username": "hppoc",
		"passwd": "password"
	}

至于github项目中README 中描述的下面这句话,还是没有搞懂,所以也没有管。


(6)安装explorer所需的node依赖

  • 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

注意的几点:

1.这里运行 npm intsall 如果出现warn 警告,可以忽略不影响。

2.经过我的测试,阿里云下,root账户执行npm install 会报权限错误,但新建一个普通账户,并赋予 sudo 权限后就不会。

3.sudo npm install 运行也会报错。

4.如果出现单个文件夹 权限不足,直接  执行  sudo chmod +777 ./XXX   来给与最高权限。

5.如果在虚拟机上运行的 保证分配的配置稍微高一点,不然 最后一步 npm run build 会卡死。

(7)运行Hyperlegder Explorer

执行下列命令

cd blockchain-explorer/
./start.sh

调用 log 目录下的目录,如果显示  Please open Internet explorer to accesshttp://localhost:8080/   那就成功了。

不然的话根据报错再调试一下,可能会遇到证书文件的权限不够,按照上面的方面给予权限就行。

最后运行界面:

如果在阿里云的部署运行过程中有问题,可以邮箱联系我,[email protected]    ,我也有现成的阿里云镜像可以商量着分享。

猜你喜欢

转载自blog.csdn.net/leehom__/article/details/81022151