faric区块链浏览器搭建

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_39304564/article/details/102753270

1. 系统环境

为了便于描述各个服务器间的配置进行以下名称约定:
在这里插入图片描述

2. 部署GO语言环境

Golang最低版本要求:1.10.x,当前安装版本:1.11;至于go的下载地址去其官网即可。

2.1. 解压文件

tar zxvpf go1.11.linux-amd64.tar.gz

2.2. 移动文件

mv go /usr/local/

2.3. 配置环境变量

vim /etc/profile

打开 /etc/profile 配置文件,在末尾加入如下配置:

export GOPATH=/opt/gopath
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:$GOPATH

加载环境变量配置

source /etc/profile

3. 安装docker

docker最低版本要求:Docker version 17.06.2-ce or greater

3.1. 安装docker-engine

下载地址:
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/ docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
执行以下命令安装:

rpm -ivh --nodeps docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm

查看docker版本信息,检查是否安装成功:

docker -v

docker 版本必须满足最低版本;

3.2. 配置docker-compose

cp docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
chmod a+x /usr/local/bin/docker-compose

3.3. 配置使用权限

systemctl restart docker 
chmod a+rw /var/run/docker.sock
systemctl restart docker 

3.4. 启动时关闭防火墙

vim /usr/lib/systemd/system/docker.service

编辑 /usr/lib/systemd/system/docker.service 配置文件,增加斜体部分,如下:
[Service]
#ExecStart=/usr/bin/dockerd
ExecStart=/usr/bin/dockerd –iptables=false
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
刷新配置并重启docker

systemctl daemon-reload
systemctl restart docker

3.5. 设置开机启动服务

systemctl enable docker.service

3.6. 重启docker服务

systemctl restart docker

3.7. 查看服务状态

service docker status

4. 关闭防火墙

4.1. 停止服务

systemctl stop firewalld.service

4.2. 禁用自动启动

systemctl disable firewalld.service

4.3. 查看状态

firewall-cmd --state

注:关闭后显示notrunning,开启后显示running

5. nodejs安装

下载链接:https://npm.taobao.org/mirrors/node/v8.11.4/node-v8.11.4-linux-x64.tar.gz

5.1. 解压缩并安装

sudo tar -xvf node-v8.11.4-linux-x64.tar.xz
mv node-v8.11.4-linux-x64 /usr/local/node

5.2. 修改环境变量

打开 /etc/profile 配置文件,

vim /etc/profile

在末尾加入如下配置
添加一下行:
export NODE_HOME=/usr/local/node
修改以下行(增加红色内容):
export PATH= $NODE_HOME/bin:PATH
更新环境变量配置

source /etc/profile

6. PostgreSQL安装

6.1. 添加RPM

yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm

6.2. 安装PostgreSQL 9.5

yum install postgresql95-server postgresql95-contrib

6.3. 初始化数据库

/usr/pgsql-9.5/bin/postgresql95-setup initdb

6.4. 设置开机自启动

systemctl enable postgresql-9.5.service

6.5. 启动服务

systemctl start postgresql-9.5.service

7. Jq安装

7.1. 安装EPEL源

yum install epel-release

7.2. 检查jq包

安装完EPEL源后,可以查看下jq包是否存在。

yum list jq

7.3. 安装jq

yum install jq

8. 加载镜像并修改tag

8.1. 加载镜像

当然这是在本地已有镜像的情况下,没有的话可以直接docker pull下载:

docker load < fabric-orderer.tar
docker load < fabric-tools.tar
docker load < fabric-baseos.tar
docker load < fabric-ccenv.tar
docker load < fabric-peer.tar

8.2. 修改镜像tag

docker tag hyperledger/fabric-tools:1.2.0 hyperledger/fabric-tools:latest
docker tag hyperledger/fabric-ccenv:1.2.0 hyperledger/fabric-ccenv:latest
docker tag hyperledger/fabric-orderer:1.2.0 hyperledger/fabric-orderer:latest
docker tag hyperledger/fabric-peer:1.2.0 hyperledger/fabric-peer:latest

