(一)动机

查看Fabric区块链的状态。

虚拟机和peer节点在同一个机器或者不在同一个机器都行。

(二)虚拟机基础环境配置*

1、IP地址配置

配一个192.168.1.x上网用,配一个192.168.30.x与通信。

有可视化界面,就用可视化界面来配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# ping 192.168.30.2 测试可以接通节点
[root@localhost ~]# ping 192.168.30.2
PING 192.168.30.2 (192.168.30.2) 56(84) bytes of data.
64 bytes from 192.168.30.2: icmp_seq=1 ttl=64 time=0.731 ms
64 bytes from 192.168.30.2: icmp_seq=2 ttl=64 time=0.427 ms
64 bytes from 192.168.30.2: icmp_seq=3 ttl=64 time=0.500 ms
^C
--- 192.168.30.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 0.427/0.552/0.731/0.132 ms
[root@localhost ~]#
# ping www.baidu.com 测试可以上网
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (220.181.38.149) 56(84) bytes of data.
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=1 ttl=51 time=18.9 ms
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=2 ttl=51 time=18.6 ms
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=3 ttl=51 time=19.5 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 18.680/19.061/19.520/0.347 ms
[root@localhost ~]#

2、SSH

远程登录,传文件比较方便。

1
2
3
4
5
6
# 安装
yum install -y openssl openssh-server
# 启动ssh
systemctl start sshd.service
# 设置开机自动启动
systemctl enable sshd.service

3、防火墙

关闭防火墙,或者就开几个端口。

systemctl stop firewalld
systemctl status firewalld
systemctl disable firewalld

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2020-09-24 23:14:15 EDT; 37ms ago
Docs: man:firewalld(1)
Process: 786 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 786 (code=exited, status=0/SUCCESS)

Sep 24 23:13:23 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Sep 24 23:13:24 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Sep 24 23:14:14 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
Sep 24 23:14:15 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]#

4、设置时间同步

确保时间正常。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 移除本地时间
$ rm -rf /etc/localtime
# 修改时区
$ ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 设置系统时钟
$ echo "ZONE="Asia/Shanghai"
UTC=false
ARC=false">>/etc/sysconfig/clock
# 安装时间服务
$ yum install -y ntp
$ systemctl start ntpd
$ systemctl enable ntpd
# 时间同步指向阿里云时间服务器
$ echo "/usr/sbin/ntpdate ntp1.aliyun.com > /dev/null 2>&1; /sbin/hwclock -w">>/etc/rc.d/rc.local
# 定时任务,每分钟同步一次
$ echo "0 */1 * * * ntpdate ntp1.aliyun.com > /dev/null 2>&1; /sbin/hwclock -w">>/etc/cro
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
[root@localhost ~]#  rm -rf /etc/localtime
[root@localhost ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@localhost ~]# echo "ZONE="Asia/Shanghai"
> UTC=false
> ARC=false">>/etc/sysconfig/clock
[root@localhost ~]# yum install -y ntp
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.bfsu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-29.el7.centos.2 will be installed
--> Processing Dependency: ntpdate = 4.2.6p5-29.el7.centos.2 for package: ntp-4.2.6p5-29.el7.centos.2.x86_64
--> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-29.el7.centos.2.x86_64
--> Running transaction check
---> Package autogen-libopts.x86_64 0:5.18-5.el7 will be installed
---> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos will be updated
---> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
ntp x86_64 4.2.6p5-29.el7.centos.2 updates 549 k
Installing for dependencies:
autogen-libopts x86_64 5.18-5.el7 base 66 k
Updating for dependencies:
ntpdate x86_64 4.2.6p5-29.el7.centos.2 updates 87 k

Transaction Summary
===========================================================================================================
Install 1 Package (+1 Dependent package)
Upgrade ( 1 Dependent package)

Total download size: 701 k
Downloading packages:
No Presto metadata available for updates
warning: /var/cache/yum/x86_64/7/updates/packages/ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm is not installed
(1/3): ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm | 87 kB 00:00:00
Public key for autogen-libopts-5.18-5.el7.x86_64.rpm is not installed
(2/3): autogen-libopts-5.18-5.el7.x86_64.rpm | 66 kB 00:00:00
(3/3): ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm | 549 kB 00:00:00
-----------------------------------------------------------------------------------------------------------
Total 2.1 MB/s | 701 kB 00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-8.2003.0.el7.centos.x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : autogen-libopts-5.18-5.el7.x86_64 1/4
Updating : ntpdate-4.2.6p5-29.el7.centos.2.x86_64 2/4
Installing : ntp-4.2.6p5-29.el7.centos.2.x86_64 3/4
Cleanup : ntpdate-4.2.6p5-29.el7.centos.x86_64 4/4
Verifying : ntpdate-4.2.6p5-29.el7.centos.2.x86_64 1/4
Verifying : ntp-4.2.6p5-29.el7.centos.2.x86_64 2/4
Verifying : autogen-libopts-5.18-5.el7.x86_64 3/4
Verifying : ntpdate-4.2.6p5-29.el7.centos.x86_64 4/4

Installed:
ntp.x86_64 0:4.2.6p5-29.el7.centos.2

Dependency Installed:
autogen-libopts.x86_64 0:5.18-5.el7

Dependency Updated:
ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2

Complete!
[root@localhost ~]# systemctl start ntpd
[root@localhost ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@localhost ~]# echo "/usr/sbin/ntpdate ntp1.aliyun.com > /dev/null 2>&1; /sbin/hwclock -w">>/etc/rc.d/rc.local
[root@localhost ~]# echo "0 */1 * * * ntpdate ntp1.aliyun.com > /dev/null 2>&1; /sbin/hwclock -w">>/etc/cro
[root@localhost ~]#

5、安装常用工具

1
2
3
4
5
6
yum install -y curl \
wget \
tree \
lrzsz \
dos2unix \
git
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
[root@localhost ~]# yum install -y curl \
> wget \
> tree \
> lrzsz \
> dos2unix \
> git
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.tuna.tsinghua.edu.cn
Package wget-1.14-18.el7_6.1.x86_64 already installed and latest version
Package lrzsz-0.12.20-36.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package curl.x86_64 0:7.29.0-57.el7 will be updated
---> Package curl.x86_64 0:7.29.0-57.el7_8.1 will be an update
--> Processing Dependency: libcurl = 7.29.0-57.el7_8.1 for package: curl-7.29.0-57.el7_8.1.x86_64
---> Package dos2unix.x86_64 0:6.0.3-7.el7 will be installed
---> Package git.x86_64 0:1.8.3.1-23.el7_8 will be installed
--> Processing Dependency: perl-Git = 1.8.3.1-23.el7_8 for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl(Term::ReadKey) for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl(Git) for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl(Error) for package: git-1.8.3.1-23.el7_8.x86_64
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Running transaction check
---> Package libcurl.x86_64 0:7.29.0-57.el7 will be updated
---> Package libcurl.x86_64 0:7.29.0-57.el7_8.1 will be an update
---> Package perl-Error.noarch 1:0.17020-2.el7 will be installed
---> Package perl-Git.noarch 0:1.8.3.1-23.el7_8 will be installed
---> Package perl-TermReadKey.x86_64 0:2.30-20.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
dos2unix x86_64 6.0.3-7.el7 base 74 k
git x86_64 1.8.3.1-23.el7_8 updates 4.4 M
tree x86_64 1.6.0-10.el7 base 46 k
Updating:
curl x86_64 7.29.0-57.el7_8.1 updates 271 k
Installing for dependencies:
perl-Error noarch 1:0.17020-2.el7 base 32 k
perl-Git noarch 1.8.3.1-23.el7_8 updates 56 k
perl-TermReadKey x86_64 2.30-20.el7 base 31 k
Updating for dependencies:
libcurl x86_64 7.29.0-57.el7_8.1 updates 223 k

Transaction Summary
===========================================================================================================
Install 3 Packages (+3 Dependent packages)
Upgrade 1 Package (+1 Dependent package)

