菜鸟系列Fabric——Fabric 1.2 多机部署(3)
多机部署fabric kafka共识
1. 角色分配
| 主机1 | 主机 2 |
|---|---|
| Org1 peer0 1 | Org2 peer 0 1 |
| Orderer 0 1 | Orderer 2 |
| kafka 0 1 | kafka 2 3 |
| zookeeper 0 1 | zookeeper 2 |
2. 配置文件生成及准备yaml文件
2.1 修改配置文件
configtx-kafka.yaml
Addresses:
- orderer0.example.com:7050
- orderer1.example.com:8050
- orderer2.example.com:7050
Kafka:
# Brokers: A list of Kafka brokers to which the orderer connects. Edit
# this list to identify the brokers of the ordering service.
# NOTE: Use IP:port notation.
Brokers:
- kafka0:9092
- kafka1:10092
- kafka2:9092
- kafka3:10092
crypto-config-kafka.yaml
OrdererOrgs:
# ---------------------------------------------------------------------------
# Orderer
# ---------------------------------------------------------------------------
- Name: Orderer
Domain: example.com
CA:
Country: US
Province: California
Locality: San Francisco
# ---------------------------------------------------------------------------
# "Specs" - See PeerOrgs below for complete description
# ---------------------------------------------------------------------------
Specs:
- Hostname: orderer0
- Hostname: orderer1
- Hostname: orderer2
2.2 生成配置文件
./generateArtifacts.sh mychannel kafka
分步执行操作如下:
1、生成公私钥和证书
[centos@jiliguo e2e_cli]$ ../../release/linux-amd64/bin/cryptogen generate --config=./crypto-config-kafka.yaml
2、生成创世区块
cp configtx-raft.yaml configtx.yaml
../../release/linux-amd64/bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
3、生成Channel配置区块
CONFIGTXGEN=../../release/linux-amd64/bin/configtxgen
CHANNEL_NAME=mychannel
$CONFIGTXGEN -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
4、更新锚节点
$CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
$CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
2.3 zookeeper、kafka等yaml文件生成
其中 ZOO_MY_ID 表示 ZK 服务的 id, 它是1-255 之间的整数, 必须在集群中唯一. ZOO_SERVERS 是ZK 集群的主机列表.
1、2181:对client端提供服务
2、3888:选举leader使用
3、2888:集群内机器通讯使用(Leader监听此端口)
zookeeper
version: '2'
services:
zookeeper0:
container_name: zookeeper0
image: hyperledger/fabric-zookeeper
restart: always
ports:
- 2181:2181
- 2888:2888
- 3888:3888
environment:
- ZOO_MY_ID=1
- ZOO_SERVERS=server.1=0.0.0.0:2888:3888 server.2=zookeeper1:5888:4888 server.3=zookeeper2:2888:3888
extra_hosts:
- "zookeeper0:0.0.0.0"
- "zookeeper1:192.168.9.110"
- "zookeeper2:192.168.9.96"
- "kafka0:192.168.9.110"
- "kafka1:192.168.9.110"
- "kafka2:192.168.9.96"
- "kafka3:192.168.9.96"
注意:ZOO_SERVERS中本机的地址一律写出0.0.0.0:2888:3888;端口号是2888:3888,不是映射到host的端口号,其他写映射的ip和端口
kafka
version: '2'
services:
kafka0:
container_name: kafka0
image: hyperledger/fabric-kafka
restart: always
environment:
- KAFKA_BROKER_ID=0
- KAFKA_MIN_INSYNC_REPLICAS=2
- KAFKA_DEFAULT_REPLICATION_FACTOR=3
- KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:3181,zookeeper2:2181
- KAFKA_MESSAGE_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
- KAFKA_REPLICA_FETCH_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
- KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
- KAFKA_ADVERTISED_HOST_NAME=192.168.9.110
- KAFKA_ADVERTISED_PORT=9092
ports:
- 9092:9092
extra_hosts:
- "zookeeper0:192.168.9.110"
- "zookeeper1:192.168.9.110"
- "zookeeper2:192.168.9.96"
- "kafka0:192.168.9.110"
- "kafka1:192.168.9.110"
- "kafka2:192.168.9.96"
- "kafka3:192.168.9.96"
注意:一定要配KAFKA_ADVERTISED_HOST_NAME和KAFKA_ADVERTISED_PORT,为host的IP和映射到host的端口
orderer
version: '2'
services:
orderer2.example.com:
container_name: orderer2.example.com
image: hyperledger/fabric-orderer
environment:
- ORDERER_GENERAL_LOGLEVEL=debug
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_GENESISMETHOD=file
- ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
# enabled TLS
- ORDERER_GENERAL_TLS_ENABLED=true
- ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
- ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s
- ORDERER_KAFKA_RETRY_SHORTTOTAL=30s
- ORDERER_KAFKA_VERBOSE=true
- ORDERER_KAFKA_BROKERS=[192.168.9.110:9092,192.168.9.110:10092,192.168.9.96:9092,192.168.9.96:10092]
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: orderer
volumes:
- ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ../crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/msp:/var/hyperledger/orderer/msp
- ../crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/:/var/hyperledger/orderer/tls
ports:
- 7050:7050
extra_hosts:
- "zookeeper0:192.168.9.110"
- "zookeeper1:192.168.9.110"
- "zookeeper2:192.168.9.96"
- "kafka0:192.168.9.110"
- "kafka1:192.168.9.110"
- "kafka2:192.168.9.96"
- "kafka3:192.168.9.96"
peer及cli
version: '2'
services:
peer0.org2.example.com:
container_name: peer0.org2.example.com
image: hyperledger/fabric-peer
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2e_cli_default
- CORE_LOGGING_LEVEL=INFO
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
- CORE_PEER_PROFILE_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
- CORE_PEER_ID=peer0.org2.example.com
- CORE_PEER_ADDRESS=peer0.org2.example.com:7051
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
- CORE_PEER_CHAINCODEADDRESS=peer0.org2.example.com:7052
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
- CORE_PEER_LOCALMSPID=Org2MSP
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
ports:
- 7051:7051
- 7052:7052
- 7053:7053
extra_hosts:
- "orderer0.example.com:192.168.9.110"
- "orderer1.example.com:192.168.9.110"
- "orderer2.example.com:192.168.9.96"
cli:
container_name: cli
image: hyperledger/fabric-tools
tty: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.org2.example.com:7051
- CORE_PEER_LOCALMSPID=Org2MSP
- CORE_PEER_LOCALMSPTYPE=bccsp
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
volumes:
- /var/run/:/host/var/run/
- ../../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
- ../crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ../scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
- ../channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
depends_on:
- peer0.org2.example.com
extra_hosts:
- "orderer0.example.com:192.168.9.110"
- "orderer1.example.com:192.168.9.110"
- "orderer2.example.com:192.168.9.96"
- "peer0.org1.example.com:192.168.9.110"
- "peer1.org1.example.com:192.168.9.110"
- "peer0.org2.example.com:192.168.9.96"
- "peer1.org2.example.com:192.168.9.96"
注意:CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2e_cli_default 需将这些yaml文件目录修改为e2e_cli
3. zookeeper集群启动
docker-compose -f docker-compose-zookeeper.yaml up -d
4. kafka集群启动
docker-compose -f docker-compose-kafka.yaml up -d
5. 启动排序节点
docker-compose -f docker-compose-orderer.yaml up -d
6. 启动peer节点
docker-compose -f docker-compose-peer.yaml up -d
7. 启动fabric网络
7.1 创建通道
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
peer channel create -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls --cafile $ORDERER_CA
7.2 加入通道
peer channel join -b mychannel.block
7.3 安装及实例化链码
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd
peer chaincode instantiate -o orderer0.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","1000000000","b","2000000000"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
7.4 查询及调用链码
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
peer chaincode invoke -o orderer0.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
note: 通过修改环境变量指向其他peer
CORE_PEER_ADDRESS=peer0.org2.example.com:9051
CORE_PEER_ID=peer0.org2.example.com
CORE_PEER_LOCALMSPID=Org2MSP
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
菜鸟系列Fabric——Fabric 1.2 多机部署(3)的更多相关文章
- Fabric 1.0的多机部署
Fabric1.0已经正式发布一段时间了,官方给出的单机部署的脚本也很完备,基本上傻瓜式的一键部署,直接运行官方的network_setup.sh up即可.但是在实际生产环境,我们不可能把所有的节点 ...
- Inspiron 14 7000 系列 (7447) 游匣14 拆机图
Inspiron 14 7000 系列 (7447) 游匣14 拆机图 游匣配置不多说,i5起步,标配4G GTX850M显卡,这么霸道的配置给我玩扫雷肯定不卡.配置高功耗就大,不过游匣的散热 ...
- 开心菜鸟系列----函数作用域(javascript入门篇)
1 <!DOCTYPE html> 2 <html> 3 <script src="./jquery-1.7.2.js"></ ...
- 开心菜鸟系列----变量的解读(javascript入门篇)
console.info( console.info(window['weiwu']) console.info(window. ...
- Hyperledger Fabric1.4的多机部署
之前的文章深入解析Hyperledger Fabric启动的全过程主要讲解了Fabric的网络搭建,以及启动的整体流程,但是都是通过单机完成的.而区块链本身就是去中心化的,所以最终还是要完成Fabri ...
- Storm 系列(三)Storm 集群部署和配置
Storm 系列(二)Storm 集群部署和配置 本章中主要介绍了 Storm 的部署过程以及相关的配置信息.通过本章内容,帮助读者从零开始搭建一个 Storm 集群. 一.Storm 的依赖组件 1 ...
- SequoiaDB 系列之一 :SequoiaDB的安装、部署
在分析或者参与一个开源项目之前,了解项目构建的目的是有必要的. 既然SequoiaDB是NoSQL数据库产品,则必然存在于传统关系型数据库相同的功能点:数据的增.删.改和查询(CRUD). 先了解怎么 ...
- Xcode证书破解 iphone真机部署
Xcode证书破解 iphone真机部署 证书伪造: 先按照该教程的步骤添加证书.注意,原教程选择的是"系统"证书,这里我们用"登录"证书,切记. Xcode破 ...
- Java多机部署下的定时任务处理方案(mysql)
因为自己有csdn和博客园两个博客, 所以两边都会发一下. csdn地址: http://blog.csdn.net/u012881584/article/details/70194237 今天来说一 ...
随机推荐
- (已解决)FVDI 2018“连接到服务器.....失败”“打不开设备”
FVDI 2018 错误和解决方案来自网站:eobdtool.co.uk FVDI 2018发现以下错误: “连接到服务器.....失败” “设备未打开” 解决方案: 请下载FDVI 2018 V3. ...
- 在java下面配置xml导致idea编译失败
1.今天遇到一个问题在java配置dao.xml的时候导致,idea编译失败 然后把pom.xml上面的 <build> <resources> <resource> ...
- MessagePack Java 0.6.X 动态类型
我们知道 Java 是一个静态类型的语言.通过输入 Value MessagePack能够实现动态的特性. Value 有方法来检查自己的类型(isIntegerType(), isArrayType ...
- CDOJ 1269 ZhangYu Speech 数组处理
ZhangYu Speech Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- NOIP 模拟赛 那些年,我们学过的文化课 --致已退役的fqk神犇.
/* 这大概是我第一次整理模拟赛吧. 唉. T2打了很长时间. 一开始读错题了中间都能缩合了. 真心对不起生物老师hhh. 这种状态判重的题目还是做的太少! */ 背单词 [题目描述] fqk 退役后 ...
- 【CUDA 基础】3.3 并行性表现
title: [CUDA 基础]3.3 并行性表现 categories: - CUDA - Freshman tags: - nvprof toc: true date: 2018-04-15 21 ...
- 关于数据库表设计之区域表system_district:省市县街道四级地址表
关于省市县的数据表的设计有两种方式: 一.将其设计成一张表 DROP TABLE IF EXISTS `system_district`; CREATE TABLE `system_district` ...
- Docker进阶-快速扩容
1.命令方式 在创建好的Swarm集群中运行nginx服务,并使用--replicas参数指定启动的副本数. docker service create --replicas 3 -p 80:80 - ...
- (十六)C语言之函数
- 码云上webide怎么提交
修改后想提交,它会提示:“暂存文件后才能提交”, 我拿放大镜找遍了整个界面也没找到“暂存”按钮, 原来,文件旁边那个+号就是暂存,好歹鼠标方式去之后给个tip,服了. 点一下这个加号,提交按钮就可用了 ...