返回

Blockchain Fabric Trace

项目地址

启动区块链网络

  1. 需要环境:docker、docker-compose
  2. 拉取docker镜像

pull

  1. 更换docker拉取镜像的源:
1
2
3
4
5
6
7
8
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://yxzrazem.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
  1. 拉取镜像:
1
2
3
4
5
6
7
8
docker pull hyperledger/fabric-peer:1.2.0 && 
docker pull hyperledger/fabric-orderer:1.2.0 && 
docker pull hyperledger/fabric-ca:1.2.0 && 
docker pull hyperledger/fabric-tools:1.2.0 && 
docker pull hyperledger/fabric-ccenv:1.2.0 && 
docker pull hyperledger/fabric-baseimage:0.4.10 && 
docker pull hyperledger/fabric-baseos:0.4.10 && 
docker pull hyperledger/fabric-couchdb:0.4.10

tag

1
2
3
4
5
6
7
8
docker tag hyperledger/fabric-peer:1.2.0 hyperledger/fabric-peer && 
docker tag hyperledger/fabric-orderer:1.2.0 hyperledger/fabric-orderer && 
docker tag hyperledger/fabric-ca:1.2.0 hyperledger/fabric-ca && 
docker tag hyperledger/fabric-tools:1.2.0 hyperledger/fabric-tools && 
docker tag hyperledger/fabric-ccenv:1.2.0 hyperledger/fabric-ccenv && 
docker tag hyperledger/fabric-baseimage:0.4.10  hyperledger/fabric-baseimage && 
docker tag hyperledger/fabric-baseos:0.4.10 hyperledger/fabric-baseos && 
docker tag hyperledger/fabric-couchdb:0.4.10 hyperledger/fabric-couchdb 
  1. 拉取项目代码
1
git clone https://gitee.com/ken_xue/Blockchain-APTrace-Fabric.git
  1. 启动fabric网络:
1
2
3
4
cd Blockchain-APTrace-Fabric/blockchain-trace-bcnetwork
sudo chmod -R 777 basic-network
cd ./basic-network
./start.sh

BUG1:

Error: error getting endorser client for channel: endorser client failed to connect to peer0.org1.trace.com:7051: failed to create new connection: context deadline exceeded

解决:

  1. 修改docker-compose.yml中所有peercli节点environmentCORE_PEER_ADDRESS=localhost:7051并添加- GODEBUG=netdns=go
  2. docker-compose-cli.yml中的cli节点同理
  3. 请确保在docker-compose.yaml文件中为每个Peer节点都设置了环境变量CORE_PEER_GOSSIP_BOOTSTRAPCORE_PEER_GOSSIP_EXTERNALENDPOINT。 这些设置用来启用Fabric发现服务,Hyperledger Explorer依赖于该服务来自动发现Fabric区块链网络的拓扑结构。
  4. 修改配置文件,注释掉options那句话,前面加#即可
1
sudo gedit /etc/resolv.conf
  1. 清理容器、数据卷
1
2
3
4
docker rm -f $(docker ps -aq)
docker volume rm $(docker volume ls)
docker ps -a
docker volume ls
  1. 重启网络

!!!注意:每次启动网络前查看配置文件,看options那句话是否注释掉

1
./start.sh
  1. 还是出现该报错的话,重启,重复步骤4、5即可;关闭代理Clash,设置里网络设为自动

安装并初始化链码

  1. 需要环境:go
  2. go version查看是否添加到环境变量
  3. 安装并初始化链码
1
2
3
4
sudo chmod -R 777 chaincode/
sudo chmod -R 777 webapp/
cd webapp/
./start.sh
  1. 查看链码是否安装成功
1
docker ps -a

BUG1:

Error: could not assemble transaction, err Proposal response was not successful, error code 500, msg failed to execute transaction 84565ffe4b1b7e84b637f8194bfa1e556411d94053ff8dc992968e0b1eaeb18b: timeout expired while starting chaincode farmercc:1.0 for transaction 84565ffe4b1b7e84b637f8194bfa1e556411d94053ff8dc992968e0b1eaeb18b

解决:

  1. docker-compose.yml中所有peer节点的environment中添加- CORE_PEER_ADDRESSAUTODETECT=true
  2. basic-network目录下重启网络:
1
2
3
4
5
docker rm -f $(docker ps -aq)
docker volume rm $(docker volume ls)
docker ps -a
docker volume ls
./start.sh

一次不成功,就重复几次

  1. 重新安装并初始化链码
1
./start.sh
  1. 查看链码是否安装成功
1
docker ps -a

启动node中间件服务

  1. 需要环境:node(12.22.12)、npm(6.14.16)
  2. node -vnpm -v查看版本
  3. 安装依赖,在webapp目录下执行:
1
npm install

Bug:FetchError: request to https://registry.npmmirror.com/n failed, reason: connect ECONNREFUSED 127.0.0.1:7890

解决:开clash代理

  1. 安装用户密钥
1
2
node enrollAdmin.js
node registerUser.js

BUG1:执行node registerUser.js可能会安装失败,请删除一下hfc-key-store后重新执行,如果还是失败,可能就是npm install出问题。

  1. 修改app.js中端口为9000
  2. 启动node服务(node服务就是一个中间件,连接前端和区块链网络)
1
node app.js
  1. 如果需要让其常驻后台,需要安装pm2。

启动:pm2 start app.js

停止:pm2 stop app.js

到这里,区块链网络就部署完成

启动后端数据库

