KAFKA安装

第2章 Kafka快速入门
2.1 安装部署
2.1.1 集群规划
hadoop102

hadoop103

hadoop104

zk

zk

zk

kafka

kafka

kafka

2.1.2 jar包下载
http://kafka.apache.org/downloads

2.1.3 集群部署
1)解压安装包

[atguigu@hadoop102 software]$ tar -zxvf kafka_2.11-2.4.1.tgz -C /opt/module/

2)修改解压后的文件名称

[atguigu@hadoop102 module]$ mv kafka_2.11-2.4.1/ kafka

3)在/opt/module/kafka目录下创建logs文件夹

[atguigu@hadoop102 kafka]$ mkdir logs

4)修改配置文件

[atguigu@hadoop102 kafka]$ cd config/

[atguigu@hadoop102 config]$ vi server.properties

修改或者增加以下内容:

#broker的全局唯一编号,不能重复

broker.id=0

#删除topic功能使能

delete.topic.enable=true

#kafka运行日志存放的路径

log.dirs=/opt/module/kafka/logs

#配置连接Zookeeper集群地址

zookeeper.connect=hadoop102:2181,hadoop103:2181,hadoop104:2181/kafka

5)配置环境变量

[atguigu@hadoop102 module]$ sudo vi /etc/profile.d/env.sh

#KAFKA_HOME

export KAFKA_HOME=/opt/module/kafka

export PATH= P A T H : PATH: PATH:KAFKA_HOME/bin

[atguigu@hadoop102 module]$ source /etc/profile.d/env.sh

6)分发安装包

[atguigu@hadoop102 module]$ xsync kafka/

注意:分发之后记得配置其他机器的环境变量

7)分别在hadoop103和hadoop104上修改配置文件/opt/module/kafka/config/server.properties中的broker.id=1、broker.id=2

注:broker.id不得重复

7)启动集群

依次在hadoop102、hadoop103、hadoop104节点上启动kafka

[atguigu@hadoop102 kafka]$ bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties

[atguigu@hadoop103 kafka]$ bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties

[atguigu@hadoop104 kafka]$ bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties

8)关闭集群

[atguigu@hadoop102 kafka]$ bin/kafka-server-stop.sh

[atguigu@hadoop103 kafka]$ bin/kafka-server-stop.sh

[atguigu@hadoop104 kafka]$ bin/kafka-server-stop.sh

9)kafka群起脚本

1)在/home/atguigu/bin目录下创建脚本kf.sh

[atguigu@hadoop102 bin]$ vim kf.sh

在脚本中填写如下内容

#! /bin/bash

case $1 in

“start”){

for i in hadoop102 hadoop103 hadoop104

do

    echo " --------启动 $i Kafka-------"

    ssh $i "/opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties "

done

};;

“stop”){

for i in hadoop102 hadoop103 hadoop104

do

    echo " --------停止 $i Kafka-------"

    ssh $i "/opt/module/kafka/bin/kafka-server-stop.sh stop"

done

};;

esac

2)增加脚本执行权限

[atguigu@hadoop102 bin]$ chmod 777 kf.sh

3)kf集群启动脚本

[atguigu@hadoop102 module]$ kf.sh start

4)kf集群停止脚本

[atguigu@hadoop102 module]$ kf.sh stop

2.2 Kafka命令行操作
1)查看当前服务器中的所有topic

[atguigu@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181/kafka --list

2)创建topic

[atguigu@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181/kafka \

–create --replication-factor 3 --partitions 1 --topic first

选项说明:

–topic 定义topic名

–replication-factor 定义副本数

–partitions 定义分区数

3)删除topic

[atguigu@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181/kafka \

–delete --topic first

需要server.properties中设置delete.topic.enable=true否则只是标记删除。

4)发送消息

[atguigu@hadoop102 kafka]$ bin/kafka-console-producer.sh \

–broker-list hadoop102:9092 --topic first

hello world

atguigu atguigu

5)消费消息

[atguigu@hadoop103 kafka]$ bin/kafka-console-consumer.sh \

