Hyperledger Fabric 演练 - 《基于联盟区块链的政务大数据共享》

2020-06-22 16:33:00

1. 背景

为了继续深入研究Fabric的加密通道逻辑,找了一个现成的例子,并修正了一个新手部署可能遇到的问题,
修正的主要点是

  1. 修改实例代码相对fabric-samples路径,
  2. 细化一些操作步骤,方便新手傻瓜式运行

1.1 区域链(基于证书准入的联盟链)网络

1.2 业务流程时序

2. 演示系统环境

OS: Ubuntu 18.04
Fabric: release-1.4
Go: go1.14.4 linux/amd64
Docker: 19.03.11

3. 源代码仓库

gitee: https://gitee.com/BCSkill/fcc

4. 实例部署

4.1 克隆源代码

git clone https://gitee.com/BCSkill/fcc.git

4.2 部署fabric-samples运行环境

细节的话可以参考《fabric-samples 部署测试》,我们这里不做详细描述,直接运行封装好的脚本

./1-1.hy-sample.sh

大概过程中会分为几步,

  1. 克隆fabric-samples到当前源码目录
  2. 下载编译到好的fabric二进制文件,并解压到 fabric-samples/bin,记得将此目录添加到环境变量
  3. 拉取所需要的Docker镜像

4.3 启动示例网络,创建区块链网络(2个组织,每组织2个节点)

./1-2.startNetwork.sh

成功后输出========= All GOOD, BYFN execution completed ===========

4.4 加入第3个组织,2个节点

./2.addOrg3.sh

完成后,结果显示========= Org3 is now halfway onto your first network =========

4.5 部署政务智能合约,并实例化

./3-1.installNetcon.sh   #合约:网签合同备案
./3-2.installEstateBook.sh   #合约:不动产权证书
./3-3.installEstateTax.sh    #合约:不动产业务缴税

完成后,结果显示

Get instantiated chaincodes on channel mychannel:
Name: estatebook, Version: 1.0, Path: github.com/chaincode/estatebook, Escc: escc, Vscc: vscc
Name: estatetax, Version: 1.0, Path: github.com/chaincode/estatetax, Escc: escc, Vscc: vscc
Name: netcon, Version: 1.0, Path: github.com/chaincode/netcon, Escc: escc, Vscc: vscc

此时链环境和链合约已经部署好了。下面开始部署项目的服务端和Web前台

4.6 编译后台。

代码位于appcode/fccserver/src 可自行编译,或直接使用已编译完成的可执行文件

chmod +x appcode/fccserver/src/fccserver

启动后台容器

./4.startAppcli.sh
docker logs -f appcli

如果启动正常,会显示

[fcc-server] 2019/12/12 03:03:55 system db initiated successfully.
[fcc-server] 2019/12/12 03:03:56 Chaincode client initialed successfully.
[fcc-server] 2019/12/12 03:03:56 Server started on  :1206

4.7 编译和部署前端

前端采用VUE,也可使用其它前端框架或HTML。使用GNINX或其它WEB服务器部署编译后的前端代码。注:当前未使用登录和权限设置
前台部署依赖yarn,《ubuntu 安装最新版本 yarn》

cd ./appcode/fcc-client // 进到Web前端代码目录
yarn install            // 安装依赖
yarn serve              // 运行前端

如果出现
运行成功后,就会显示访问地址

  App running at:
  - Local:   http://localhost:8080/ 
  - Network: http://192.168.31.134:8080/

浏览器打开地址,就能看到实例演示了

在线演示

http://xujf000.tk:28888/#/

实例依赖Docker 镜像

