Kafka集群部署

本文详细介绍了如何在多台QFS服务器上部署Kafka 2.11-2.4.1集群,包括下载、配置、启动/停止服务、创建和管理topic,以及查看topic信息。重点展示了如何设置broker ID、监听器、日志目录和Zookeeper连接,并通过SSH脚本实现集群操作的自动化。
摘要由CSDN通过智能技术生成

Kafka集群部署

服务器基本信息

qfs服务器IP安装服务用户名host
12.0.2.23kafka_2.11-2.4.1mppadminqfs004
12.0.2.24kafka_2.11-2.4.1mppadminqfs005
12.0.2.25kafka_2.11-2.4.1mppadminqfs006
12.0.2.26kafka_2.11-2.4.1mppadminqfs007
12.0.2.27kafka_2.11-2.4.1mppadminqfs008
12.0.2.28kafka_2.11-2.4.1mppadminqfs009

1 部署kafka集群

1.1 下载安装包,解压

tar -xzf kafka_2.11-2.4.1.tgz
cd kafka_2.11-2.4.1
mkdir kafka-logs
cd config
vim server.properties

1.2 修改配置文件

############################# Server Basics #############################
broker.id=0
############################# Socket Server Settings #############################
listeners=PLAINTEXT://12.0.2.23:9092
############################# Log Basics #############################
log.dirs=/home/mppadmin/kafka_2.11-2.4.1/kafka-logs
############################# Zookeeper #############################
zookeeper.connect=12.0.2.20:2181,12.0.2.21:2181,12.0.2.22:2181

1.3 修改后kafka_2.11-2.4.1拷贝至其他节点

其他节点修改server.properties

############################# Server Basics #############################
broker.id=1
############################# Socket Server Settings #############################
listeners=PLAINTEXT://12.0.2.24:9092

2 配置集群启动停止服务

每个节点配置kafka全局变量

# KAFKA_HOME author:liuyy
export KAFKA_HOME=/home/mppadmin/kafka_2.11-2.4.1
export PATH=$KAFKA_HOME/bin:$PATH

集群启动停止服务

#! /bin/bash

# Kafka代理节点地址
hosts=(qfs004 qfs005 qfs006 qfs007 qfs008 qfs009)

# 打印启动分布式脚本信息
mill=`date "+%N"`
tdate=`date "+%Y-%m-%d %H:%M:%S,${mill:0:3}"`

echo [$tdate] INFO [Kafka Cluster] begins to execute the $1 operation.

# 执行分布式开启命令    
function start()
{       
        for i in ${hosts[@]}
                do      
                        smill=`date "+%N"`
                        stdate=`date "+%Y-%m-%d %H:%M:%S,${smill:0:3}"`                        ssh mppadmin@$i "source /etc/profile;echo [$stdate] INFO [Kafka Broker $i] begins to execute the startup operation.;kafka-server-start.sh $KAFKA_HOME/config/server.properties>/dev/null" &
                        sleep 1
                done
}

# 执行分布式关闭命令    
function stop()
{
        for i in ${hosts[@]}
                do
                        smill=`date "+%N"`
                        stdate=`date "+%Y-%m-%d %H:%M:%S,${smill:0:3}"`
                        ssh mppadmin@$i "source /etc/profile;echo [$stdate] INFO [Kafka Broker $i] begins to execute the shutdown operation.;kafka-server-stop.sh>/dev/null;" &
                        sleep 1
                done
}
# 查看Kafka代理节点状态
function status()
{
        for i in ${hosts[@]}
                do
                        smill=`date "+%N"`
                        stdate=`date "+%Y-%m-%d %H:%M:%S,${smill:0:3}"`
                        ssh mppadmin@$i "source /etc/profile;echo [$stdate] INFO [Kafka Broker $i] status message is :;jps | grep Kafka;" &
                        sleep 1
                done
}

# 判断输入的Kafka命令参数是否有效
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status
        ;;
    *)
        echo "Usage: $0 {start|stop|status}"
        RETVAL=1
esac

验证

[mppadmin@qfs004 ~]$ kafka-daemons.sh start
[2021-02-04 09:08:05,711] INFO [Kafka Cluster] begins to execute the start operation.
[2021-02-04 09:08:05,716] INFO [Kafka Broker qfs004] begins to execute the startup operation.
[2021-02-04 09:08:06,722] INFO [Kafka Broker qfs005] begins to execute the startup operation.
[2021-02-04 09:08:07,729] INFO [Kafka Broker qfs006] begins to execute the startup operation.
[2021-02-04 09:08:08,735] INFO [Kafka Broker qfs007] begins to execute the startup operation.
[2021-02-04 09:08:09,743] INFO [Kafka Broker qfs008] begins to execute the startup operation.
[2021-02-04 09:08:10,750] INFO [Kafka Broker qfs009] begins to execute the startup operation.

3 创建topic

[mppadmin@qfs004 ~]$  kafka-topics.sh --create -zookeeper qfs001:2181,qfs002:2181,qfs003:2181 --replication-factor 1 --partitions 12 --topic test
Created topic test.

4 查看topic信息

mppadmin@qfs004 ~]$ kafka-topics.sh --describe --zookeeper qfs001:2181,qfs002:2181,qfs003:2181 --topic test
Topic: test	PartitionCount: 12	ReplicationFactor: 1	Configs: 
	Topic: test	Partition: 0	Leader: 4	Replicas: 4	Isr: 4
	Topic: test	Partition: 1	Leader: 5	Replicas: 5	Isr: 5
	Topic: test	Partition: 2	Leader: 0	Replicas: 0	Isr: 0
	Topic: test	Partition: 3	Leader: 1	Replicas: 1	Isr: 1
	Topic: test	Partition: 4	Leader: 2	Replicas: 2	Isr: 2
	Topic: test	Partition: 5	Leader: 3	Replicas: 3	Isr: 3
	Topic: test	Partition: 6	Leader: 4	Replicas: 4	Isr: 4
	Topic: test	Partition: 7	Leader: 5	Replicas: 5	Isr: 5
	Topic: test	Partition: 8	Leader: 0	Replicas: 0	Isr: 0
	Topic: test	Partition: 9	Leader: 1	Replicas: 1	Isr: 1
	Topic: test	Partition: 10	Leader: 2	Replicas: 2	Isr: 2
	Topic: test	Partition: 11	Leader: 3	Replicas: 3	Isr: 3

5 查看所有topic信息

[mppadmin@qfs004 ~]$ kafka-topics.sh --zookeeper qfs001:2181,qfs002:2181,qfs001:2181 --list
test

6 消费test

kafka-console-consumer.sh --bootstrap-server 12.0.2.23:9092 --topic test --from-beginning
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值