–bootstrap-server hadoop102:9092 --from-beginning --topic first

[atguigu@hadoop103 kafka]$ bin/kafka-console-consumer.sh \

–bootstrap-server hadoop102:9092 --from-beginning --topic first

–from-beginning:会把主题中以往所有的数据都读取出来。

6)查看某个Topic的详情

[atguigu@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181/kafka \

–describe --topic first

7)修改分区数

[atguigu@hadoop102 kafka]$bin/kafka-topics.sh --zookeeper hadoop102:2181/kafka --alter --topic first --partitions 6

第5章 Kafka监控(Kafka Eagle)
1)修改kafka启动命令

修改kafka-server-start.sh命令中

if [ “x$KAFKA_HEAP_OPTS” = “x” ]; then

export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"

fi

if [ “x$KAFKA_HEAP_OPTS” = “x” ]; then

export KAFKA_HEAP_OPTS="-server -Xms2G -Xmx2G -XX:PermSize=128m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=8 -XX:ConcGCThreads=5 -XX:InitiatingHeapOccupancyPercent=70"

export JMX_PORT="9999"

#export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"

fi

注意:修改之后在启动Kafka之前要分发之其他节点

2)上传压缩包kafka-eagle-bin-1.3.7.tar.gz到集群/opt/software目录

3)解压到本地

[atguigu@hadoop102 software]$ tar -zxvf kafka-eagle-bin-1.3.7.tar.gz

4)进入刚才解压的目录

[atguigu@hadoop102 kafka-eagle-bin-1.3.7]$ ll

总用量 82932

-rw-rw-r–. 1 atguigu atguigu 84920710 8月 13 23:00 kafka-eagle-web-1.3.7-bin.tar.gz

5)将kafka-eagle-web-1.3.7-bin.tar.gz解压至/opt/module

[atguigu@hadoop102 kafka-eagle-bin-1.3.7]$ tar -zxvf kafka-eagle-web-1.3.7-bin.tar.gz -C /opt/module/

6)修改名称

[atguigu@hadoop102 module]$ mv kafka-eagle-web-1.3.7/ eagle

7)给启动文件执行权限

[atguigu@hadoop102 eagle]$ cd bin/

[atguigu@hadoop102 bin]$ ll

总用量 12

-rw-r–r--. 1 atguigu atguigu 1848 8月 22 2017 ke.bat

-rw-r–r--. 1 atguigu atguigu 7190 7月 30 20:12 ke.sh

[atguigu@hadoop102 bin]$ chmod 777 ke.sh

8)修改配置文件

######################################

multi zookeeper&kafka cluster list

######################################

kafka.eagle.zk.cluster.alias=cluster1

cluster1.zk.list=hadoop102:2181,hadoop103:2181,hadoop104:2181

######################################

kafka offset storage

######################################

cluster1.kafka.eagle.offset.storage=kafka

######################################

enable kafka metrics

######################################

kafka.eagle.metrics.charts=true

kafka.eagle.sql.fix.error=false

######################################

kafka jdbc driver address

######################################

kafka.eagle.driver=com.mysql.jdbc.Driver

kafka.eagle.url=jdbc:mysql://hadoop102:3306/ke?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull

kafka.eagle.username=root

kafka.eagle.password=000000

9)添加环境变量

export KE_HOME=/opt/module/eagle

export PATH= P A T H : PATH: PATH:KE_HOME/bin

注意:source /etc/profile

10)启动

[atguigu@hadoop102 eagle]$ bin/ke.sh start

… …

… …


  • Kafka Eagle Service has started success.

  • Welcome, Now you can visit ‘http://192.168.9.102:8048/ke’

  • Account:admin ,Password:123456


  • ke.sh [start|status|stop|restart|stats]

  • https://www.kafka-eagle.org/


[atguigu@hadoop102 eagle]$

注意:启动之前需要先启动ZK以及KAFKA

11)登录页面查看监控数据

http://192.168.9.102:8048/ke

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值