kafka 2.11 安装和测试(Linux环境)

10 篇文章 0 订阅
6 篇文章 0 订阅
本文档详细介绍了如何在Linux环境下安装和配置Apache Kafka 2.11版本,包括设置Zookeeper、启动Kafka服务、创建及管理topics,以及进行生产者和消费者的测试。此外,还提供了配置文件`server.properties`的关键参数说明,并展示了添加环境变量和启动Kafka的步骤。
摘要由CSDN通过智能技术生成

kafka 2.11 安装和测试(Linux环境)

安装前最好已安装有zookeeper
启动zookeeper

zkServer.sh start 

下载
下载地址:

http://kafka.apache.org/downloads.html 我这里下载的是Scala 2.11对应的 kafka_2.11-2.0.0.tgz

上传解压缩

 tar -xf kafka_2.11-2.0.0.tgz 
mv kafka_2.11-2.0.0 kafka

创建日志目录

  cd kafka
  mkdir logs

修改配置文件
进入kafka的安装配置目录

 cd config/
vi server.properties

############################# Server Basics #############################

The id of the broker. This must be set to a unique integer for each broker.

broker.id=0


#是否允许删除topic,默认false不能手动删除
delete.topic.enable=true


############################# Socket Server Settings #############################

# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092

listeners=PLAINTEXT://192.168.254.100:9092


# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3

# The number of threads that the server uses for processing requests, which may include disk I/O
num.io.threads=8

############################# Log Basics #############################

# A comma separated list of directories under which to store log files

log.dirs=/usr/local/data/servers/kafka/logs


# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=1

# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1

############################# Internal Topic Settings  #############################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended for to ensure availability such as 3.
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1



############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion due to age
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

#是否启用log压缩,一般不用启用,启用的话可以提高性能
log.cleaner.enable=false


############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.

zookeeper.connect=node01:2181,node02:2181,node03:2181


# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000

添加环境变量
vi /etc/profile

#KAFKA_HOME
export KAFKA_HOME=/opt/module/kafka_2.11-1.1.0
export PATH=$PATH:$KAFKA_HOME/bin

保存使其立即生效

source /etc/profile

后台启动Kafka集群服务

kafka-server-start.sh  config/server.properties &

创建主题topic

kafka-topics.sh --create --zookeeper  192.168.254.100:2181 --replication-factor 1 --partitions 1 --topic dbtopic01

查看topic副本信息


 kafka-topics.sh --describe --zookeeper 192.168.254.100:2181 --topic dbtopic01

查看已经创建的topic信息


 kafka-topics.sh --list --zookeeper 192.168.254.100:2181

测试生产者发送消息


bin/kafka-console-producer.sh --broker-list 192.168.254.100:9092 --topic  dbtopic01

随便输入一些消息,可以多行

测试消费者消费消息

bin/kafka-console-consumer.sh --bootstrap-server  192.168.254.100:9092   --topic  dbtopic01--from-beginning 

就可以看到你刚才发送的消息了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值