surou@surou:~/go/src/github.com/chaincode/netcon$ docker ps
+ docker ps
CONTAINER ID        IMAGE                                                                                                        COMMAND                  CREATED             STATUS              PORTS                                        NAMES
f3b34643ff39        dev-peer0.org2.example.com-estatebook-1.0-08d85d200f6268a9c9656f01eac3d5325c44c1d2a93a1115168f63888a27206b   "chaincode -peer.add…"   44 minutes ago      Up 43 minutes                                                    dev-peer0.org2.example.com-estatebook-1.0
9828c2b46b4e        dev-peer0.org2.example.com-estatetax-1.0-975867dfc12f233b11d78db94c347aa6b7e94f1d389af7cc892cb8730652c110    "chaincode -peer.add…"   45 minutes ago      Up 45 minutes                                                    dev-peer0.org2.example.com-estatetax-1.0
9d62c54bfd73        dev-peer0.org2.example.com-netcon-1.0-8285fea29f8449473340c346dc0b6716a084576593325a33707353426d7298dc       "chaincode -peer.add…"   46 minutes ago      Up 46 minutes                                                    dev-peer0.org2.example.com-netcon-1.0
cb870db589c4        hyperledger/fabric-tools:1.4.3                                                                               "./fccserver"            About an hour ago   Up About an hour    0.0.0.0:1206->1206/tcp                       appcli
33ad280f1f17        dev-peer0.org1.example.com-estatetax-1.0-3284f6d77599d92fad2da964008b3f4bb78573eeb938f40e2110de2089455dc3    "chaincode -peer.add…"   About an hour ago   Up About an hour                                                 dev-peer0.org1.example.com-estatetax-1.0
fa575e9548e3        dev-peer0.org1.example.com-estatebook-1.0-1804a11c573ccbef46e7cda2314c1d76edc2fb52b0f7f9d10ed2024c03343aff   "chaincode -peer.add…"   About an hour ago   Up About an hour                                                 dev-peer0.org1.example.com-estatebook-1.0
75c50829fbb8        dev-peer0.org1.example.com-netcon-1.0-4faf315b9f1da5832e386fbae0d05157d269cff3802d770b0e8f135a69027796       "chaincode -peer.add…"   About an hour ago   Up About an hour                                                 dev-peer0.org1.example.com-netcon-1.0
15d29c21ed9a        hyperledger/fabric-tools:1.4.3                                                                               "/bin/bash"              2 hours ago         Up 2 hours                                                       Org3cli
d0ce2cc32019        hyperledger/fabric-peer:1.4.3                                                                                "peer node start"        2 hours ago         Up 2 hours          0.0.0.0:12051->12051/tcp                     peer1.org3.example.com
9bcf5082db71        hyperledger/fabric-peer:1.4.3                                                                                "peer node start"        2 hours ago         Up 2 hours          0.0.0.0:11051->11051/tcp                     peer0.org3.example.com
6f76cca2d809        hyperledger/fabric-tools:latest                                                                              "/bin/bash"              2 hours ago         Up 2 hours                                                       cli
04d61faad751        hyperledger/fabric-peer:latest                                                                               "peer node start"        2 hours ago         Up 2 hours          0.0.0.0:10051->10051/tcp                     peer1.org2.example.com
cdbffd49d7d2        hyperledger/fabric-peer:latest                                                                               "peer node start"        2 hours ago         Up 2 hours          0.0.0.0:8051->8051/tcp                       peer1.org1.example.com
d59fe735b96d        hyperledger/fabric-peer:latest                                                                               "peer node start"        2 hours ago         Up 2 hours          0.0.0.0:9051->9051/tcp                       peer0.org2.example.com
4caeb0c062e0        hyperledger/fabric-peer:latest                                                                               "peer node start"        2 hours ago         Up 2 hours          0.0.0.0:7051->7051/tcp                       peer0.org1.example.com
431ad6029954        hyperledger/fabric-ca:latest                                                                                 "sh -c 'fabric-ca-se…"   2 hours ago         Up 2 hours          7054/tcp, 0.0.0.0:8054->8054/tcp             ca_peerOrg2
4d69e9f76b1b        hyperledger/fabric-couchdb                                                                                   "tini -- /docker-ent…"   2 hours ago         Up 2 hours          4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp   couchdb0
1bcd9f89625f        hyperledger/fabric-couchdb                                                                                   "tini -- /docker-ent…"   2 hours ago         Up 2 hours          4369/tcp, 9100/tcp, 0.0.0.0:6984->5984/tcp   couchdb1
cb46fd7307cf        hyperledger/fabric-couchdb                                                                                   "tini -- /docker-ent…"   2 hours ago         Up 2 hours          4369/tcp, 9100/tcp, 0.0.0.0:8984->5984/tcp   couchdb3
ac996671c144        hyperledger/fabric-orderer:latest                                                                            "orderer"                2 hours ago         Up 2 hours          0.0.0.0:7050->7050/tcp                       orderer.example.com
c13cc3241b96        hyperledger/fabric-ca:latest                                                                                 "sh -c 'fabric-ca-se…"   2 hours ago         Up 2 hours          0.0.0.0:7054->7054/tcp                       ca_peerOrg1
01ce681daa6c        hyperledger/fabric-couchdb                                                                                   "tini -- /docker-ent…"   2 hours ago         Up 2 hours          4369/tcp, 9100/tcp, 0.0.0.0:7984->5984/tcp   couchdb2

参考

https://www.bcskill.com/index.php/archives/926.html

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »