基于helm一键部署fabric网络(五)

本教程是《Fabric实战教程之一步步走向生产》系列教程的第五篇,也是最为干货的一篇,直接一键部署fabric网络,动态支持LevelDB和CouchDB状态数据库,也支持三种排序模式:solo、kafka、etcdRaft,同时提供了一键生成connection-profile配置文件脚本以及blockchain-explorer区块链看板。

教程目录结构如下:

  1. 简介
  2. 基于docker部署最简fabric网络
  3. 基于docker部署多机fabric网络
  4. 一键部署k8s集群
  5. 基于helm一键部署fabric网络
  6. [国内网络下的网络搭建调整细节]
  7. [踩坑总结]

本文教程在阿里云海外服务器上面实操,由于国内网络问题,docker和镜像都比较难下载,后面第六篇介绍国内网络下的脚本调整细节。

主机系统版本如下

[root@test ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@test ~]# uname -a
Linux test 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

k8s网络拓扑如下:

主机 类型
host1 master
host2 node
host3 node

下面启动脚本所实现的fabric网络拓扑如下:

基于helm一键部署fabric网络(五)_第1张图片

1.启动k8s集群

参照上一章节快速启动k8s集群

2.启动网络(如下以上面的拓扑进行实现)

#以下所有命令都在k8s的master主机上进行操作
cd ~
git clone https://github.com/jiang11958/fabric-platform
cd ~/fabric-platform
sh run.sh "{'network':{'name':'fab'},'nfs':{'domain':'','in_ip':'172.21.28.224','ip':'172.21.28.224','port':22,'user':'root','pass':'password','path':'/nfs/fabric/fab','export':'172.21.28.0/24'},'orderer':{'name':'orderer','type':'etcdRaft','count':5,'port':'7050','domain':'orderer.example.com','password':'12345678','batchTimeout':'2','maxMessageCount':'10','absoluteMaxBytes':'99','preferredMaxBytes':'512'},'orgs':[{'name':'org1','mspName':'org1MSP','domain':'org1.example.com','stateDbType':'LevelDB','port':'7051','count':1},{'name':'org2','mspName':'org2MSP','domain':'org2.example.com','stateDbType':'LevelDB','port':'7051','count':1},{'name':'org3','mspName':'org3MSP','domain':'org3.example.com','stateDbType':'LevelDB','port':'7051','count':1}],'channels':[{'name':'mychannel2','orgs':['org1','org3']},{'name':'mychannel1','orgs':['org1','org2']}]}" 

json字段说明

{
	"network": {
		"name": "fab"                      #fabric 网络名称
	},
	"nfs": {                               #nfs 配置
		"domain": "",
		"in_ip": "172.21.28.225",          #局域网 ip
		"ip": "161.117.249.248",           #因特网 ip
		"port": 22,                        #ssh 端口
		"user": "root",                    #ssh 用户名
		"pass": "password"                 #ssh 密码
		"path": "/nfs/fabric/fab",	       #nfs 共享路径
		"export": "172.21.28.0/24"         #nfs 可访问的子网或ip列表
	},
	"orderer": {
		"name": "orderer",                 #必须小写字母开头
		"type": "etcdRaft",                #排序模式:solo kafka etcdRaft
		"port": "7050",                    #orderer端口 默认
		"count": 5,                        #排序模式下对应orderer节点数量solo:1 kafka:3 etcdRaft:5
		"domain": "orderer.example.com",   #orderer 组织域名
		"password": "12345678",            #MSP 证书密码
		"batchTimeout": "2",               #orderer 默认设置
		"maxMessageCount": "10",           #orderer 默认设置
		"absoluteMaxBytes": "99",          #orderer 默认设置
		"preferredMaxBytes": "512",        #orderer 默认设置
	},
	"orgs": [{                             #组织设置
		"name": "org1",                    #必须小写字母开头
		"mspName": "org1MSP",              #MSP ID
		"domain": "org1.example.com",      #组织域名
		"stateDbType": "LevelDB",          #状态数据库LevelDB 或者 CouchDB
		"port": "7051",                    #peer 端口
		"count": 1                         #peer 节点数量
	}, {
		"name": "org2",
		"mspName": "org2MSP",
		"domain": "org2.example.com",
		"stateDbType": "LevelDB",          
		"port": "7051",
		"count": 1
	}, {
		"name": "org3",
		"mspName": "org3MSP",
		"domain": "org3.example.com",
		"stateDbType": "LevelDB",
		"port": "7051",
		"count": 1
	}],
	"channels": [{                         #通道配置
		"name": "mychannel2",              #通道名称
		"orgs": ["org1", "org3"]           #加入该通道的组织名
	}, {
		"name": "mychannel1",
		"orgs": ["org1", "org2"]
	}]
}

