操作系统:centos_7_06_64
节点版本:geth-linux-amd64-1.9.14-6d74d1e5.tar.gz
开源浏览器:https://github.com/etherparty/explorer
1、环境安装
安装git:
yum -y install git
安装nodejs:
wget https://nodejs.org/dist/v12.16.3/node-v12.16.3-linux-x64.tar.gz //下载
tar -zxvf node-v12.16.3-linux-x64.tar.gz //解压
cd node-v12.16.3-linux-x64 //进入目录
//修改环境变量
vim /etc/profile //环境变量
export PATH=$PATH:/root/node-v12.16.3-linux-x64/bin” //最下面增加
source /etc/profile //立即生效
查看版本,即安装正常:
[node-v12.16.3-linux-x64]# node -v
v12.16.3
[node-v12.16.3-linux-x64]# npm -v
6.14.4
2、下载eth区块链浏览器源码
下载浏览器源码:
git clone https://github.com/etherparty/explorer
3、安装bower
进入目录:
# cd explorer
# npm install -g bower -y //安装 bower
+ [email protected]
added 1 package from 1 contributor in 23.482s
初始化bower:
# bower init
# 注1问:命令报错 /usr/bin/env:"node" 没有那个文件或目录
# 注1解:sudo ln -s /usr/bin/nodejs /usr/bin/node
# 注2问:命令报错 bower esudo cannot be run with sudo
# 注2解:bower init --allow-root
在命令行一直回车,下一步即可。结果如下:
[explorer]# bower init --allow-root
bower existing The existing bower.json file will be used and filled in
? name angular-seed
? description A starter project for AngularJS
? main file
? keywords
? authors
? license MIT
? homepage https://github.com/angular/angular-seed
? set currently installed components as dependencies? No
? add commonly ignored files to ignore list? Yes
? would you like to mark this package as private which prevents it from being accidentally published to the registry? Yes
{
name: 'angular-seed',
description: 'A starter project for AngularJS',
version: '0.0.0',
homepage: 'https://github.com/angular/angular-seed',
license: 'MIT',
private: true,
dependencies: {
angular: '~1.4.0',
'angular-route': '~1.4.0',
'angular-loader': '~1.4.0',
'angular-mocks': '~1.4.0',
'html5-boilerplate': '~5.2.0',
web3: '~0.14.0',
'angular-bootstrap': '~0.13.3'
},
main: '',
ignore: [
'**/.*',
'node_modules',
'bower_components',
'app/bower_components',
'test',
]
}
? Looks good? Yes
You have new mail in /var/spool/mail/root
[explorer]#
bower安装:
bower install --allow-root
bower install angular --save-dev --allow-root
执行情况:
[explorer]# bower install angular --save-dev --allow-root
bower angular#* cached https://github.com/angular/bower-angular.git#1.7.9
bower angular#* validate 1.7.9 against https://github.com/angular/bower-angular.git#*
bower angular#~1.4.0 cached https://github.com/angular/bower-angular.git#1.4.14
bower angular#~1.4.0 validate 1.4.14 against https://github.com/angular/bower-angular.git#~1.4.0
bower angular#>=1.3.0 cached https://github.com/angular/bower-angular.git#1.7.9
bower angular#>=1.3.0 validate 1.7.9 against https://github.com/angular/bower-angular.git#>=1.3.0
Unable to find a suitable version for angular, please choose one by typing one of the numbers below:
1) angular#1.4.14 which resolved to 1.4.14 and is required by angular-loader#1.4.14, angular-mocks#1.4.14, angular-route#1.4.14
2) angular#~1.4.0 which resolved to 1.4.14 and is required by angular-seed
3) angular#>=1.3.0 which resolved to 1.7.9 and is required by angular-bootstrap#0.13.4
4) angular#^1.7.9 which resolved to 1.7.9
Prefix the choice with ! to persist it to bower.json
? Answer 1
[explorer]#
到这里,bower工具就已经安装成功了。
4、启动geth
本文启动geth命令:
./geth --datadir ./node/ --networkid 517 --port 30309 --rpc --rpcaddr 0.0.0.0 --rpcport 8549 --rpcapi personal,db,eth,net,web3,admin --rpccorsdomain * --syncmode full --nodiscover --allow-insecure-unlock
可能有部分参数不同,能正常启动geth节点并同步区块链就行,不需要其他任何操作。
5、启动npm
npm start # 在下载的explorer目录下执行
启动的开始会有很多的 WARN 和 ERR,这个不用管,让他自己跑;
[explorer]# npm start
> [email protected] prestart /data1/explorer/explorer
> npm install
> [email protected] install /data1/explorer/explorer/node_modules/bufferutil
> node-gyp rebuild
gyp WARN EACCES current user does not have permission to access the dev dir "/root/.cache/node-gyp/12.16.3"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/data1/explorer/explorer/node_modules/bufferutil/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/data1/explorer/explorer/node_modules/bufferutil/.node-gyp'
gyp ERR! System Linux 3.10.0-957.el7.x86_64
gyp ERR! command "/data1/explorer/nodejs/node-v12.16.3-linux-x64/bin/node" "/data1/explorer/nodejs/node-v12.16.3-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /data1/explorer/explorer/node_modules/bufferutil
gyp ERR! node -v v12.16.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
> [email protected] install /data1/explorer/explorer/node_modules/utf-8-validate
> node-gyp rebuild
gyp WARN EACCES current user does not have permission to access the dev dir "/root/.cache/node-gyp/12.16.3"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/data1/explorer/explorer/node_modules/utf-8-validate/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/data1/explorer/explorer/node_modules/utf-8-validate/.node-gyp'
gyp ERR! System Linux 3.10.0-957.el7.x86_64
gyp ERR! command "/data1/explorer/nodejs/node-v12.16.3-linux-x64/bin/node" "/data1/explorer/nodejs/node-v12.16.3-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /data1/explorer/explorer/node_modules/utf-8-validate
gyp ERR! node -v v12.16.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN lifecycle [email protected]~postinstall: cannot run in wd [email protected] bower install (wd=/data1/explorer/explorer)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/bufferutil):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/utf-8-validate):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
audited 488 packages in 5.11s
29 packages are looking for funding
run `npm fund` for details
found 64 vulnerabilities (19 low, 11 moderate, 34 high)
run `npm audit fix` to fix them, or `npm audit` for details
> [email protected] start /data1/explorer/explorer
> http-server ./app -a localhost -p 8000 -c-1
Starting up http-server, serving ./app on port: 8000
Hit CTRL-C to stop the server
目前为止,基本上就已经搭建完成了,在浏览器输入“localhost:8000”即可访问你搭建的区块链浏览器;
6、网络配置
修改连接以太网节点地址为远程节点地址:
# cd explorer
explorer# vim app/app.js
将var eth_node_url = 'http://localhost:8545'; 修改为 var eth_node_url = 'http://远程或本地以太坊节点ip:8545';
修改浏览器地址为本地IP地址:
# cd explorer
explorer# vim ./package.json
把"start": "http-server ./app -a localhost -p 8000 -c-1", 改为"start": "http-server ./app -a 本地ip -p 8000 -c-1",
此处有个坑,如果填写的ip地址是127.0.0.1,则只能在本机访问,而如果填写的是真实的服务器外网ip地址,npm start会失败:
Error: listen EADDRNOTAVAIL: address not available 59.1.1.1:8080
at Server.setupListenHandle [as _listen2] (net.js:1296:21)
at listenInCluster (net.js:1361:12)
at doListen (net.js:1500:7)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1340:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
网上查看了各种解决方案,说是地址端口这里出了问题,端口号被占用,于是在cmd中查看端口号是否被占用,发现没有被占用,将127.0.0.1修改为0.0.0.0;
然后重新启动npm start;正常。
没有任何数据,但是可以显示网页了。
修改app/index.html ,查找使用“ajax.googleapis.com”,把对应的js文件angular.min.js和jquery.min.js下载到本地,修改src路径;或者(本文实际按以下做法):
搜索国内可用的angular.min.js和jquery.min.js;比如本文将这两项修改为:
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
参考:http://www.jq22.com/jquery-info122
https://www.angularjs.net.cn/download/
重新启动npm star,看到最终结果:
实际运行中:
//后台运行,标准输出被定向到当前目录下的nohup.out文件,起到了log的作用
nohup npm start > nohup.out 2>&1 &
tail -100f nohup.out //查看,可以直接Ctrl+C退出
ps -ef | grep npm //查看npm进程id
ps -ef | grep node //查看node进程id
kill -9 10532 //关闭npm