centos7.5安装kafka(支持外部连接)

13 篇文章 0 订阅
  • 安装kafka之前确保安装环境已经安装好jdk以及zk,并启动,以上有详细步骤,这里不再重复.

  • zk安装地址https://blog.csdn.net/LXYuuuuu/article/details/107605769

  • 上传相应kafka安装包到/export/software/

  • tar -zxvf kafka_2.11-1.0.0.tgz -C /export/servers/

  • cd /export/servers/kafka_2.11-1.0.0/config/

  • vim server.properties

    • 文件只保留以下内容,其余均注释掉即可
      broker.id=0
      host.name=本机ip(本处可直接设置为localhost,如果想让其他机器连接,需要设置成本机ip,如遇到腾讯云环境部署时,因威望地址在ifconfig中查不到,所以可以直接编写ifconfig中显示的内网地址,访问时外网内部映射找到内网该服务)
      num.network.threads=3
      num.io.threads=8
      socket.send.buffer.bytes=102400
      socket.receive.buffer.bytes=102400
      socket.request.max.bytes=104857600
      log.dirs=/export/servers/kafka_2.11-1.0.0/kafka-logs(本处文件夹需自己手动创建)
      log.cleaner.enable=true
      num.partitions=1
      num.recovery.threads.per.data.dir=1
      offsets.topic.replication.factor=1
      transaction.state.log.replication.factor=1
      transaction.state.log.min.isr=1
      log.retention.hours=168
      log.segment.bytes=1073741824
      log.retention.check.interval.ms=300000
      zookeeper.connect=本机ip:2181(地址可设置为localhost,同时也可设置为本机安装zk的ip)
      zookeeper.connection.timeout.ms=6000
      group.initial.rebalance.delay.ms=0
      
  • cd . ./

  • mkdir kafka-logs(创建配置文件中提到的log目录)

  • 开始启动kafka

    • nohup bin/kafka-server-start.sh config/server.properties >> /dev/null &
      
      上面代码nohup代表把任务放到后台作为服务运行,有些脚本不像之前的二进制程序一样可以一直跑在服务器上,虽然后面加上&表示在后台运行,但是一段时间后可能会退出,nohup可以让程序一直跑在后台,输入以上命令后命令行会卡住,然后需要再次输入一次回车回到命令行,另外我们退出shell时必须使用logout退出,切不可直接关闭窗口,否则程序也可能异常退出
      
  • 创建一个消息队列

    • bin/kafka-topics.sh --create --replication-factor 1 --partitions 1 --topic test --zookeeper 本机ip(server.properties里面配置的对应信息):2181
      
      创建队列的时候,replication-factor只能是1个,因为是单节点,而partitions分区可以是1个或者2个都可以,测试环境建议是1个即可
      
      查看topic
      bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --list
      
  • 创建一个消费者

    • bin/kafka-console-consumer.sh --zookeeper 本机ip(server.properties里面配置的对应信息):2181 --topic test
      如果上述方式报错可采用如下方式
      bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic logtopic --from-beginning
      
  • 新开窗口,进入kafka目录,创建一个生产者

    • bin/kafka-console-producer.sh --broker-list 本机ip(server.properties里面配置的对应信息):9092 --topic test
      
    • 同样这个时候命令行进入运行状态,输入一个字符串
      在这里插入图片描述

  • 此时打开刚才创建消费者的窗口,会看到刚才的输入消息被消费了
    在这里插入图片描述

  • 到现在,Kafka单机消息队列基本的配置和运行都是正常的,单机环境配置基本上就是这些

  • 同时可用jps查看当前服务器上运行的服务情况

  • 常用命令

查看策列:bin/kafka-configs.sh --zookeeper --zookeeper ip:2181 --describe --entity-type topics --entity-name test2m

后台启动: nohup bin/kafka-server-start.sh config/server.properties >> /dev/null &

消息队列:bin/kafka-topics.sh --create --replication-factor 1 --partitions 1 --topic test2m --zookeeper ip:2181

消费者:bin/kafka-console-consumer.sh --zookeeper ip:2181 --topic test2m

生产者: bin/kafka-console-producer.sh --broker-list ip:9092 --topic test2m

topic 查询:bin/kafka-topics.sh --list  --zookeeper ip:2181

kafka必须配置参数delete.topic.enable=true
topic 删除:./bin/kafka-topics.sh --zookeeper ip:2181 --delete  --topic topicName
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值