HyperLedger Fabric 1.4.4搭建基于多节点kafka共识集群
作者:互联网
修改configtx.yaml
配置文件
在SampleDevModeKafka
下增加kafka
的broker
节点,我增加后的内容如下
SampleDevModeKafka:
<<: *ChannelDefaults
Capabilities:
<<: *ChannelCapabilities
Orderer:
<<: *OrdererDefaults
OrdererType: kafka
Kafka:
Brokers:
- kafka1.example.com:9082
- kafka2.example.com:9083
- kafka3.example.com:9084
Organizations:
- *OrdererOrg
Capabilities:
<<: *OrdererCapabilities
Application:
<<: *ApplicationDefaults
Organizations:
- <<: *OrdererOrg
Consortiums:
SampleConsortium:
Organizations:
- *Org1
- *Org2
生成通道的创世区块
将原来solo
共识的命令改为如下命令
configtxgen -profile SampleDevModeKafka -channelID kafka-channel -outputBlock ./channel-artifacts/genesis.block
docker-compose-kafka.yaml
新建docker-compose-kafka.yaml
文件,内容如下:
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# NOTE: This is not the way a Kafka cluster would normally be deployed in production, as it is not secure
# and is not fault tolerant. This example is a toy deployment that is only meant to exercise the Kafka code path
# of the ordering service.
version: '2'
services:
zookeeper1.example.com:
container_name: zookeeper1.example.com
hostname: zookeeper1.example.com
image: hyperledger/fabric-zookeeper:latest
ports:
- "2171:2181"
- "2878:2878"
- "3878:3878"
environment:
# 这里是zookeeper客户端的端口号,一般无用
# 需要注意的是zookeeper的端口号依然是2181
# 所以一个主机装多个zookeeper的时候,需要将2181映射到外部的其他端口上
ZOOKEEPER_CLIENT_PORT: 32171
ZOOKEEPER_TICK_TIME: 2000
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zookeeper1.example.com:2878:3878 server.2=zookeeper2.example.com:2879:3879 server.3=zookeeper3.example.com:2880:3880
extra_hosts:
- "kafka1.example.com:10.1.24.225"
- "zookeeper2.example.com:10.1.24.225"
- "kafka2.example.com:10.1.24.225"
- "zookeeper3.example.com:10.1.24.225"
- "kafka3.example.com:10.1.24.225"
kafka1.example.com:
container_name: kafka1.example.com
image: hyperledger/fabric-kafka:latest
depends_on:
- zookeeper1.example.com
- zookeeper2.example.com
- zookeeper3.example.com
ports:
- "9082:9092"
environment:
# 因为kafka.example.com是容器名,并不是主机名,所以下面这一行一定要注释掉,否则是监听不到
# 不过个人猜测可以通过kafka设置外网监听的方式实现
# - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka.example.com:9092
- KAFKA_BROKER_ID=1
- KAFKA_ZOOKEEPER_CONNECT=zookeeper1.example.com:2171,zookeeper2.example.com:2172,zookeeper3.example.com:2173
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=3
- KAFKA_MESSAGE_MAX_BYTES=1048576 # 1 * 1024 * 1024 B
- KAFKA_REPLICA_FETCH_MAX_BYTES=1048576 # 1 * 1024 * 1024 B
- KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
- KAFKA_LOG_RETENTION_MS=-1
- KAFKA_MIN_INSYNC_REPLICAS=1
- KAFKA_DEFAULT_REPLICATION_FACTOR=3
extra_hosts:
- "zookeeper1.example.com:10.1.24.225"
- "zookeeper2.example.com:10.1.24.225"
- "kafka2.example.com:10.1.24.225"
- "zookeeper3.example.com:10.1.24.225"
- "kafka3.example.com:10.1.24.225"
zookeeper2.example.com:
container_name: zookeeper2.example.com
hostname: zookeeper2.example.com
image: hyperledger/fabric-zookeeper:latest
ports:
- "2172:2181"
- "2879:2879"
- "3879:3879"
environment:
ZOOKEEPER_CLIENT_PORT: 32172
ZOOKEEPER_TICK_TIME: 2000
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zookeeper1.example.com:2878:3878 server.2=zookeeper2.example.com:2879:3879 server.3=zookeeper3.example.com:2880:3880
extra_hosts:
- "zookeeper1.example.com:10.1.24.225"
- "kafka1.example.com:10.1.24.225"
- "kafka2.example.com:10.1.24.225"
- "zookeeper3.example.com:10.1.24.225"
- "kafka3.example.com:10.1.24.225"
kafka2.example.com:
container_name: kafka2.example.com
image: hyperledger/fabric-kafka:latest
depends_on:
- zookeeper1.example.com
- zookeeper2.example.com
- zookeeper3.example.com
ports:
- "9083:9092"
environment:
- KAFKA_BROKER_ID=2
- KAFKA_ZOOKEEPER_CONNECT=zookeeper1.example.com:2171,zookeeper2.example.com:2172,zookeeper3.example.com:2173
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=3
- KAFKA_MESSAGE_MAX_BYTES=1048576 # 1 * 1024 * 1024 B
- KAFKA_REPLICA_FETCH_MAX_BYTES=1048576 # 1 * 1024 * 1024 B
- KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
- KAFKA_LOG_RETENTION_MS=-1
- KAFKA_MIN_INSYNC_REPLICAS=1
- KAFKA_DEFAULT_REPLICATION_FACTOR=3
extra_hosts:
- "zookeeper1.example.com:10.1.24.225"
- "kafka1.example.com:10.1.24.225"
- "zookeeper2.example.com:10.1.24.225"
- "zookeeper3.example.com:10.1.24.225"
- "kafka3.example.com:10.1.24.225"
zookeeper3.example.com:
container_name: zookeeper3.example.com
hostname: zookeeper3.example.com
image: hyperledger/fabric-zookeeper:latest
ports:
- "2173:2181"
- "2880:2880"
- "3880:3880"
environment:
ZOOKEEPER_CLIENT_PORT: 32173
ZOOKEEPER_TICK_TIME: 2000
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zookeeper1.example.com:2878:3878 server.2=zookeeper2.example.com:2879:3879 server.3=zookeeper3.example.com:2880:3880
extra_hosts:
- "zookeeper1.example.com:10.1.24.225"
- "kafka1.example.com:10.1.24.225"
- "zookeeper2.example.com:10.1.24.225"
- "kafka2.example.com:10.1.24.225"
- "kafka3.example.com:10.1.24.225"
kafka3.example.com:
container_name: kafka3.example.com
image: hyperledger/fabric-kafka:latest
depends_on:
- zookeeper1.example.com
- zookeeper2.example.com
- zookeeper3.example.com
ports:
- "9084:9092"
environment:
- KAFKA_BROKER_ID=3
- KAFKA_ZOOKEEPER_CONNECT=zookeeper1.example.com:2171,zookeeper2.example.com:2172,zookeeper3.example.com:2173
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=3
- KAFKA_MESSAGE_MAX_BYTES=1048576 # 1 * 1024 * 1024 B
- KAFKA_REPLICA_FETCH_MAX_BYTES=1048576 # 1 * 1024 * 1024 B
- KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
- KAFKA_LOG_RETENTION_MS=-1
- KAFKA_MIN_INSYNC_REPLICAS=1
- KAFKA_DEFAULT_REPLICATION_FACTOR=3
extra_hosts:
- "zookeeper1.example.com:10.1.24.225"
- "kafka1.example.com:10.1.24.225"
- "zookeeper2.example.com:10.1.24.225"
- "kafka2.example.com:10.1.24.225"
- "zookeeper3.example.com:10.1.24.225"
启动
启动的时候带上-f docker-compose-kafka.yaml
即可
标签:1.4,10.1,Fabric,kafka,zookeeper1,24.225,KAFKA,com,example 来源: https://blog.csdn.net/qq_39800434/article/details/105265047