系统基础数据后台blockchain-trace-basic-data,是一个SpringBoot项目

  1. 需要环境:mysql、redis、fastdfs、java、maven、idea
  2. 检查环境是否配置成功:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
systemctl status mysql
systemctl status redis
sudo /usr/local/nginx/sbin/nginx
ps -ef | grep nginx
fdfs_trackerd /etc/fdfs/tracker.conf
fdfs_storaged /etc/fdfs/storage.conf
fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz
http://192.168.169.135:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.tar.gz
java -version
mvn -v
  1. 修改application.yml文件中的Redis地址和fastdfs地址(application.yml文件在blockchain-trace-basic-data/ruoyi-admin/src/main/resources下)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
  # redis 配置
  redis:
    # 地址
    host: 127.0.0.1
    # 端口,默认为6379
    port: 6379
    # 密码
    password: 

  fdfs:
      so-timeout: 1501
      connect-timeout: 601
      thumb-image:
        width: 60
        height: 60
      tracker-list: 127.0.0.1:22122
      address: http://127.0.0.1:8888/
  1. 修改application-druid.yml文件中mysql地址和密码
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 数据源配置
spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        driverClassName: com.mysql.cj.jdbc.Driver
        druid:
            # 主库数据源
            master:
                url: jdbc:mysql://127.0.0.1:3306/blockchain?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                username: root
                password: root
  1. 修改pom.xml文件中<maven-jar-plugin.version>3.6.3</maven-jar-plugin.version>

  2. 创建日志目录并修改权限:

1
2
3
4
5
sudo mkdir /home/ruoyi
cd /home/ruoyi/
sudo mkdir logs
cd ../
sudo chmod -R 777 ruoyi/
  1. 用Navicat新建数据库blockchain
  2. 用Navicat选择数据库blockchain,导入blockchain.sql文件
  3. 配置IDEA

  1. 使用IDEA打开blockchain-trace-basic-data,会自动加载Maven依赖包,初次加载会比较慢(根据自身网络情况而定,建议把虚拟机内存调大),运行com.ruoyi.RuoYiApplication.java启动RuoYi-Vue后端,,出现如下图表示启动成功:

Bug1:找不到插件 org.apache.maven.plugins:maven-compiler-plugin:3.1

解决:修改pom.xml文件中<maven-jar-plugin.version>3.6.3</maven-jar-plugin.version>

Bug2:无法解析插件 org.apache.maven.plugins:maven-install-plugin:2.4

Bug3:java: 程序包sun.misc不存在

解决:切换JDK1.8

Bug4:ERROR in ch.qos.logback.core.rolling.RollingFileAppender[file_info] - openFile(/home/ruoyi/logs/sys-info.log,true) call failed. java.io.FileNotFoundException: /home/ruoyi/logs/sys-info.log (没有那个文件或目录)

解决:

1
2
3
4
5
sudo mkdir ruoyi
cd ruoyi/
sudo mkdir logs
cd ../
sudo chmod -R 777 ruoyi/

Bug5:java.sql.SQLSyntaxErrorException: Unknown database ‘blockchain’

解决:用Navicat新建数据库blockchain

Bug6:Error querying database. Cause: java.sql.SQLSyntaxErrorException: Table ‘blockchain.sys_config’ doesn’t exist

解决:用Navicat选择数据库blockchain,导入blockchain.sql文件

Bug7:could not start Quartz Scheduler after delay; nested exception is org.quartz.SchedulerException: The Scheduler cannot be restarted after shutdown() has been called.

继续往上翻会看到:Caused by: java.net.BindException: 地址已在使用

解决:关闭node中间件,释放8080端口

启动PC端

blockchain-trace-pc

  1. 安装依赖:
1
sudo npm install --registry=https://registry.npm.taobao.org

Bug1:npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree

解决:在新版本的npm中,默认情况下,npm install遇到冲突的peerDependencies时将失败。--legacy-peer-deps标志是在v7中引入的,目的是绕过peerDependency自动安装;它告诉NPM忽略项目中引入的各个modules之间的相同modules但不同版本的问题并继续安装,保证各个引入的依赖之间对自身所使用的不同版本modules共存。

1
npm install --registry=https://registry.npm.taobao.org --legacy-peer-deps 

Bug2:gyp ERR! stack Error: Can’t find Python executable “python2.7”, you can set the PYTHON env variable.

解决:

1
2
npm config set python python2.7
npm config set msvs_version 2015

Bug3:npm ERR! Cannot read property ‘insert’ of undefined

解决:更换node、npm版本:node(12.22.12)、npm(6.14.16)

注意:更换版本时要关闭前面启动的node中间件

1
2
3
4
5
sudo npm install n -g
sudo n 12.22.12
sudo n
node -v
sudo npm -v
  1. 修改连接区块链网络地址,src/main.js中修改为区块链网络所在服务器地址
1
Vue.prototype.$httpUrl = "http://localhost:9000/route";
  1. 启动项目:
1
npm run dev

Bug:(node:42423) UnhandledPromiseRejectionWarning: Error: Cannot find module ‘semver’

解决:加sudo

Bug3:前台提示404 NOT FOUND

解决:修改端口号

Bug4:Proxy error: Could not proxy request /captchaImage from 192.168.1.131:1024 to http://localhost:8088 (ECONNREFUSED).

解决:使用IDE(IDEA)启动Ruo-Yi Vue后端(data)

Built with Hugo
Theme Stack designed by Jimmy