Total download size: 5.1 M
Downloading packages:
No Presto metadata available for updates
(1/8): dos2unix-6.0.3-7.el7.x86_64.rpm | 74 kB 00:00:00
(2/8): curl-7.29.0-57.el7_8.1.x86_64.rpm | 271 kB 00:00:01
(3/8): git-1.8.3.1-23.el7_8.x86_64.rpm | 4.4 MB 00:00:01
(4/8): libcurl-7.29.0-57.el7_8.1.x86_64.rpm | 223 kB 00:00:00
(5/8): perl-Git-1.8.3.1-23.el7_8.noarch.rpm | 56 kB 00:00:00
(6/8): perl-Error-0.17020-2.el7.noarch.rpm | 32 kB 00:00:01
(7/8): perl-TermReadKey-2.30-20.el7.x86_64.rpm | 31 kB 00:00:01
(8/8): tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00
-----------------------------------------------------------------------------------------------------------
Total 2.1 MB/s | 5.1 MB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : libcurl-7.29.0-57.el7_8.1.x86_64 1/10
Installing : 1:perl-Error-0.17020-2.el7.noarch 2/10
Installing : perl-TermReadKey-2.30-20.el7.x86_64 3/10
Installing : perl-Git-1.8.3.1-23.el7_8.noarch 4/10
Installing : git-1.8.3.1-23.el7_8.x86_64 5/10
Updating : curl-7.29.0-57.el7_8.1.x86_64 6/10
Installing : tree-1.6.0-10.el7.x86_64 7/10
Installing : dos2unix-6.0.3-7.el7.x86_64 8/10
Cleanup : curl-7.29.0-57.el7.x86_64 9/10
Cleanup : libcurl-7.29.0-57.el7.x86_64 10/10
Verifying : git-1.8.3.1-23.el7_8.x86_64 1/10
Verifying : dos2unix-6.0.3-7.el7.x86_64 2/10
Verifying : perl-TermReadKey-2.30-20.el7.x86_64 3/10
Verifying : 1:perl-Error-0.17020-2.el7.noarch 4/10
Verifying : curl-7.29.0-57.el7_8.1.x86_64 5/10
Verifying : tree-1.6.0-10.el7.x86_64 6/10
Verifying : libcurl-7.29.0-57.el7_8.1.x86_64 7/10
Verifying : perl-Git-1.8.3.1-23.el7_8.noarch 8/10
Verifying : curl-7.29.0-57.el7.x86_64 9/10
Verifying : libcurl-7.29.0-57.el7.x86_64 10/10

Installed:
dos2unix.x86_64 0:6.0.3-7.el7 git.x86_64 0:1.8.3.1-23.el7_8 tree.x86_64 0:1.6.0-10.el7

Dependency Installed:
perl-Error.noarch 1:0.17020-2.el7 perl-Git.noarch 0:1.8.3.1-23.el7_8
perl-TermReadKey.x86_64 0:2.30-20.el7

Updated:
curl.x86_64 0:7.29.0-57.el7_8.1

Dependency Updated:
libcurl.x86_64 0:7.29.0-57.el7_8.1

Complete!
[root@localhost ~]#

6、更换软件源

下载软件更快。

1
2
3
4
5
6
7
8
9
10
11
12
13
# 使用网易的镜像源
# 源存储目录
cd /etc/yum.repos.d/
# 更改名称进行备份
mv CentOS-Base.repo CentOS-Base.repo.ori
# 下载文件
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
# 更改名称
mv CentOS6-Base-163.repo CentOS-Base.repo
# 清理缓存
yum -y clean all
# 更新缓存
yum makecache
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
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.ori
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
--2020-09-25 11:18:45-- http://mirrors.163.com/.help/CentOS6-Base-163.repo
Resolving mirrors.163.com (mirrors.163.com)... 59.111.0.251
Connecting to mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2006 (2.0K) [application/octet-stream]
Saving to: ‘CentOS6-Base-163.repo’

100%[=================================================================>] 2,006 --.-K/s in 0s

2020-09-25 11:18:45 (296 MB/s) - ‘CentOS6-Base-163.repo’ saved [2006/2006]

[root@localhost yum.repos.d]# mv CentOS6-Base-163.repo CentOS-Base.repo
[root@localhost yum.repos.d]# yum -y clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/10): base/7/x86_64/filelists_db | 7.1 MB 00:00:01
(3/10): base/7/x86_64/other_db | 2.6 MB 00:00:00
(4/10): base/7/x86_64/primary_db | 6.1 MB 00:00:03
(5/10): extras/7/x86_64/filelists_db | 217 kB 00:00:05
(6/10): extras/7/x86_64/primary_db | 206 kB 00:00:05
(7/10): extras/7/x86_64/other_db | 124 kB 00:00:00
(8/10): updates/7/x86_64/filelists_db | 2.4 MB 00:00:00
(9/10): updates/7/x86_64/primary_db | 4.5 MB 00:00:00
(10/10): updates/7/x86_64/other_db | 318 kB 00:00:00
Metadata Cache Created
[root@localhost yum.repos.d]# cd ~
[root@localhost ~]#

7、更改hosts文件

设置默认域名、IP对应表。

vim /etc/hosts
192.168.30.2 orderer0.example.com
192.168.30.2 kafka0
192.168.30.2 zookeeper0
192.168.30.3 orderer1.example.com
192.168.30.3 kafka1
192.168.30.3 zookeeper1
192.168.30.4 orderer2.example.com
192.168.30.4 kafka2
192.168.30.4 zookeeper2
192.168.30.5 kafka3
192.168.30.6 peer0.org1.example.com
192.168.30.7 peer1.org1.example.com
192.168.30.8 peer0.org2.example.com
192.168.30.9 peer1.org2.example.com

(三)区块链浏览器相关配置

参考文献:

https://learnblockchain.cn/article/1420

https://blog.csdn.net/ory001/article/details/108360167

https://blog.csdn.net/drbinzhao/article/details/85953319

http://www.htsjk.com/postgresSQL/27622.html

1、blockchain-explorer

git clone https://gitee.com/ryou5416/blockchain-explorer.git

或者

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

(是把上边的数据备份了一份)

注意下载的位置:root用户的/usr/local。

这个位置要su postgres之后能访问到,不一定非得是这个位置。

1
2
3
4
5
6
7
8
9
10
11
12
[root@localhost ~]# cd /usr/local
[root@localhost local]# ls
bin blockchain-explorer etc games include lib lib64 libexec nodejs sbin share src
[root@localhost local]$ git clone https://github.com/CupsWen/blockchain-explorer.git
Cloning into 'blockchain-explorer'...
remote: Enumerating objects: 627, done.
remote: Counting objects: 100% (627/627), done.
remote: Compressing objects: 100% (481/481), done.
remote: Total 627 (delta 104), reused 627 (delta 104), pack-reused 0
Receiving objects: 100% (627/627), 14.66 MiB | 74.00 KiB/s, done.
Resolving deltas: 100% (104/104), done.
[root@localhost local]$

2、PostgreSQL

(1)安装PostgreSQL

开源数据库,用于存放区块链信息。

访问网址填写机器相关信息:https://www.postgresql.org/download/linux/redhat/

获得的安装命令如下所示:

1
2
3
4
5
6
7
8
# Install the repository RPM:
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install PostgreSQL:
yum install -y postgresql95-server
# Optionally initialize the database and enable automatic start:
/usr/pgsql-9.5/bin/postgresql95-setup initdb
systemctl enable postgresql-9.5
systemctl start postgresql-9.5

注意一定要在装完后,切换到/usr/local目录下,确认postgres用户可以访问。

1
2
3
4
5
6
[root@vm192168308 ~]# cd /usr/local
[root@vm192168308 local]# su postgres
bash-4.2$ ls
bin etc games go include lib lib64 libexec nodejs sbin share src
bash-4.2$ exit
[root@vm192168308 local]#
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
[root@localhost ~]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Loaded plugins: fastestmirror, langpacks
pgdg-redhat-repo-latest.noarch.rpm | 6.7 kB 00:00:00
Examining /var/tmp/yum-root-x32c48/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-repo-42.0-13.noarch
Marking /var/tmp/yum-root-x32c48/pgdg-redhat-repo-latest.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-redhat-repo.noarch 0:42.0-13 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
pgdg-redhat-repo noarch 42.0-13 /pgdg-redhat-repo-latest.noarch 11 k

Transaction Summary
===========================================================================================================
Install 1 Package

Total size: 11 k
Installed size: 11 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : pgdg-redhat-repo-42.0-13.noarch 1/1
Verifying : pgdg-redhat-repo-42.0-13.noarch 1/1

Installed:
pgdg-redhat-repo.noarch 0:42.0-13