9. 部署区块链服务

9.1. 下载安装fabric-sample

从fabric官方下载fabric-sample源码文件(TODO,修改为从gitlab拉取),如下:

cd $GOPATH/src/github.com/hyperledger
git clone https://github.com/hyperledger/fabric-samples.git
cd fabric-samples/
git branch -a
git checkout release-1.2 (若已是1.2可省略)

9.2. 下载自动化部署脚本

在fabric-samples目录中,下载自动化部署脚本并执行:

curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s 1.2.0 1.2.0 0.4.10 

如果上一步下载失败,则直接从10.1.53.60主机上/opt/gopath/src/github.com/hyperledger/目录下直接拉取整个fabric-samples目录的内容,替换当前主机的fabric-samples目录,并接着执行。
打开 /etc/profile 配置文件,在末尾加入如下配置

vim /etc/profile

添加一下行:
FABRIC_SAMPLES=$GOPATH/src/github.com/hyperledger/fabric-samples
修改以下行(增加红色内容):

export PATH=$FABRIC_SAMPLES/bin:$PATH

更新环境变量配置

source /etc/profile

9.3. 执行脚本测试

cd $GOPATH/src/github.com/hyperledger/fabric-samples/first-network
./byfn.sh up

10. 部署区块链浏览器服务

10.1. 下载安装blockchain-explorer

从fabric官方下载blockchain-explorer源码文件,如下:

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

10.2. 启动postgreSQL数据库

这里采用默认配置,直接启动即可,如下:

chmod -R 775 blockchain-explorer/app/persistence/fabric/postgreSQL/db
cd blockchain-explorer/app/persistence/fabric/postgreSQL/db
./createdb.sh

10.3. 配置NPM国内镜像

NPM 国内被墙,需要配置淘宝的镜像。

vim  root/.npmrc

添加以下内容
registry = https://registry.npm.taobao.org
注:本机是以root用户登陆,故修改root/.npmrc,其他用户登陆时修改~/.npmrc

10.4. 编译

项目编译:

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

10.5. 启动服务

启动区块链浏览器服务:

cd blockchain-explorer
./start.sh

注:停止服务为在blockchain-explorer目录下执行./stop.sh。

10.6. 访问区块链浏览器服务

在浏览器访问区块链浏览器服务:http://10.252.79.17:8080/
在这里插入图片描述

11. 常见错误排查

11.1. grpc包安装有问题

在执行./start.sh之后服务并没有启动,检查日志发现无法加载grpc_node模块。
在这里插入图片描述
解决:

cd blockchain-explorer
npm rebuild --unsafe-perm
./start.sh

11.2. postgresql连接不上

在执行./start.sh之后服务并没有启动,检查日志发现数据库连接报错,报错信息如下:
db error { error: Ident authentication failed for user “hppoc”
解决方案:
(1)修改数据库权限配置:

/var/lib/pgsql/9.5/data/pg_hba.conf
修改之后的配置文件情况如下:
#"local" is for Unix domain socket connections only
local   all             all                                     trust
#IPv4 local connections:
host    all             all             127.0.0.1/32            trust
#IPv6 local connections:
host    all             all             ::1/128                 trust
#Allow replication connections from localhost, by a user with the
#replication privilege.
local   replication     postgres                                trust
host    replication     postgres        127.0.0.1/32            trust
host    replication     postgres        ::1/128                 trust

(2)重启数据库服务:

systemctl restart postgresql-9.5.service

11.3. npm install报错

在执行npm install时,报用户权限不足的错,报错信息如下:

gyp  WARNWARN  EACCESEACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/node-inspector/node_modules/v8-debug/.node-gyp"
 attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/node-inspector/node_modules/v8-debug/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/node-inspector/node_modules/v8-debug/.node-gyp/10.6.0"

解决方案:
安装的时候增加–unsafe-perm 参数即可

npm install -g --unsafe-perm

猜你喜欢

转载自blog.csdn.net/weixin_39304564/article/details/102753270