基于fabric1.4.2的区块链浏览器搭建

基于fabric1.4.2的blockchain-explorer搭建

环境准备

  • fabric 1.4.2
  • fabric-sample 1.4.2
  • blockchain-explorer 0.3.9.5

  • go 1.12.8 环境安装

下载安装包

在网址 https://studygolang.com/dl 下载压缩包之后解压提取到Ubuntu中

设置环境配置

vim /etc/profile

export GOROOT=/go

export GOPATH=/Go_WorkSpace

export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

source /etc/profile
使此修改的文件立即生效

go env -w GOPROXY=https://goproxy.cn,direct

  • nodejs 8.11.4 环境安装

安装nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

安装后重启该会话或重新开一个会话即可生效

查看当前支持的版本

nvm ls-remote

安装(同时安装npm)

nvm install 8.11.4

检查node.js安装版本

node -v

检查npm的安装版本

npm -v

切换源

npm install -g nrm

nrm ls

nrm use taobao

  • PostgreSQL 10.10 环境安装

apt install postgresql

  • Jq jq-1.5-1-a5b5cbe

apt install jq

  • docker 19.03.2 环境安装

官方安装脚本

curl -fsSL https://get.docker.com | bash -s docker —mirror Aliyun

配置Docker镜像站

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

sudo systemctl restart docker.service

  • docker-compose 1.24.1 环境安装

docker-compose安装

sudo apt-get install python-pip

sudo pip install docker-compose

查看版本

docker-compose -version

first-network搭建

编译工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
go get github.com/hyperledger/fabric

go get -u github.com/golang/protobuf/protoc-gen-go

cd $GOPATH/src/github.com/hyperledger/fabric

git checkout v1.4.2

sudo apt install libtool libltdl-dev

make release

cd release/linux-amd64 (bin文件下生成了一些必要的工具)

sudo cp -r bin /usr/local (移动到/usr/local下,全局使用)

cd ../..

mkdir -p .build/docker/gotools/

cp -r $GOPATH/bin .build/docker/gotools/

cp -r $GOPATH/src/github.com/hyperledger/fabric/release/linux-amd64/bin/ .build/docker/gotools/

启动网络

1
2
3
4
5
6
7
8
9
10
11
12
13
go get -u github.com/hyperledger/fabric-samples

cd $GOPATH/src/github.com/hyperledger/fabric-samples/

git checkout v1.4.2

cd first-network

./byfn.sh -m generate

./byfn.sh -m up

./byfn.sh -m down(TODO:清除所有容器和镜像,最后使用)

区块链浏览器运行实现

导入数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cd $GOPATH/src/github.com/hyperledger/blockchain-explorer

git checkout v0.3.9.5

cd app/persistence/fabric/postgreSQL

chmod +R 775 db/

cd db

./createdb.sh

cd $GOPATH/src/github.com/hyperledger/blockchain-explorer/app/platform/fabric/

vim config.json

将$GOPATH换成自己的路径,将organizations组织的sk证书文件名称换成自己的文件名称,保存退出

可参考以下配置信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{
"name": "first-network",
"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": {},
"peer1.org1.example.com": {},
"peer0.org2.example.com": {},
"peer1.org2.example.com": {}
},

"connection": {
"timeout": {
"peer": {
"endorser": "6000",
"eventHub": "6000",
"eventReg": "6000"
}
}
}
}
},
"organizations": {
"Org1": {
"mspid": "Org1MSP",
"fullpath": true,
"adminPrivateKey": {
"path": "$GOPATH/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/095dd549c6724c0280f1e22adf5216e09da2914c7491ec155b649cef85d960f8_sk"
},
"signedCert": {
"path": "$GOPATH/src/github.com/hyperledger/fabric-samples/first-network/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": "$GOPATH/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
},
"url": "grpcs://localhost:7051",
"eventUrl": "grpcs://localhost:7053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com"
}
},
"peer1.org1.example.com": {
"tlsCACerts": {
"path": "$GOPATH/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt"
},
"url": "grpcs://localhost:8051",
"eventUrl": "grpcs://localhost:8053",
"grpcOptions": {
"ssl-target-name-override": "peer1.org1.example.com"
}
},
"peer0.org2.example.com": {
"tlsCACerts": {
"path": "$GOPATH/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
},
"url": "grpcs://localhost:9051",
"eventUrl": "grpcs://localhost:9053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org2.example.com"
}
},
"peer1.org2.example.com": {
"tlsCACerts": {
"path": "$GOPATH/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt"
},
"url": "grpcs://localhost:10051",
"eventUrl": "grpcs://localhost:10053",
"grpcOptions": {
"ssl-target-name-override": "peer1.org2.example.com"
}
}
}
}

编译启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cd $GOPATH/src/github.com/hyperledger/blockchain-explorer

npm install

cd app/test

npm install

npm run test

cd ../../client/

rm package-lock.json

npm install

npm run test:ci -- -u --coverage

npm run build

连接终端

1
2
3
cd $GOPATH/src/github.com/hyperledger/blockchain-explorer

./start.sh

打开浏览器输入以下网址

http://localhost:8080/#/login

账号密码见config.json配置

深入浅出区块链 - 打造高质量区块链技术博客,学区块链都来这里,关注知乎微博 掌握区块链技术动态。

LBC-Team wechat
欢迎订阅公众号:深入浅出区块链技术
0%