Complete!
[root@localhost ~]# yum install -y postgresql95-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
pgdg-common | 2.9 kB 00:00:00
pgdg10 | 3.6 kB 00:00:00
pgdg11 | 3.6 kB 00:00:00
pgdg12 | 3.6 kB 00:00:00
pgdg13 | 3.6 kB 00:00:00
pgdg95 | 3.6 kB 00:00:00
pgdg96 | 3.6 kB 00:00:00
(1/13): pgdg11/7/x86_64/group_gz | 245 B 00:00:01
(2/13): pgdg12/7/x86_64/group_gz | 245 B 00:00:00
(3/13): pgdg10/7/x86_64/group_gz | 245 B 00:00:01
(4/13): pgdg-common/7/x86_64/primary_db | 134 kB 00:00:02
(5/13): pgdg13/7/x86_64/group_gz | 246 B 00:00:00
(6/13): pgdg13/7/x86_64/primary_db | 35 kB 00:00:00
(7/13): pgdg95/7/x86_64/group_gz | 249 B 00:00:00
(8/13): pgdg11/7/x86_64/primary_db | 268 kB 00:00:02
(9/13): pgdg96/7/x86_64/group_gz | 249 B 00:00:00
(10/13): pgdg95/7/x86_64/primary_db | 221 kB 00:00:00
(11/13): pgdg12/7/x86_64/primary_db | 134 kB 00:00:02
(12/13): pgdg96/7/x86_64/primary_db | 253 kB 00:00:02
(13/13): pgdg10/7/x86_64/primary_db | 262 kB 00:00:13
Resolving Dependencies
--> Running transaction check
---> Package postgresql95-server.x86_64 0:9.5.23-1PGDG.rhel7 will be installed
--> Processing Dependency: postgresql95-libs(x86-64) = 9.5.23-1PGDG.rhel7 for package: postgresql95-server-9.5.23-1PGDG.rhel7.x86_64
--> Processing Dependency: postgresql95(x86-64) = 9.5.23-1PGDG.rhel7 for package: postgresql95-server-9.5.23-1PGDG.rhel7.x86_64
--> Processing Dependency: postgresql95 = 9.5.23-1PGDG.rhel7 for package: postgresql95-server-9.5.23-1PGDG.rhel7.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql95-server-9.5.23-1PGDG.rhel7.x86_64
--> Running transaction check
---> Package postgresql95.x86_64 0:9.5.23-1PGDG.rhel7 will be installed
---> Package postgresql95-libs.x86_64 0:9.5.23-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
postgresql95-server x86_64 9.5.23-1PGDG.rhel7 pgdg95 4.1 M
Installing for dependencies:
postgresql95 x86_64 9.5.23-1PGDG.rhel7 pgdg95 1.3 M
postgresql95-libs x86_64 9.5.23-1PGDG.rhel7 pgdg95 225 k

Transaction Summary
===========================================================================================================
Install 1 Package (+2 Dependent packages)

Total download size: 5.7 M
Installed size: 24 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/pgdg95/packages/postgresql95-libs-9.5.23-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Public key for postgresql95-libs-9.5.23-1PGDG.rhel7.x86_64.rpm is not installed
(1/3): postgresql95-libs-9.5.23-1PGDG.rhel7.x86_64.rpm | 225 kB 00:00:04
(2/3): postgresql95-9.5.23-1PGDG.rhel7.x86_64.rpm | 1.3 MB 00:00:05
(3/3): postgresql95-server-9.5.23-1PGDG.rhel7.x86_64.rpm | 4.1 MB 00:00:06
-----------------------------------------------------------------------------------------------------------
Total 534 kB/s | 5.7 MB 00:00:10
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Importing GPG key 0x442DF0F8:
Userid : "PostgreSQL RPM Building Project <pgsqlrpms-hackers@pgfoundry.org>"
Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
Package : pgdg-redhat-repo-42.0-13.noarch (@/pgdg-redhat-repo-latest.noarch)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : postgresql95-libs-9.5.23-1PGDG.rhel7.x86_64 1/3
Installing : postgresql95-9.5.23-1PGDG.rhel7.x86_64 2/3
Installing : postgresql95-server-9.5.23-1PGDG.rhel7.x86_64 3/3
Verifying : postgresql95-9.5.23-1PGDG.rhel7.x86_64 1/3
Verifying : postgresql95-libs-9.5.23-1PGDG.rhel7.x86_64 2/3
Verifying : postgresql95-server-9.5.23-1PGDG.rhel7.x86_64 3/3

Installed:
postgresql95-server.x86_64 0:9.5.23-1PGDG.rhel7

Dependency Installed:
postgresql95.x86_64 0:9.5.23-1PGDG.rhel7 postgresql95-libs.x86_64 0:9.5.23-1PGDG.rhel7

Complete!
[root@localhost ~]# /usr/pgsql-9.5/bin/postgresql95-setup initdb
Initializing database ... OK

[root@localhost ~]# systemctl enable postgresql-9.5
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-9.5.service to /usr/lib/systemd/system/postgresql-9.5.service.
[root@localhost ~]# systemctl start postgresql-9.5
[root@localhost ~]#

(2)配置密码

上面只能表示这个数据库装上了。还需要进行一些设置。

修改数据用户postgres的密码

1
2
3
4
5
6
# 登录PostgreSQL 
sudo -u postgres psql
# 修改登录PostgreSQL密码
ALTER USER postgres WITH PASSWORD '123456789';
# 退出PostgreSQL客户端
\q

修改linux系统用户postgres的密码

1
2
3
4
5
# 删除用户postgres的密码
sudo passwd -d postgres
# 设置用户postgres的密码
sudo -u postgres passwd
# 系统提示输入新的密码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 密码123456
[root@localhost ~]# sudo -u postgres psql
could not change directory to "/root": Permission denied
psql (9.5.23)
Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD '123456789';
ALTER ROLE
postgres=# \q
# 密码hello123456
[root@localhost ~]# sudo passwd -d postgres
Removing password for user postgres.
passwd: Success
[root@localhost ~]# sudo -u postgres passwd
Changing password for user postgres.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]#

(3)配置实现远程访问

vim /var/lib/pgsql/9.5/data/postgresql.conf

// 监听任何地址访问,修改连接权限 59行

// listen_addresses = ‘localhost’ 改为 listen_addresses = ‘*’

// 启用密码验证 88行

// # password_encryption = on 改为 password_encryption = on

vim /var/lib/pgsql/9.5/data/pg_hba.conf

// 在文档末尾加上以下内容

// host all all 0.0.0.0/0 md5

// 重启服务

systemctl restart postgresql-9.5.service

3、Node

blockchain-explorer代码的执行环境。因为blockchain-explorer使用js写的。

下载地址:https://nodejs.org/dist/v10.19.0/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 下载安装包
wget https://nodejs.org/dist/v10.19.0/node-v10.19.0-linux-x64.tar.gz
# 解压
tar -C /usr/local -xzf node-v10.19.0-linux-x64.tar.gz
# 重命名
cd /usr/local
mv node-v10.19.0-linux-x64 nodejs
# 打开环境变量配置文件
vim /etc/profile
# 写入
export PATH=$PATH:/usr/local/nodejs/bin
# 更新
source /etc/profile
# 查看版本
node -v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@localhost ~]$ wget https://nodejs.org/dist/v10.19.0/node-v10.19.0-linux-x64.tar.gz
--2020-09-24 16:47:55-- https://nodejs.org/dist/v10.19.0/node-v10.19.0-linux-x64.tar.gz
Resolving nodejs.org (nodejs.org)... 104.20.23.46, 104.20.22.46, 2606:4700:10::6814:172e, ...
Connecting to nodejs.org (nodejs.org)|104.20.23.46|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 21262197 (20M) [application/gzip]
Saving to: ‘node-v10.19.0-linux-x64.tar.gz’

100%[======================================>] 21,262,197 804KB/s in 34s

2020-09-24 16:48:30 (619 KB/s) - ‘node-v10.19.0-linux-x64.tar.gz’ saved [21262197/21262197]

[root@localhost ~]# tar -C /usr/local -xzf node-v10.19.0-linux-x64.tar.gz
[root@localhost ~]# cd /usr/local
[root@localhost local]# mv node-v10.19.0-linux-x64 nodejs
[root@localhost local]# vim /etc/profile
[root@localhost local]# source /etc/profile
[root@localhost local]# node -v
v10.19.0
[root@localhost local]#

4、jq

一个解析数据的函数包,被blockchain-explorer所使用,版本号(jq.x86_64 0:1.6-2.el7 )。

1
2
3
4
5
6
# 安装EPEL源:
yum install epel-release
# 安装完EPEL源后,可以查看下jq包是否存在:
yum list jq
# 安装jq:
yum install jq
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
95
96
97
98
99
100
101
102
103
104
105
106
107
[root@localhost local]# yum install epel-release
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
epel-release noarch 7-11 extras 15 k

Transaction Summary
===========================================================================================================
Install 1 Package

Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-11.noarch.rpm | 15 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-11.noarch 1/1
Verifying : epel-release-7-11.noarch 1/1

Installed:
epel-release.noarch 0:7-11

Complete!
[root@localhost local]# yum list jq
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 6.3 kB 00:00:00
* epel: mirrors.tuna.tsinghua.edu.cn
epel | 4.7 kB 00:00:00
(1/3): epel/x86_64/group_gz | 95 kB 00:00:00
(2/3): epel/x86_64/updateinfo | 1.0 MB 00:00:01
(3/3): epel/x86_64/primary_db | 6.9 MB 00:00:03
Available Packages
jq.x86_64 1.6-2.el7 epel
[root@localhost local]# yum install jq
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* epel: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package jq.x86_64 0:1.6-2.el7 will be installed
--> Processing Dependency: libonig.so.5()(64bit) for package: jq-1.6-2.el7.x86_64
--> Running transaction check
---> Package oniguruma.x86_64 0:6.8.2-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
jq x86_64 1.6-2.el7 epel 167 k
Installing for dependencies:
oniguruma x86_64 6.8.2-1.el7 epel 181 k

Transaction Summary
===========================================================================================================
Install 1 Package (+1 Dependent package)

