- 环境:ubuntu
- Fabric浏览器版本:1.0
- 浏览器官方地址: https://github.com/hyperledger/blockchain-explorer
- 推荐使用官方提供的docker-compose搭建https://www.jianshu.com/p/77b87ec0a78f
准备
- 确定搭建的Fabric网络版本
- clone对应的浏览的版本
比如,1.4版本的Faric网络,就可以clone 1.0版本的Fabric explore
- 确定node版本。如果版本不对,会出现许多未知错误。具体可参照官方github
- 安装 postgresql
sudo apt-get install postgresql
- 安装 jq
sudo apt-get install jq
- 安装 docker
开始搭建
git clone https://github.com/hyperledger/blockchain-explorer.git
cd blockchain-explorer
- 主要用到v1.0.0-rc2版本的浏览器以下几个配置文件:
- appconfig.json
用于设置浏览器的IP和端口 - exploreconfig.json
用于设置数据库的相关信息 - first-network.json
用于设置证书相关信息 - config.json
config.json目前不需要过多关注,他内部引用的是first-network.json文件。
- 设置first-network
(1) 把搭建Fabric网络时生成的crypto-config复制到blockchain-explorer目录下任意位置。
(2) 替换organizations
和peers
下的证书位置,最好使用全路径。使用全路径时,需要把fullpath
设为true
.
我的配置:
{
"name": "aberic",
"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": {}
},
"connection": {
"timeout": {
"peer": {
"endorser": "6000",
"eventHub": "6000",
"eventReg": "6000"
}
}
}
}
},
"organizations": {
"Org1MSP": {
"mspid": "Org1MSP",
"fullpath": true,
"adminPrivateKey": {
"path": "XXX/blockchain-explorer/app/platform/fabric/fixtures/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/0f7cc385f61b26515396a756b91ea2de980081dca57bcc375a33a5138979163c_sk"
},
"signedCert": {
"path": "XXX/blockchain-explorer/app/platform/fabric/fixtures/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": "XXX/blockchain-explorer/app/platform/fabric/fixtures/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
},
"url": "grpcs://XXX",
"eventUrl": "grpcs://XXX",
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com"
}
}
}
}
- 设置 exploreconfig.json
这个配置可以使用默认配置。 - 初始化数据库表
(1)cd blockchain-explorer/app/persistence/fabric/postgreSQL/db
(2)./createdb.sh
可能报错:
Copying ENV variables into temp file...
module.js:549
throw err;
^
Error: Cannot find module '/root/blockchain-explorer/app/persistence/fabric/postgreSQL/db/processenv.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
USER="hppoc"
DATABASE="fabricexplorer"
PASSWD='password'
rm: remove write-protected regular file '/tmp/process.env.json'? n
Executing SQL scripts, OS=linux-gnu
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LC_TERMINAL = "iTerm2",
LC_TERMINAL_VERSION = "3.3.7",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
could not change directory to "/root/blockchain-explorer/app/persistence/fabric/postgreSQL/db": Permission denied
./explorerpg.sql: No such file or directory
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LC_TERMINAL = "iTerm2",
LC_TERMINAL_VERSION = "3.3.7",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
could not change directory to "/root/blockchain-explorer/app/persistence/fabric/postgreSQL/db": Permission denied
./updatepg.sql: No such file or directory
解决方法:
- perl warining:
export LC_ALL=en_US.UTF-8
- Permission denied:
createdb.sh
会创建一个postgres的用户,并以这个用户初始化数据库表。如果你的当前用户不允许其他用户访问其下的数据,就会报这种错误。
比如:我当前用户root,到根目录下查看当前用户权限cd \ && ll
.
drwx------ 18 root root 4.0K Dec 18 07:57 root
用户权限是700,不允许同组和其他用户访问。
当我执行./createdb.sh
时,在脚本内以用户postgres对root下的文件执行一些操作时,就会报错。
这个问题解决方法很多。
我的解决方法是:把blockchain-explorer项目移到根目录下。
再次执行./createdb.sh
当你看到以下句子时,说明你成功了。
You are now connected to database XXX as user XXX.
- 运行主目录下的
./start.sh
可能会出现以下错误:
- FATAL: password authentication failed for user "
logs/console/
下的日志文件也会出现postgres无法连接的错误。
解决方法:
修改pg_hba.conf
配置文件,将第4个字段改为trust
# Database administrative login by Unix domain socket
local all postgres peer
为了避免麻烦,我将所有行的第4个字段都改成了 trust
最后执行sudo /etc/init.d/postgresql reload
,重新加载配置文件。
- saveTransaction false 错误
这个可能是与数据库原来内容冲突,将数据库清空,重新启动浏览器,不启动应该也可以,浏览器会主动更新;
重新启动前,要用./stop.sh关闭浏览器后台进程