3.一键生产connection profile配置文件

#以下所有命令都在k8s的master主机上进行操作
cd ~/fabric-platform/profile
sh run.sh "{\"network\":{\"name\":\"fab\"},\"org\":{\"name\":\"org1\",\"mspName\":\"org1MSP\",\"domain\":\"org1.example.com\",\"port\":\"7051\"},\"orderer\":{\"name\":\"orderer\",\"count\":\"1\",\"domain\":\"orderer.example.com\"},\"orgs\":[{\"name\":\"org1\",\"mspName\":\"org1MSP\",\"domain\":\"org1.example.com\",\"port\":\"7051\",\"count\":\"1\"},{\"name\":\"org2\",\"mspName\":\"org2MSP\",\"domain\":\"org2.example.com\",\"port\":\"7051\",\"count\":\"1\"},{\"name\":\"org3\",\"mspName\":\"org3MSP\",\"domain\":\"org3.example.com\",\"port\":\"7051\",\"count\":\"1\"}],\"channels\":[{\"name\":\"mychannel2\",\"orgs\":[\"org1\",\"org3\"]},{\"name\":\"mychannel1\",\"orgs\":[\"org1\",\"org2\"]}]}" 

json格式说明

{
	"network": {                           #fabric 网络名称
		"name": "fab"
	},
	"org": {                               #此配置文件对应组织的信息
		"name": "org1",
		"mspName": "org1MSP",
		"domain": "org1.example.com",
		"port": "7051"
	},
	"orderer": {                           #orderer 组织配置
		"name": "orderer",
		"count": "5",                      #orderer节点数量 solo:1 kafka:3 etcdRaft:5
		"domain": "orderer.example.com"
	},
	"orgs": [{                             #所有组织配置信息
		"name": "org1",
		"mspName": "org1MSP",
		"domain": "org1.example.com",
		"port": "7051",
		"count": "1"
	}, {
		"name": "org2",
		"mspName": "org2MSP",
		"domain": "org2.example.com",
		"port": "7051",
		"count": "1"
	}, {
		"name": "org3",
		"mspName": "org3MSP",
		"domain": "org3.example.com",
		"port": "7051",
		"count": "1"
	}],
	"channels": [{                        #所有通道配置信息
		"name": "mychannel2",
		"orgs": ["org1", "org3"]
	}, {
		"name": "mychannel1",
		"orgs": ["org1", "org2"]
	}]
}

4.获取每个组织下的区块链看板地址

[root@test ~]cd ~
[root@test ~]kubectl get svc -n fab | grep explorer | awk '{split($5,port,/[:/]/); print $1 " " port[2]}'
# get the explorer internet port
#  explorer-org1 32320        ,组织org1 的explorer地址: http://your_master_ip:32320
#  explorer-org2 31224        ,组织org2 的explorer地址: http://your_master_ip:31224
#  explorer-org3 32101        ,组织org3 的explorer地址: http://your_master_ip:32101

5.一键清除fabric网络

cd ~/fabric-platform
sh remove.sh "{'network':{'name':'fab'}}"

你可能感兴趣的:(Hyperledger,Fabric)