Total download size: 348 k
Installed size: 1.0 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/epel/packages/jq-1.6-2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Public key for jq-1.6-2.el7.x86_64.rpm is not installed
(1/2): jq-1.6-2.el7.x86_64.rpm | 167 kB 00:00:00
(2/2): oniguruma-6.8.2-1.el7.x86_64.rpm | 181 kB 00:00:00
-----------------------------------------------------------------------------------------------------------
Total 712 kB/s | 348 kB 00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
Userid : "Fedora EPEL (7) <epel@fedoraproject.org>"
Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
Package : epel-release-7-11.noarch (@extras)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : oniguruma-6.8.2-1.el7.x86_64 1/2
Installing : jq-1.6-2.el7.x86_64 2/2
Verifying : oniguruma-6.8.2-1.el7.x86_64 1/2
Verifying : jq-1.6-2.el7.x86_64 2/2

Installed:
jq.x86_64 0:1.6-2.el7

Dependency Installed:
oniguruma.x86_64 0:6.8.2-1.el7

Complete!
[root@localhost local]#

5、gcc-c++

npm install用到了。

pkcs11的编译。

yum install -y gcc-c++

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
[root@localhost local]# yum install -y gcc-c++
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* epel: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package gcc-c++.x86_64 0:4.8.5-39.el7 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-39.el7 for package: gcc-c++-4.8.5-39.el7.x86_64
--> Processing Dependency: gcc = 4.8.5-39.el7 for package: gcc-c++-4.8.5-39.el7.x86_64
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-39.el7 will be installed
--> Processing Dependency: cpp = 4.8.5-39.el7 for package: gcc-4.8.5-39.el7.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-39.el7.x86_64
---> Package libstdc++-devel.x86_64 0:4.8.5-39.el7 will be installed
--> Running transaction check
---> Package cpp.x86_64 0:4.8.5-39.el7 will be installed
---> Package glibc-devel.x86_64 0:2.17-307.el7.1 will be installed
--> Processing Dependency: glibc-headers = 2.17-307.el7.1 for package: glibc-devel-2.17-307.el7.1.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-307.el7.1.x86_64
--> Running transaction check
---> Package glibc-headers.x86_64 0:2.17-307.el7.1 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-307.el7.1.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-307.el7.1.x86_64
--> Running transaction check
---> Package kernel-headers.x86_64 0:3.10.0-1127.19.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
gcc-c++ x86_64 4.8.5-39.el7 base 7.2 M
Installing for dependencies:
cpp x86_64 4.8.5-39.el7 base 5.9 M
gcc x86_64 4.8.5-39.el7 base 16 M
glibc-devel x86_64 2.17-307.el7.1 base 1.1 M
glibc-headers x86_64 2.17-307.el7.1 base 689 k
kernel-headers x86_64 3.10.0-1127.19.1.el7 updates 9.0 M
libstdc++-devel x86_64 4.8.5-39.el7 base 1.5 M

Transaction Summary
===========================================================================================================
Install 1 Package (+6 Dependent packages)

Total download size: 42 M
Installed size: 84 M
Downloading packages:
(1/7): cpp-4.8.5-39.el7.x86_64.rpm | 5.9 MB 00:00:02
(2/7): gcc-4.8.5-39.el7.x86_64.rpm | 16 MB 00:00:02
(3/7): glibc-devel-2.17-307.el7.1.x86_64.rpm | 1.1 MB 00:00:00
(4/7): gcc-c++-4.8.5-39.el7.x86_64.rpm | 7.2 MB 00:00:01
(5/7): glibc-headers-2.17-307.el7.1.x86_64.rpm | 689 kB 00:00:00
(6/7): libstdc++-devel-4.8.5-39.el7.x86_64.rpm | 1.5 MB 00:00:00
(7/7): kernel-headers-3.10.0-1127.19.1.el7.x86_64.rpm | 9.0 MB 00:00:01
-----------------------------------------------------------------------------------------------------------
Total 9.2 MB/s | 42 MB 00:00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libstdc++-devel-4.8.5-39.el7.x86_64 1/7
Installing : kernel-headers-3.10.0-1127.19.1.el7.x86_64 2/7
Installing : glibc-headers-2.17-307.el7.1.x86_64 3/7
Installing : glibc-devel-2.17-307.el7.1.x86_64 4/7
Installing : cpp-4.8.5-39.el7.x86_64 5/7
Installing : gcc-4.8.5-39.el7.x86_64 6/7
Installing : gcc-c++-4.8.5-39.el7.x86_64 7/7
Verifying : glibc-headers-2.17-307.el7.1.x86_64 1/7
Verifying : glibc-devel-2.17-307.el7.1.x86_64 2/7
Verifying : gcc-c++-4.8.5-39.el7.x86_64 3/7
Verifying : cpp-4.8.5-39.el7.x86_64 4/7
Verifying : gcc-4.8.5-39.el7.x86_64 5/7
Verifying : kernel-headers-3.10.0-1127.19.1.el7.x86_64 6/7
Verifying : libstdc++-devel-4.8.5-39.el7.x86_64 7/7

Installed:
gcc-c++.x86_64 0:4.8.5-39.el7

Dependency Installed:
cpp.x86_64 0:4.8.5-39.el7 gcc.x86_64 0:4.8.5-39.el7
glibc-devel.x86_64 0:2.17-307.el7.1 glibc-headers.x86_64 0:2.17-307.el7.1
kernel-headers.x86_64 0:3.10.0-1127.19.1.el7 libstdc++-devel.x86_64 0:4.8.5-39.el7

Complete!
[root@localhost local]#

(四)blockchain-explorer配置

1、修改配置文件

(1)appconfig.json

文件所在路径:blockchain-explorer/appconfig.json。

文件功能:配置浏览器。

因为希望在别的机器也可以访问区块链浏览器,所以修改host中的localhost为本机IP:192.168.1.111。

sslEnabled:是否使用ssl。

sslCertsPath:ssl证书位置。

host:IP地址。

port:端口。

1
2
3
4
5
6
7
{
"sslEnabled": false,
"sslCertsPath": "ssl-certs",
"host": "192.168.1.111",
"port": "8080",
"license": "Apache-2.0"
}

(2)explorerconfig.json

文件所在路径:blockchain-explorer/app/explorerconfig.json。

文件功能:配置浏览器。

修改host、database、username、passwd为自己的设置。

persistence:保留数据的数据库。

platforms:平台,platforms下面的目录。

postgreSQL:数据库相关配置。

​ host:数据库IP。

​ port:数据库端口。

​ database:数据库名称。

​ username:数据库用户。

​ passwd:用户密码。

sync:异步同步数据设置。

​ type: 同步进程和Hyperledger Explorer 的关系。host不再一台主机、local在一台主机。

​ platform:平台,platforms下面的目录。

​ blocksSyncTime:异步同步时间。1s。

jwt:身份授权配置。

​ secret:用于签名消息载荷的密文。

​ expiresIn:过期事件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"persistence": "postgreSQL",
"platforms": ["fabric"],
"postgreSQL": {
"host": "192.168.1.111",
"port": "5432",
"database": "fabricexplorer",
"username": "cups",
"passwd": "123456789"
},
"sync": {
"type": "local",
"platform": "fabric",
"blocksSyncTime": "1"
},
"jwt": {
"secret": "a secret phrase!!",
"expiresIn": "2h"
}
}

(3)config.json

文件路径:blockchain-explorer/app/platform/fabric/config.json。

文件作用:网络配置文件,指向connection文件。

network-configs:网络。默认网络配置的集合,不能改变。

connection:网络名称。随意改,主要作用是用于区分不同网络。

name:网络名称。随意改,主要作用是用于区分不同网络。

profile:连接配置文件的路径。即将要建立连接文件路径。

1
2
3
4
5
6
7
8
9
{
"network-configs": {
"connection": {
"name": "connection",
"profile": "./connection-profile/connection.json"
}
},
"license": "Apache-2.0"
}

(4)证书

将架设区块链浏览器的组织的管理员证书复制到这台虚拟机上。

这里以组织1的管理员证书和peer0.org1.example.com的peer证书为例。

证书的路径:crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com

​ crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com

复制到本地虚拟机路径:/usr/local/crypto-config/Admin@org1.example.com

​ /usr/local/crypto-config/peer0.org1.example.com

采用SSH复制的方式,证书是前面kafka的证书。

现在关键证书的路径如下:

admin用户:

adminPrivateKey:/usr/local/crypto-config/Admin@org1.example.com/msp/keystore/1fd81eec726eb1474cb755da65deaef5426eb59f4b00bdf83d72b0615bae0a75_sk

signedCert:/usr/local/crypto-config/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem

peer01的TLS通信证书:

tlsCACerts:/usr/local/crypto-config/peer0.org1.example.com/tls/ca.crt

(5)connection.json

路径:blockchain-explorer/app/platform/fabric/connection-profile/connection.json。

作用:client使用连接配置文件,接入fabric网络。

vim connection.json

