kafka配置详解笔记

  • 一、kafka集群搭建详细步骤
    • 1、装好jdk,并配置好zookeeper、hdfs集群
    • 2、下载好kafka安装包,解压。
    • 3、进入解压后的kafkaconfig目录,主要是server.properties(kafka配置文件)
      本文主要参考:http://blog.51cto.com/lee90/2067533,仅个人笔记使用。
cd /soft/kafka/config
vi /server.properties

修改如下:

#唯一的服务器id,每台机器分别不一样。
broker.id=001
#允许删掉主题
delete.topic.enable=true
#监听ip和端口
listeners=PLAINTEXT://192.168.56.131:9092
#监听端口
port=9092
#节点需要绑定的主机名称。如果没有设置,服务器会绑定到所有接口
host.name=192.168.56.131
#节点的主机名会通知给生产者和消费者。如果没有设置,它将会使用"host.name"的值(前提是设置了host.name)
#否则他会使用java.net.InetAddress.getCanonicalHostName()的返回值
advertised.listeners=PLAINTEXT://192.168.56.131:9092


# 接受网络请求的线程数
num.network.threads=3

# 进行磁盘IO的线程数
num.io.threads=8

# 套接字服务器使用的发送缓冲区大小
socket.send.buffer.bytes=102400

# 套接字服务器使用的接收缓冲区大小
socket.receive.buffer.bytes=102400

#  单个请求最大能接收的数据量
socket.request.max.bytes=104857600


#用来存储日志文件
log.dirs=/tmp/kafka-logs

# 每个主题的日志分区的默认数量。更多的分区允许更大的并行操作,但是它会导致节点产生更多的文件。副本数量,建议设置成3,免得单点故障
num.partitions=1

# 每个数据目录中的线程数,用于在启动时日志恢复,并在关闭时刷新。
num.recovery.threads.per.data.dir=1

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs here:
#    1. Durability: Unflushed data may be lost if you are not using replication.
#    2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
#    3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks.
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# 在强制刷新数据到磁盘执勤啊允许接收消息的数量
#log.flush.interval.messages=10000

# 在强制刷新之前,消息可以在日志中停留的最长时间
#log.flush.interval.ms=1000



#一个日志的最小存活时间,可以被删除
log.retention.hours=168

#  一个基于大小的日志保留策略。段将被从日志中删除只要剩下的部分段不低于log.retention.bytes。
#log.retention.bytes=1073741824

#  每一个日志段大小的最大值。当到达这个大小时,会生成一个新的片段。
log.segment.bytes=1073741824

# 检查日志段的时间间隔,看是否可以根据保留策略删除它们
log.retention.check.interval.ms=300000


# 这是一个以逗号为分割的部分,每一个都匹配一个Zookeeper,选举的时候依赖于zookeeper,写下zookeeper的地址
zookeeper.connect=192.168.56.130:2181,192.168.56.131:2181,192.168.56.132:2181

# 连接到Zookeeper的超时时间
zookeeper.connection.timeout.ms=6000
  • 二、启动kafka集群,在每一台kafka机器上启动kafka
/soft/kafka/bin/kafka-server-start.sh -daemon /opt/kafka/config/server.properties
  • 三、测试kafka的功能
    • 1.创建Tipic
    • #参数含义
    • –replication-factor 2 #复制两份
    • –partitions 2 #创建2个分区
    • –topic #主题

      kafka/bin/kafka-topics.sh --create --zookeeper node71:2181 --replication-factor 2 --partitions 3 --topic test
    • 2.在一台服务器上创建一个发布者

      kafka/bin/kafka-console-producer.sh --broker-list node72:9092 --topic test
    • 3.创建一个订阅者

      kafka/bin/kafka-console-consumer.sh --zookeeper node72:2181 --from-beginning --topic test
    • 4.查看所有的topic
    • –cluster1 指的是你配置的zookeeper的集群的名称,这个在core-site.xml里面设置的

      kafka/bin/kafka-topics.sh --list --zookeeper cluster1:2181
    • 5.查看指定的topic状态

      kafka/bin/kafka-topics.sh --describe --zookeeper node72:2181 --topic mysql-coupons
  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值