Hyperledger Fabric1.4.0搭建区块链浏览器

参考博文
https://www.jianshu.com/p/2d4673567ff8?utm_campaign=haruki
https://www.jianshu.com/p/58ade73fc68c
https://github.com/hyperledger/blockchain-explorer
https://blog.csdn.net/oafzzl/article/details/103878692?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-2

准备工作

1、 安装Nodejs 10.19.0

wget https://nodejs.org/download/release/v10.19.0/node-v10.19.0-linux-x64.tar.gz
tar -xvf node-v10.19.0-linux-x64.tar.gz
sudo ln -s /home/ubuntu/node-v10.19.0-linux-x64/bin/node
/usr/local/bin/node
sudo ln -s /home/ubuntu/node-v10.19.0-linux-x64/bin/npm
/usr/local/bin/npm
mv /home/ubuntu/node-v8.14.0-linux-x64  /home/ubuntu/node
vim /etc/profile  #修改profile加入下面内容
export PATH="$PATH:/home/ubuntu/node/bin"

2、 PostgreSQL 9.5以上,我用的是10
更新 apt 包索引

sudo apt-get update

安装数据库,安装后会自动添加postgres 的操作系统用户,密码是随机的

sudo apt-get install postgresql

打开客户端工具 psql

sudo -u postgres psql

修改 postgres 数据库用户的密码为123456

postgres=# ALTER USER postgres WITH
PASSWORD '123456'; 

退出 psql

postgres=# \q

修改 ubuntu 操作系统的 postgres 用户的密码

sudo passwd -d postgres
sudo -u postgres passwd

修改配置实现远程访问

vi /etc/postgresql/10/main/postgresql.conf

修改连接权限

#listen_addresses = 'localhost' 改为 listen_addresses = '*'

设置所有用户可连接

vi /etc/postgresql/10/main/pg_hba.conf

在最后一行插入以下内容

host all all 0.0.0.0/0 md5

重启服务

/etc/init.d/postgresql restart

3、安装 Jq

sudo apt-get install jq

验证版本

jq -V

4、 Docker CE 18.09.2 or later
5、 Docker Compose 1.14.0
6、 保证first-network可以运行

开始搭建
拉取项目

git clone https://github.com/hyperledger/blockchain-explorer.git
#太慢的话用码云

进入目录

cd blockchain-explorer

修改配置文件

进入目录blockchain-explorer/app,默认配置就好,其实不需要修改

vim explorerconfig.json
cd blockchain-explorer/app/persistence/fabric/PostgreSQL
chmod -R 775 db/
cd db

查看是否创建成功
连接 postgresSQL

sudo -u postgres psql

查看已有数据库

\l

创建表

\d

退出

\q

修改配置文件

cd blockchain-explorer/app
"jwt": {
"secret" : "a secret phrase!!",
"expiresIn": "2 days"
}

启动first-network

./byfn.sh up

修改first-network.json配置文件

(1) 把搭建Fabric网络时生成的crypto-config复制到blockchain-explorer目录下任意位置。

(2) 替换organizations和peers下的证书位置,最好使用全路径。使用全路径时,需要把fullpath设为true.

XXXX为修改部分

{
"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/XXXX"
#换成自己的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"
}
}
    }
}

构建Hyperledger Explorer

cd ~
cd blockchain-explorer/
./main.sh install
./main.sh test

运行

cd ~
cd blockchain-explorer/
./start.sh

可能出现的错误

./createdb.sh
could not change
directory to "/home/dc2-user/kongli/blockchain-explorer/app/persistence/postgreSQL/db":
权限不够

需要把blockchain-explorer下载在非当前用户文件夹下,比如/tmp

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段命令的作用是: 1. 执行 `source /etc/profile` 命令,使得之前添加的 Go 语言环境变量生效; 2. 执行 `mkdir -p /home/ubuntu/gopath/src/github.com/hyperledger` 命令,创建一个目录用于存放 Hyperledger Fabric 的源代码; 3. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger` 命令,切换到 Hyperledger Fabric 代码存放的目录; 4. 执行 `cp /resource/docker-compose /usr/local/bin` 命令,将预设好的 `docker-compose` 文件拷贝到 `/usr/local/bin` 目录下; 5. 执行 `chmod +x /usr/local/bin/docker-compose` 命令,添加可执行权限; 6. 执行 `cp /resource/fabric-samples.tar.gz /home/ubuntu/gopath/src/github.com/hyperledger` 命令,将预设好的 Hyperledger Fabric 样例程序压缩包拷贝到 `github.com/hyperledger` 目录下; 7. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger` 命令,切换到 Hyperledger Fabric 样例程序所在的目录; 8. 执行 `tar -xf ./fabric-samples.tar.gz` 命令,解压 Hyperledger Fabric 样例程序压缩包; 9. 执行 `source /etc/profile` 命令,重新加载 Go 语言环境变量; 10. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger/fabric-samples/scripts` 命令,切换到 Hyperledger Fabric 样例程序的脚本目录; 11. 执行 `./bootstrap.sh 1.4.0 1.4.0 0.4.14` 命令,安装 Hyperledger Fabric 所需的依赖组件; 12. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger/fabric-samples/first-network` 命令,切换到 Hyperledger Fabric 样例程序的第一个网络目录; 13. 执行 `./byfn.sh up -s couchdb` 命令,启动第一个网络,并使用 CouchDB 作为状态数据库; 14. 执行 `docker-compose -f docker-compose-cli.yaml -f docker-compose-couch.yaml -f docker-compose-kafka.yaml start` 命令,启动 Fabric 网络中的 Docker 容器; 15. 执行 `../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx channel-artifacts/test.tx -channelID test` 命令,使用 configtxgen 工具生成通道交易配置文件和创世块配置文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值