写入如下内容。

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
{
"name": "kafka",
"version": "1.0.0",
"client": {
"tlsEnable": true,
"adminCredential": {
"id": "cups",
"password": "123456"
},
"enableAuthentication": true,
"organization": "Org1MSP",
"connection": {
"timeout": {
"peer": {
"endorser": "300"
},
"orderer": "300"
}
}
},
"channels": {
"mychannel": {
"peers": {
"peer0.org1.example.com": {}
},
"connection": {
"timeout": {
"peer": {
"endorser": "6000",
"eventHub": "6000",
"eventReg": "6000"
}
}
}
}
},
"organizations": {
"Org1MSP": {
"mspid": "Org1MSP",
"adminPrivateKey": {
"path": "/usr/local/crypto-config/Admin@org1.example.com/msp/keystore/1fd81eec726eb1474cb755da65deaef5426eb59f4b00bdf83d72b0615bae0a75_sk"
},
"peers": ["peer0.org1.example.com"],
"signedCert": {
"path": "/usr/local/crypto-config/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem"
}
}
},
"peers": {
"peer0.org1.example.com": {
"tlsCACerts": {
"path": "/usr/local/crypto-config/peer0.org1.example.com/tls/ca.crt"
},
"url": "grpcs://peer0.org1.example.com:7051"
}
}
}

(6)start.sh

路径:blockchain-explorer/start.sh

作用:区块链浏览器启动入口。

之所以要修改,是想把一些配置信息写死了,免的回头忘记。

LOG_LEVEL_APP:APP日志级别。

LOG_LEVEL_DB:数据库日志级别。

LOG_LEVEL_CONSOLE:终端日志级别。

LOG_CONSOLE_STDOUT:中终端输出日志信息。

DISCOVERY_AS_LOCALHOST:peer节点是否在本地。===========>重点是要把这个设定为false。

start.sh的输出主要有:app、db、console。

我们上边设置export LOG_CONSOLE_STDOUT=true主要是为了直观的观察程序运行情况。

若不这么做,需要去blockchain-explorer/logs/console/console.log中不断查看比较麻烦。

1
2
3
4
5
6
7
8
9
10
11
echo "************************************************************************************"
echo "**************************** Hyperledger Explorer **********************************"
echo "************************************************************************************"

export LOG_LEVEL_APP=debug
export LOG_LEVEL_DB=debug
export LOG_LEVEL_CONSOLE=info
export LOG_CONSOLE_STDOUT=true
export DISCOVERY_AS_LOCALHOST=false

node main.js name - hyperledger-explorer &

2、初始化数据库

对数据库进行初始化。

主要是根据配置文件建立相关的东西。

数据库:fabricexplorer。

用户名:cups。

用户密码:123456789。

