Kafka单机多节点部署

基于Kafka单机单节点部署,讲config目录下的server.properties文件复制两份,分别为 server-1.properties 、server-2.properties

> cp config/server.properties config/server-1.properties
> cp config/server.properties config/server-2.properties

对 server-1.properties 、server-2.properties的配置进行修改(端口、brokerId、日志目录)
1 Vim config/server-1.properties:
2     broker.id=1
3     listeners=PLAINTEXT://:9093
4     log.dir=/tmp/kafka-logs-1
5  
6 Vim config/server-2.properties:
7     broker.id=2
8     listeners=PLAINTEXT://:9094
9     log.dir=/tmp/kafka-logs-2

broker.id属性是集群中每个节点的名称,这一名称是唯一且永久的。我们必须重写端口和日志目录,因为我们在同一台机器上运行这些,我们不希望所有的代理尝试在同一个端口注册,或者覆盖彼此的数据。
我们已经建立Zookeeper和一个Kafka Broker了,现在我们只需要启动两个新的节点:
1 > nohup ./kafka-server-start.sh ../config/server-1.properties &
3 > nohup ./kafka-server-start.sh ../config/server-2.properties &

此时,我们的Kafka集群为 三个Broker,单Zookeeper。

验证:
① 创建一个副本为3的新topic:
./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic

②查看topic信息:
./kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic

Topic:my-replicated-topic   PartitionCount:1    ReplicationFactor:3 Configs:
  Topic: my-replicated-topic  Partition: 0    Leader: 1   Replicas: 1,2,0 Isr: 1,2,0

③启动生产者

./kafka-console-producer.sh --broker-list localhost:9092 --topic my-replicated-topic

④启动消费者
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic my-replicated-topic

⑤让我们来测试一 下容错性。 Broker 1 现在是 leader,让我们来杀了它:

ps -ef | grep server-1.properties

kill -9 pid

⑥查看topic信息:

发现领导权已经切换到一个从属节点,而且节点1也不在同步副本集中了.

猜你喜欢

转载自www.cnblogs.com/malcolmfeng/p/13372081.html