菜鸟系列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、生成公私钥和证书
[[email protected] 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/[email protected]/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/[email protected]/msp

原文地址:https://www.cnblogs.com/jiliguo/p/10885329.html

时间: 2024-10-08 20:41:56

菜鸟系列Fabric——Fabric 1.2 多机部署(3)的相关文章

Tungsten Fabric与K8s集成指南丨部署准备与初始状态

Hi!欢迎来到Tungsten Fabric与Kubernetes集成指南系列,本文介绍K8s组件和Tungsten Fabric组件部署的准备工作,以及运行的初始状态.Tungsten Fabric与K8s集成指南系列文章,由TF中文社区为您呈现,旨在帮助大家了解Tungsten Fabric与K8s集成的基础知识.大家在相关部署中有什么经验,或者遇到的问题,欢迎与我们联系. 说明:文中部分内容涉及到"Contrail",Tungsten Fabric原名为OpenContrail,

菜鸟系列之C/C++经典试题(三)

设计包含min函数的栈 题目:定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素.要求函数min.push以及pop的时间复杂度都是O(1). 分析:这是2006年google的一道面试题. 我看到这道题目时,第一反应就是每次push一个新元素时,将栈里所有逆序元素排序.这样栈顶元素将是最小元素.但由于不能保证最后push进栈的元素最先出栈,这种思路设计的数据结构已经不是一个栈了. 在栈里添加一个成员变量存放最小元素(或最小元素的位置).每次push一个新元素进栈的时候,如果该元素比

[Fabric]Fabric With Nohup 执行方式

Fabric是Python的远程SSH命令行工具,常用来实现服务远程管理及持续化部署.最近需要在集群中执行离线任务,在官方文档中有例子 <span style="font-family: Arial, Helvetica, sans-serif;">run("nohup yes >& /dev/null < /dev/null &")</span> 但按照这种写法在实际操作中并无法正确执行相应的任务,折腾一阵后发现

菜鸟系列之C/C++经典试题(一)

这个我写菜鸟系列之C/C++ 的第一篇文章 题目:输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表.要求不能创建任何新的结点,只调整指针的指向. 比如将二元查找树 10 /    \ 6       14 /  \     / \ 4     8  12   16 转换成双向链表 4=6=8=10=12=14=16. 分析:本题是微软的面试题.很多与树相关的题目都是用递归的思路来解决,本题也不例外.下面我们用两种不同的递归思路来分析. 思路一:当我们到达某一结点准备调整以该结点为根结点

菜鸟系列之C/C++经典试题(二)

求子数组的最大和 题目描述: 输入一个整形数组,数组里有正数也有负数.数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和.求所有子数组的和的最大值.要求时间复杂度为O(n). 例如输入的数组为1, -2, 3, 10, -4, 7, 2, -5,和最大的子数组为3, 10, -4,7, 2,因此输出为该子数组的和18. 这个问题在各大公司面试中出现频率之频繁,被人引用次数之多,非一般面试题可与之匹敌.ok,下面,咱们来一步一步分析这个题. 分析与解法 解法一 求一个数组的最大子数组和

Java设计模式菜鸟系列总结及博客全目录

转载请注明出处:http://blog.csdn.net/lhy_ycu/article/details/40031567 今天来对这23种设计模式做个总结.咱使用设计模式的目的是为了可重用代码.让代码更容易被他人理解.保证代码可靠性,当然设计模式并不是万能的,项目中的实际问题还有具体分析.咱不能为了使用设计模式而使用,而是在分析问题的过程中,想到使用某种设计模式能达到咱需要的效果,而且比不使用设计模式更有优势,那么咱该考虑使用设计模式了. 一.设计模式的一般分类 创建型(Creator)模式(

PowerShell 运维菜鸟系列-02-批量取n台Windows KEY(2018年大年初一奉献)

系列博文: PowerShell 运维菜鸟系列-01-批量为n台服务器导入PFX证书(2017年除夕奉献) http://blog.51cto.com/dynamic/2071716 项目场景: 2017年,某客户忽然来电:"我们单位正在查正版,我想知道所有加域的Windows电脑的激活KEY分别是什么?". 详细需求: 1. 操作系统版本 Windows XP.Windows 7.Windows 10.Windows Server 2003.Windows Server 2008 R

Lucene/Solr搜索引擎开发系列 - 第2章 Solr安装与部署(Tomcat篇)

一.安装环境 图1-1 Tomcat和Solr的版本     我本机目前使用的Java版本为JDK 1.8,因为Solr 4.9要求Java版本为1.7+,请注意. 二.Solr部署到Tomcat流程 图1-2 Tomcat安装目录     1.如图1-2所示,为Tomcat的解压目录: 图1-3 Tomcat首页     2.在目录E:\apache-tomcat-8.0.9\bin中,找到startup.bat文件,双击该文件,启动Tomcat服务器,等待几秒钟后,在浏览器中输入http:/

Open-E DSS V7 应用系列之九 主动/主动 iSCSI群集部署(一)

续Open-E DSS V7 应用系列之八 远程访问和管理员密码恢复 一.群集的定义和分类 群集就是由一些互相连接在一起的计算机构成的一个并行或分布式系统,从外部来看,它们仅仅是一个系统,对外提供统一的服务.高可用性是它的显著特点之一. 群集按平台提供商可以分类OS平台提供商,数据库平台提供商,应用服务器平台提供商,存储提供商等:按实现功能可以分为High availability clusters(Fail-over Cluster) 高可用性(故障转移)群集.High performance