1
2
3
4
5
6
7
8
9
10
11
12
13
# 进入数据库初始化目录
cd blockchain-explorer/app/persistence/fabric/postgreSQL/db
# 赋予权限
chmod 755 -R ./*
# 进入postgres
su postgres
# 执行初始化脚本
./createdb.sh
# ctrl+D退出
# 查看数据库
sudo -u postgres psql fabricexplorer -c '\d'
# 一定要记住(20 rows),不然就是少创建了数据库。
# 不同的版本数据库结构不一样,这个是20。
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

[root@localhost db]# su postgres
bash-4.2$ ./createdb.sh
Copying ENV variables into temp file...
USER="cups"
DATABASE="fabricexplorer"
PASSWD='123456789'
Executing SQL scripts, OS=linux-gnu
psql:./explorerpg.sql:6: ERROR: role "cups" already exists
DROP DATABASE
CREATE DATABASE
You are now connected to database "fabricexplorer" as user "postgres".
psql:./explorerpg.sql:15: NOTICE: table "blocks" does not exist, skipping
DROP TABLE
CREATE TABLE
ALTER TABLE
psql:./explorerpg.sql:37: NOTICE: table "chaincodes" does not exist, skipping
DROP TABLE
CREATE TABLE
ALTER TABLE
ALTER SEQUENCE
psql:./explorerpg.sql:57: NOTICE: table "peer_ref_chaincode" does not exist, skipping
DROP TABLE
CREATE TABLE
ALTER TABLE
psql:./explorerpg.sql:74: NOTICE: table "channel" does not exist, skipping
DROP TABLE
CREATE TABLE
ALTER TABLE
ALTER SEQUENCE
psql:./explorerpg.sql:99: NOTICE: table "peer" does not exist, skipping
DROP TABLE
CREATE TABLE
ALTER TABLE
psql:./explorerpg.sql:120: NOTICE: table "peer_ref_channel" does not exist, skipping
DROP TABLE
CREATE TABLE
ALTER TABLE
psql:./explorerpg.sql:137: NOTICE: table "orderer" does not exist, skipping
DROP TABLE
CREATE TABLE
ALTER TABLE
psql:./explorerpg.sql:155: NOTICE: table "transactions" does not exist, skipping
DROP TABLE
CREATE TABLE
ALTER TABLE
ALTER SEQUENCE
psql:./explorerpg.sql:190: NOTICE: table "users" does not exist, skipping
DROP TABLE
CREATE TABLE
ALTER TABLE
psql:./explorerpg.sql:208: NOTICE: table "write_lock" does not exist, skipping
DROP TABLE
CREATE TABLE
ALTER TABLE
ALTER SEQUENCE
psql:./explorerpg.sql:217: NOTICE: index "blocks_blocknum_idx" does not exist, skipping
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:221: NOTICE: index "blocks_channel_genesis_hash_idx" does not exist, skipping
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:225: NOTICE: index "blocks_createdt_idx" does not exist, skipping
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:229: NOTICE: index "transaction_txhash_idx" does not exist, skipping
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:233: NOTICE: index "transaction_channel_genesis_hash_idx" does not exist, skipping
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:237: NOTICE: index "transaction_createdt_idx" does not exist, skipping
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:241: NOTICE: index "transaction_blockid_idx" does not exist, skipping
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:245: NOTICE: index "transaction_chaincode_proposal_input_idx" does not exist, skipping
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:250: NOTICE: index "channel_channel_genesis_hash_idx" does not exist, skipping
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:254: NOTICE: index "channel_channel_hash_idx" does not exist, skipping
DROP INDEX
CREATE INDEX
GRANT
You are now connected to database "fabricexplorer" as user "postgres".
bash-4.2$ exit
[root@localhost db]# sudo -u postgres psql fabricexplorer -c '\d'
List of relations
Schema | Name | Type | Owner
--------+---------------------------+----------+-------
public | blocks | table | cups
public | blocks_id_seq | sequence | cups
public | chaincodes | table | cups
public | chaincodes_id_seq | sequence | cups
public | channel | table | cups
public | channel_id_seq | sequence | cups
public | orderer | table | cups
public | orderer_id_seq | sequence | cups
public | peer | table | cups
public | peer_id_seq | sequence | cups
public | peer_ref_chaincode | table | cups
public | peer_ref_chaincode_id_seq | sequence | cups
public | peer_ref_channel | table | cups
public | peer_ref_channel_id_seq | sequence | cups
public | transactions | table | cups
public | transactions_id_seq | sequence | cups
public | users | table | cups
public | users_id_seq | sequence | cups
public | write_lock | table | cups
public | write_lock_write_lock_seq | sequence | cups
(20 rows)

[root@localhost db]#

3、安装blockchain-explorer需要的库

nodejs项目需要下载安装函数库都是提前写在在文件下的package.json文件里。

安装时使用npm install进行安装。

下面安装项目需要的软件包。

注意一定要获取管理员权限(sudo su),不然node-pre-gyp那部分过不去。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 切换到blockchain-explorer目录
cd blockchain-explorer
# 赋予权限(主要目的是为可以执行的文件赋权)
chmod 755 -R ./*
# 获取管理员权限
sudo su
# 更新/etc/profile
source /etc/profile
# 安装函数包
npm install
# 切换到app/test(项目ui和数据存储测试部分)
cd app/test
# 安装函数包
npm install
# 进行测试
npm run test
# 切换到blockchain-explorer/client/(客户端部分,负责监听数据,并进行同步)
cd ../../client
# 安装函数包
npm install
# 打包项目
npm run build

这个过程,时间很长请耐心等待。

下载的项目文件中有package-lock.json。

这个包是和package.json一起使用的:package.json说明需要哪些函数包;package-lock.json指明去哪里下载这些函数包以及函数包的版本。

不同的机器之间需要下载的函数版本可能不同,这是由npm自行搜索的。比如ubuntu和centos7的package-lock.json就不同。如果采用https://github.com/CupsWen/blockchain-explorer.git,里边包含的是centos7下的函数包下载地。如果采用的是其他型号的系统,请把package-lock.json(3个)删除,再使用npm install。

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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
[root@localhost local]# cd blockchain-explorer/
[root@localhost blockchain-explorer]# sudo su
[root@localhost blockchain-explorer]# source /etc/profile
[root@localhost blockchain-explorer]# npm install
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated

> bufferutil@4.0.1 install /usr/local/blockchain-explorer/node_modules/bufferutil
> node-gyp-build


> pkcs11js@1.0.22 install /usr/local/blockchain-explorer/node_modules/pkcs11js
> node-gyp rebuild

make: Entering directory `/usr/local/blockchain-explorer/node_modules/pkcs11js/build'
CXX(target) Release/obj.target/pkcs11/src/main.o
CXX(target) Release/obj.target/pkcs11/src/dl.o
CXX(target) Release/obj.target/pkcs11/src/const.o
CXX(target) Release/obj.target/pkcs11/src/pkcs11/error.o
CXX(target) Release/obj.target/pkcs11/src/pkcs11/v8_convert.o
CXX(target) Release/obj.target/pkcs11/src/pkcs11/template.o
CXX(target) Release/obj.target/pkcs11/src/pkcs11/mech.o
CXX(target) Release/obj.target/pkcs11/src/pkcs11/param.o
CXX(target) Release/obj.target/pkcs11/src/pkcs11/param_aes.o
CXX(target) Release/obj.target/pkcs11/src/pkcs11/param_rsa.o
CXX(target) Release/obj.target/pkcs11/src/pkcs11/param_ecdh.o
CXX(target) Release/obj.target/pkcs11/src/pkcs11/pkcs11.o
CXX(target) Release/obj.target/pkcs11/src/async.o
CXX(target) Release/obj.target/pkcs11/src/node.o
SOLINK_MODULE(target) Release/obj.target/pkcs11.node
COPY Release/pkcs11.node
make: Leaving directory `/usr/local/blockchain-explorer/node_modules/pkcs11js/build'

> utf-8-validate@5.0.2 install /usr/local/blockchain-explorer/node_modules/utf-8-validate
> node-gyp-build


> bcrypt@5.0.0 install /usr/local/blockchain-explorer/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
[bcrypt] Success: "/usr/local/blockchain-explorer/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" is installed via remote

> grpc@1.24.3 install /usr/local/blockchain-explorer/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library

node-pre-gyp WARN Using request for node-pre-gyp https download
[grpc] Success: "/usr/local/blockchain-explorer/node_modules/grpc/src/node/extension_binary/node-v64-linux-x64-glibc/grpc_node.node" is installed via remote

> husky@0.14.3 install /usr/local/blockchain-explorer/node_modules/husky
> node ./bin/install.js

husky
setting up Git hooks
done


> core-js-pure@3.6.5 postinstall /usr/local/blockchain-explorer/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> protobufjs@6.10.1 postinstall /usr/local/blockchain-explorer/node_modules/protobufjs
> node scripts/postinstall


> ejs@2.7.4 postinstall /usr/local/blockchain-explorer/node_modules/ejs
> node ./postinstall.js

Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN eslint-config-airbnb@17.1.1 requires a peer of eslint@^4.19.1 || ^5.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-import@2.22.0 requires a peer of eslint@^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-jsx-a11y@6.3.1 requires a peer of eslint@^3 || ^4 || ^5 || ^6 || ^7 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-react@7.21.2 requires a peer of eslint@^3 || ^4 || ^5 || ^6 || ^7 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-spellcheck@0.0.11 requires a peer of eslint@>=0.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-config-airbnb-base@13.2.0 requires a peer of eslint@^4.19.1 || ^5.3.0 but none is installed. You must install peer dependencies yourself.

added 713 packages from 575 contributors and audited 716 packages in 60.908s

28 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities

[root@localhost blockchain-explorer]# cd app/test
[root@localhost test]# npm install
npm WARN hyperledger-explorer-test@0.3.9 No repository field.

added 341 packages from 1086 contributors and audited 341 packages in 24.425s

22 packages are looking for funding
run `npm fund` for details

found 1 low severity vulnerability
run `npm audit fix` to fix them, or `npm audit` for details
[root@localhost test]# npm run test

> hyperledger-explorer-test@0.3.9 test /usr/local/blockchain-explorer/app/test
> nyc mocha *.js --exit



GET /api/blockactivity/:channel_genesis_hash
✓ should return blockactivity

GET /api/blockAndTxList/:channel/:blocknum
✓ should return blockandtx

GET /api/block/:channel_genesis_hash/:number
✓ should return block

GET /api/blocksByHour/:channel_genesis_hash/:day
✓ should return blockbyhour

GET /api/blocksByMinute/:channel_genesis_hash/:hour
✓ should return blockbyminute

GET /api/block/transactions/:channel_genesis_hash/:number
✓ should return blocktransaction

GET /api/chaincode/:channel
✓ should return chaincode

GET /api/changeChannel/:channelName
✓ should return changedchannel

GET /api/channels/info
✓ should return channelsinfo

GET /api/channels/
✓ should return channels

GET /api/curChannel
✓ should return currentchannel

dateUtils().toUTCmilliseconds
✓ dateUtils.toUTCmilliseconds should be not null

POST /auth/enroll/
✓ should return enroll

POST /auth/login
✓ should return login

GET /auth/networklist
✓ should return networklist

GET /api/peer/channel
✓ should return peers

Test explorerpg.sql for DDL statements syntax verification
✓ should read the file explorerpg.sql for ddl statements
TAP version 13
# Test Results
# Test completed and Temporary database deleted
✓ should execute statements successfully in explorerpg.sql file

POST /auth/register/
✓ should return register

requestutils().orgsArrayToString should return empty string
✓ requestutils().orgsArrayToString should return empty string

requestutils().orgsArrayToString should return single quotes value
✓ requestutils().orgsArrayToString should return single quotes value

requestutils().orgsArrayToString should return comma separated single quotes values
✓ requestutils().orgsArrayToString should return comma separated single quotes values

GET api/status/:channel_genesis_hash
✓ should return channel status

getLogger()
✓ should getLogger()

GET /api/transaction/:channel_genesis_hash/:txid
✓ should return transaction

GET /api/txByHour/:channel_genesis_hash/:day
✓ should return txbyhour

GET /api/txByMinute/:channel_genesis/:hour
✓ should return txbyminute

GET /api/txByOrg/:channel
✓ should return txbyorg


28 passing (86ms)


1..0
# tests 0
# pass 0

# ok

[root@localhost test]# cd ../../client
[root@localhost client]# npm install

> fibers_node_v8@3.1.5 preinstall /usr/local/blockchain-explorer/client/node_modules/fibers_node_v8
> node preinstall.js


> fibers@4.0.3 install /usr/local/blockchain-explorer/client/node_modules/fibers
> node build.js || nodejs build.js

`linux-x64-64-glibc` exists; testing
Problem with the binary; manual build incoming
make: Entering directory `/usr/local/blockchain-explorer/client/node_modules/fibers/build'
CXX(target) Release/obj.target/fibers/src/fibers.o
CXX(target) Release/obj.target/fibers/src/coroutine.o
CC(target) Release/obj.target/fibers/src/libcoro/coro.o
SOLINK_MODULE(target) Release/obj.target/fibers.node
COPY Release/fibers.node
make: Leaving directory `/usr/local/blockchain-explorer/client/node_modules/fibers/build'
Installed in `/usr/local/blockchain-explorer/client/node_modules/fibers/bin/linux-x64-64-glibc/fibers.node`

> fibers_node_v8@3.1.5 install /usr/local/blockchain-explorer/client/node_modules/fibers_node_v8
> node build.js

ignore install

> core-js@2.6.11 postinstall /usr/local/blockchain-explorer/client/node_modules/babel-runtime/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js-pure@3.6.5 postinstall /usr/local/blockchain-explorer/client/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js@3.6.5 postinstall /usr/local/blockchain-explorer/client/node_modules/react-app-polyfill/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js@2.6.11 postinstall /usr/local/blockchain-explorer/client/node_modules/react-tree-graph/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js@2.6.11 postinstall /usr/local/blockchain-explorer/client/node_modules/recharts/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> ejs@3.1.3 postinstall /usr/local/blockchain-explorer/client/node_modules/ejs
> node --harmony ./postinstall.js

Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)


> jss@9.8.7 postinstall /usr/local/blockchain-explorer/client/node_modules/jss
> node -e "console.log('\u001b[35m\u001b[1mLove JSS? You can now support us on open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/jss/donate\u001b[0m')"

Love JSS? You can now support us on open collective:
> https://opencollective.com/jss/donate

> sinon@4.5.0 postinstall /usr/local/blockchain-explorer/client/node_modules/sinon
> node scripts/support-sinon.js

Have some ❤️ for Sinon? You can support the project via Open Collective:
> https://opencollective.com/sinon/donate

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/jest-haste-map/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 2112 packages from 1462 contributors and audited 2120 packages in 70.605s

80 packages are looking for funding
run `npm fund` for details

found 6 low severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
[root@localhost client]# npm run build

> hyperledger-explorer-client@1.1.2 build /usr/local/blockchain-explorer/client
> react-scripts build

Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

418.09 KB build/static/js/2.ff5333c4.chunk.js
39.88 KB build/static/css/2.4aa0fea1.chunk.css
30.41 KB build/static/js/main.52072528.chunk.js
1005 B build/static/css/main.cf67b53d.chunk.css
787 B build/static/js/runtime-main.16fb02ed.js

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

npm install -g serve
serve -s build

Find out more about deployment here:

bit.ly/CRA-deploy

[root@localhost client]#

4、启动项目

程序入口是start.sh

路径:blockchain-explorer/start.sh

作用:区块链浏览器启动入口。

1
2
3
4
# 回到blockchain-explorer目录
cd ..
# 启动程序
./start.sh
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
[root@localhost blockchain-explorer]# ./start.sh 
************************************************************************************
**************************** Hyperledger Explorer **********************************
************************************************************************************
[root@localhost blockchain-explorer]# [2020-09-25T16:05:43.815] [INFO] PgService - SSL to Postgresql disabled
[2020-09-25T16:05:43.816] [INFO] PgService - connecting to Postgresql postgres://cups:******@192.168.1.111:5432/fabricexplorer
[2020-09-25T16:05:44.638] [INFO] Platform - network_config.id kafka_default network_config.profile ./connection-profile/connection.json
[2020-09-25T16:05:44.749] [INFO] FabricConfig - config.client.tlsEnable true
[2020-09-25T16:05:44.750] [INFO] FabricConfig - FabricConfig, this.config.channels mychannel
[2020-09-25T16:05:44.753] [INFO] FabricGateway - enrollUserIdentity: userName : cups
[2020-09-25T16:05:45.029] [INFO] FabricUtils - generateBlockHash 0
[2020-09-25T16:05:45.032] [INFO] Platform - initializeListener, network_id, network_client kafka_default { name: 'kafka',
version: '1.0.0',
client:
{ tlsEnable: true,
adminCredential: { id: 'cups', password: '123456' },
enableAuthentication: true,
organization: 'Org1MSP',
connection: { timeout: [Object] } },
channels: { mychannel: { peers: [Object], connection: [Object] } },
organizations:
{ Org1MSP:
{ mspid: 'Org1MSP',
adminPrivateKey: [Object],
peers: [Array],
signedCert: [Object] } },
peers:
{ 'peer0.org1.example.com':
{ tlsCACerts: [Object],
url: 'grpcs://peer0.org1.example.com:7051' } } }
[2020-09-25T16:05:45.041] [INFO] main - Please open web browser to access :http://localhost:8080/
[2020-09-25T16:05:45.041] [INFO] main - pid is 3546
[2020-09-25T16:05:45.246] [INFO] PgService - SSL to Postgresql disabled
[2020-09-25T16:05:45.247] [INFO] PgService - connecting to Postgresql postgres://cups:******@192.168.1.111:5432/fabricexplorer
[2020-09-25T16:05:45.843] [INFO] Synchronizer - initialize : 60
[2020-09-25T16:05:45.844] [INFO] SyncPlatform - Sync process is started for the network : [kafka_default] and client : [kafka_default]
[2020-09-25T16:05:45.845] [INFO] FabricConfig - config.client.tlsEnable true
[2020-09-25T16:05:45.845] [INFO] FabricConfig - FabricConfig, this.config.channels mychannel
[2020-09-25T16:05:46.127] [INFO] FabricUtils - generateBlockHash 0
[2020-09-25T16:05:46.136] [INFO] SyncServices - SyncServices.synchNetworkConfigToDB client kafka_default channel_name mychannel
[2020-09-25T16:05:46.145] [INFO] FabricUtils - generateBlockHash 0
[2020-09-25T16:05:46.245] [INFO] FabricClient - Discovered Org1MSP [ { mspid: 'Org1MSP',
endpoint: 'peer0.org1.example.com:7051',
name: 'peer0.org1.example.com:7051',
ledgerHeight: Long { low: 7, high: 0, unsigned: true },
chaincodes: [ [Object] ] } ]
[2020-09-25T16:05:46.257] [INFO] FabricGateway - queryInstantiatedChaincodes mychannel
[2020-09-25T16:05:46.270] [INFO] Sync - Synchronizer pid is 3561
[2020-09-25T16:05:46.290] [INFO] FabricEvent - Successfully created channel event hub for [mychannel]
[2020-09-25T16:05:46.293] [INFO] FabricUtils - generateBlockHash 1
[2020-09-25T16:05:46.305] [INFO] SyncServices - block_row.blocknum 1
[2020-09-25T16:05:46.310] [INFO] FabricUtils - generateBlockHash 2
[2020-09-25T16:05:46.314] [INFO] SyncServices - block_row.blocknum 2
[2020-09-25T16:05:46.317] [INFO] FabricUtils - generateBlockHash 3
[2020-09-25T16:05:46.321] [INFO] SyncServices - block_row.blocknum 3
[2020-09-25T16:05:46.324] [INFO] FabricUtils - generateBlockHash 4
[2020-09-25T16:05:46.331] [INFO] SyncServices - block_row.blocknum 4
[2020-09-25T16:05:46.333] [INFO] FabricUtils - generateBlockHash 5
[2020-09-25T16:05:46.338] [INFO] SyncServices - block_row.blocknum 5
[2020-09-25T16:05:46.340] [INFO] FabricUtils - generateBlockHash 6
[2020-09-25T16:05:46.344] [INFO] SyncServices - block_row.blocknum 6

当输出main - Please open web browser to access :http://localhost:8080/,且程序不自动退出时。

表明程序运行成功。http://localhost:8080/

5、执行结果

6、结束程序

ctrl+c不会导致程序结束。正确的结束方式是运行./stop.sh。

1
2
3
4
5
6
7
8
[root@localhost blockchain-explorer]# ./stop.sh 
Stopping node process hyperledger-explorer, id 3546
[2020-09-25T16:35:34.450] [INFO] main - Received kill signal, shutting down gracefully
[root@localhost blockchain-explorer]# [2020-09-25T16:35:34.453] [INFO] Platform - <<<<<<<<<<<<<<<<<<<<<<<<<< Closing explorer >>>>>>>>>>>>>>>>>>>>>
[2020-09-25T16:35:34.454] [INFO] main - Closed out connections
[2020-09-25T16:35:34.455] [INFO] Sync - <<<<<<<<<<<<<<<<<<<<<<<<<< Closing client processor >>>>>>>>>>>>>>>>>>>>>
^C
[root@localhost blockchain-explorer]#

7、修改start.sh*

区块链浏览器正常启动起来了。

可以设置export LOG_CONSOLE_STDOUT=false,毕竟日志在眼前一直跳,也不是很舒服。

(五)过程

1、辛苦的过程

blockchain-explorer有两种方式把它架起来:

1、使用github上下载的代码。

2、使用镜像。

(1)使用github上下载的代码

默认会考虑,blockchain-explorer代码版本、nodejs和Fabric的对应关系。

毫无疑问会选择:

Fabric===================>1.4.0==========>上一篇文章里边已经定了

blockchain-explorer========>v0.3.9.4

nodejs===================>v8.11.x========>v8.11.1

然而,多次尝试,错误频出,且难以排错。

例如:(1)初始化数据库的代码无法运行。(`皿´)ノ==================>权限问题;手动生成。

​ (2)nodejs正常引用函数包都会出现问题。 (`皿´)ノ============>npm打包不成功。

​ (3)数据库解析出现异常。(`皿´)ノ=========================>数据库创建不全。

​ (4)start.sh中的空行都要报错。(`皿´)ノ=====================>???????????????。

相关文章: https://learnblockchain.cn/article/1420

(2)使用镜像

相关文章:https://blog.csdn.net/ory001/article/details/108360167

使用镜像的基本原理就是,准备好相关文件挂载到镜像的相关位置,然后就不能够被我们所控制了。

按照上边的文章进行操作,启动起来的镜像也是出现各种问题,且无法解决,因为除了相关配置文件,其他的想管都管不了。

例如:(1)证书路径中出现/fabric-path/,导致无法正确找到证书。(`皿´)ノ

​ (2)无法连接数据库。(`皿´)ノ

​ (3)端口被占用。(`皿´)ノ

​ (4)出现frist-network,这个东西我们根本没设置。(`皿´)ノ

(3)本次成功纯属巧合

万般无奈之下使用(2)中的项目文件,配置一下基本信息,居然把blockchain-explorer起起来了。

(ubuntu)系统下。

总结ubuntu系统下成功的案例:确定各部分的版本;相关问题的解决方法;大胆尝试。

最终如上所示。

2、数据库初始化

数据库的初始化。上边的方法是完美的。

为避免经历浪费,还是想记录一下手动创建的过程。

下面是手动创建的结果。

官方的数据库初始化,实际上是很难一步完成的。

1、postgres的安装会生成一个用户postgres,它权限不高无法加载当前路径下的文件。

2、./createdb.sh的执行也经常出现问题。

3、如果在一个普通用户下装postgres,则更没有权限访问root用户下的目录。

4、有待尝试:root用户装postgres,普通用户下载blockchain-explorer进行初始化。

这个操作的主要作用是用是使用explorerpg.sql对数据库进行配置。

explorerpg.sql进行修改后内容如下。(替换:user为cups,对创建用户、数据库的部分进行了注释)。

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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
--
-- SPDX-License-Identifier: Apache-2.0
--
-- CREATE USER cups
-- WITH PASSWORD 123456789;
-- DROP DATABASE IF EXISTS fabricexplorer;
-- CREATE DATABASE fabricexplorer owner cups;
-- \c fabricexplorer;
--

-- ----------------------------
-- 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,
blksize integer DEFAULT NULL,
network_name varchar(255)
);

ALTER table blocks owner to cups;

-- ----------------------------
-- 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,
channel_genesis_hash character varying(256) DEFAULT NULL,
txcount integer DEFAULT 0,
createdt Timestamp DEFAULT NULL,
network_name varchar(255)
);

ALTER table chaincodes owner to cups;
Alter sequence chaincodes_id_seq restart with 10;

-- ---------------------------
-- Table structure for `peer_ref_chaincode`
-- ----------------------------
DROP TABLE IF EXISTS peer_ref_chaincode;

CREATE TABLE peer_ref_chaincode
(
id SERIAL PRIMARY KEY,
peerid varchar(256) DEFAULT NULL,
chaincodeid varchar(255) DEFAULT NULL,
cc_version varchar(255) DEFAULT NULL,
channelid character varying(256) DEFAULT NULL,
createdt Timestamp DEFAULT NULL,
network_name varchar(255)
);
ALTER table peer_ref_chaincode owner to cups;

-- ----------------------------
-- Table structure for `channel`
-- ----------------------------
DROP TABLE IF EXISTS channel;

-- state character(1) NOT NULL DEFAULT A CHECK (state in (A, D, S))

CREATE TABLE channel
(
id SERIAL PRIMARY KEY,
name varchar(256) DEFAULT NULL,
blocks integer DEFAULT NULL,
trans integer DEFAULT NULL,
createdt Timestamp DEFAULT NULL,
channel_genesis_hash character varying(256) DEFAULT NULL,
channel_hash character varying(256) DEFAULT NULL,
channel_config bytea default NULL,
channel_block bytea DEFAULT NULL,
channel_tx bytea DEFAULT NULL,
channel_version character varying(256) DEFAULT NULL,
network_name varchar(255)
);

ALTER table channel owner to cups;
Alter sequence channel_id_seq restart with 3;
-- ----------------------------
-- Table structure for `peer`
-- ----------------------------
DROP TABLE IF EXISTS peer;

-- state character(1) NOT NULL DEFAULT A CHECK (state in (A, D, S))

CREATE TABLE peer
(
id SERIAL PRIMARY KEY,
org integer DEFAULT NULL,
channel_genesis_hash character varying(256) DEFAULT NULL,
mspid varchar(256) DEFAULT NULL,
requests varchar(256) DEFAULT NULL,
events varchar(256) DEFAULT NULL,
server_hostname varchar(256) DEFAULT NULL,
createdt timestamp DEFAULT NULL,
peer_type character varying(256) DEFAULT NULL,
network_name varchar(255)
);
ALTER table peer owner to cups;
-- ---------------------------
-- Table structure for `peer_ref_channel`
-- ----------------------------
DROP TABLE IF EXISTS peer_ref_channel;

CREATE TABLE peer_ref_channel
(
id SERIAL PRIMARY KEY,
createdt Timestamp DEFAULT NULL,
peerid varchar(256),
channelid character varying(256),
peer_type character varying(256) DEFAULT NULL,
network_name varchar(255)
);
ALTER table peer_ref_channel owner to cups;

-- ====================Orderer BE-303=====================================
-- ----------------------------
-- Table structure for `orderer`
-- ----------------------------
DROP TABLE IF EXISTS orderer;

-- state character(1) NOT NULL DEFAULT A CHECK (state in (A, D, S))

CREATE TABLE orderer
(
id SERIAL PRIMARY KEY,
requests varchar(256) DEFAULT NULL,
server_hostname varchar(256) DEFAULT NULL,
createdt timestamp DEFAULT NULL,
network_name varchar(255)
);
ALTER table orderer owner to cups;

--// ====================Orderer BE-303=====================================
-- ----------------------------
-- Table structure for `transactions`
-- ----------------------------
DROP TABLE IF EXISTS transactions;
CREATE TABLE transactions
(
id SERIAL PRIMARY KEY,
blockid integer DEFAULT NULL,
txhash character varying(256) DEFAULT NULL,
createdt timestamp DEFAULT NULL,
chaincodename character varying(255) DEFAULT NULL,
status integer DEFAULT NULL,
creator_msp_id character varying(256) DEFAULT NULL,
endorser_msp_id character varying(800) DEFAULT NULL,
chaincode_id character varying(256) DEFAULT NULL,
type character varying(256) DEFAULT NULL,
read_set json default NULL,
write_set json default NULL,
channel_genesis_hash character varying(256) DEFAULT NULL,
validation_code character varying(255) DEFAULT NULL,
envelope_signature character varying DEFAULT NULL,
payload_extension character varying DEFAULT NULL,
creator_id_bytes character varying DEFAULT NULL,
creator_nonce character varying DEFAULT NULL,
chaincode_proposal_input character varying DEFAULT NULL,
tx_response character varying DEFAULT NULL,
payload_proposal_hash character varying DEFAULT NULL,
endorser_id_bytes character varying DEFAULT NULL,
endorser_signature character varying DEFAULT NULL,
network_name varchar(255)
);

ALTER table transactions owner to cups;
Alter sequence transactions_id_seq restart with 6;

-- ---------------------------
-- Table structure for `users`
-- ----------------------------
DROP TABLE IF EXISTS users;

CREATE TABLE users
(
id SERIAL PRIMARY KEY,
username varchar(255) NOT NULL,
email varchar(255),
"networkName" varchar(255) NOT NULL,
"firstName" varchar(255),
"lastName" varchar(255),
"password" varchar(255),
"roles" varchar(255),
salt varchar(255),
"createdAt" timestamp NOT NULL,
"updatedAt" timestamp NOT NULL
);
ALTER table users owner to cups;

DROP TABLE IF EXISTS write_lock;
CREATE TABLE write_lock
(
write_lock SERIAl PRIMARY KEY
);

ALTER table write_lock owner to cups;
Alter sequence write_lock_write_lock_seq restart with 2;

DROP INDEX IF EXISTS blocks_blocknum_idx;
CREATE INDEX ON Blocks
(blocknum);

DROP INDEX IF EXISTS blocks_channel_genesis_hash_idx;
CREATE INDEX ON Blocks
(channel_genesis_hash);

DROP INDEX IF EXISTS blocks_createdt_idx;
CREATE INDEX ON Blocks
(createdt);

DROP INDEX IF EXISTS transaction_txhash_idx;
CREATE INDEX ON Transactions
(txhash);

DROP INDEX IF EXISTS transaction_channel_genesis_hash_idx;
CREATE INDEX ON Transactions
(channel_genesis_hash);

DROP INDEX IF EXISTS transaction_createdt_idx;
CREATE INDEX ON Transactions
(createdt);

DROP INDEX IF EXISTS transaction_blockid_idx;
CREATE INDEX ON Transactions
(blockid);

DROP INDEX IF EXISTS transaction_chaincode_proposal_input_idx;
CREATE INDEX ON Transactions
((md5
(chaincode_proposal_input)));

DROP INDEX IF EXISTS channel_channel_genesis_hash_idx;
CREATE INDEX ON channel
(channel_genesis_hash);

DROP INDEX IF EXISTS channel_channel_hash_idx;
CREATE INDEX ON channel
(channel_hash);

GRANT SELECT, INSERT, UPDATE,DELETE ON ALL TABLES IN SCHEMA PUBLIC to cups;

下载破解的教程: https://blog.csdn.net/loveer0/article/details/82016644

连接数据的教程:https://jingyan.baidu.com/article/642c9d34ea3ada644a46f7ad.html

新建用户: https://blog.csdn.net/chenchunlin526/article/details/79001081

新建数据库:https://jingyan.baidu.com/article/d713063593db9f13fdf475c3.html

新建用户:cups,管理员用户。==========================>密码是:123456789

新建数据库:fabricexplorer,这个数据库的管理权是cups的。

执行sql文件,将剩下的表创建完成。

数据库用户名、用户密码、数据库名称和相对应。

(1)连接数据库

(2)创建用户

(3)创建数据库

(4)运行sql

(5)最终结果

常用命令

清空所有容器

1
2
3
4
sudo docker stop $(docker ps -a -q)
sudo docker ps -qa|xargs docker rm
# 重启
reboot

清空所有镜像

1
sudo docker image rm $(docker images -a -q)

清理文件

1
2
3
4
cd ~
rm -rf fabric-tools/
rm -rf kafka/
rm -rf /root/.local/share/Trash/files