coder

CentOS上安装Kafka(单点入门)

2018-08-26  本文已影响0人  不重要的小编辑

安装

1.进入官网获取安装资源 http://kafka.apache.org/downloads

wget http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.0.0/kafka_2.11-2.0.0.tgz

2.解压安装包

tar -zxvf kafka_2.11-2.0.0.tgz

修改配置文件

vim server.properties

相关注释:

broker.id=0 设置每一个节点的ID,且该ID属于唯一值

log.dirs=/tmp/kafka-logs 设置消息持久化目录

zookeeper.connect=192.168.16.139:2181 设置zookeeper链接地址,多个地址使用英文逗号分隔

listeners=PLAINTEXT://192.168.16.139:9092 服务器监听的地址,如果不配置从java.net.InetAddress.getCanonicalHostName()获得。在配置集群的时候,必须设置

注意:在集群的时候,broker.id和listeners不能相同

服务启停

1.启动。-daemon以守护进程方式启动kafka server

./bin/kafka-server-start.sh -daemon config/server.properties

启动后输入命令jps查看是否启动成功,若出现

说明启动成功

2.停止

./bin/kafka-server-stop.sh

3.附启动脚本

#!/bin/bash

#chkconfig:2345 20 90

#description:kafka

#processname:kafka

export JAVA_HOME=/soft/jdk1.8.0_201

case $1 in

        start) /soft/kafka_2.11-2.0.0/bin/kafka-server-start.sh -daemon /soft/kafka_2.11-2.0.0/config/server.properties;;

        stop) /soft/kafka_2.11-2.0.0/bin/kafka-server-stop.sh;;

        status) /soft/jdk1.8.0_201/bin/jps;;

        restart)

                /soft/kafka_2.11-2.0.0/bin/kafka-server-stop.sh

                /soft/kafka_2.11-2.0.0/bin/kafka-server-start.sh -daemon /soft/kafka_2.11-2.0.0/config/server.properties

        ;;

        *) echo "require start|stop|status|restart" ;;

esac

消息收发

1.创建主题

./bin/kafka-topics.sh --create --zookeeper 192.168.16.139:2181 --replication-factor 1 --partitions 1 --topic test-topic

创建成功后可看到 Created topid "xxx"

2.查看主题/消息

./bin/kafka-topics.sh --list --zookeeper 192.168.16.139:2181

./bin/kafka-topics.sh --describe --zookeeper 192.168.16.139:2181 --topic test-topic

3.删除主题

./bin/kafka-topics.sh --delete --zookeeper 192.168.16.139:2181 --topic test-topic

3.发送主题消息

./bin/kafka-console-producer.sh --broker-list 192.168.16.139:9092 --topic test-topic

4.消费主题消息

./bin/kafka-console-consumer.sh --bootstrap-server 192.168.16.139:9092 --topic test-topic --from-beginning --partition 0

监控插件 kafka eagle

1.安装包下载 http://download.smartloli.org/

2.将下载好的安装包上传至服务器,然后使用 tar -zxvf kafka-eagle-bin-1.3.0.tar.gz 进行解压。解压后,会得到另外一个压缩包,继续将其加压。

3.修改环境变量,增加 JAVA_HONE 和 KE_HOME

vim /etc/profile

#kafka-eagle-web-1.3.0

export KE_HOME=/soft/kafka-eagle-web-1.3.0

export PATH=$PATH:$KE_HOME/bin

source /etc/profile

4.修改 kafka-eagle 配置文件

vim conf/system-config.properties

kafka.eagle.zk.cluster.alias=cluster1

cluster1.zk.list=192.168.16.139:2181

kafka.eagle.webui.port=8048

kafka.eagle.metrics.charts=true

kafka.eagle.sql.fix.error=true

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

kafka.eagle.url=jdbc:mysql://127.0.0.1:3306/kafka?useSSL=true&characterEncoding=utf8&useUnicode=true&serverTimezone=UTC

kafka.eagle.username=username

kafka.eagle.password=password

5.保存退出后,为启动文件授权 chmod +x bin/ke.sh

6.启停 ./bin/ke.sh start [ ./bin/ke.sh stop]

7.附开机自启动相关命令与脚本

vim /etc/init.d/kafka-eagle

#!/bin/bash

#chkconfig:2345 80 20

#description:kafka-eagle

case $1 in

        start) /soft/kafka-eagle-web-1.3.0/bin/ke.sh start ;;

        stop) /soft/kafka-eagle-web-1.3.0/bin/ke.sh stop ;;

        status) /soft/kafka-eagle-web-1.3.0/bin/ke.sh status ;;

        restart) /soft/kafka-eagle-web-1.3.0/bin/ke.sh restart ;;

        *) echo "require start|stop|status|restart" ;;

esac

chmod +x kafka-eagle

chkconfig --add /etc/init.d/kafka-eagle

参考

centos7安装kafka_2.11-1.0.0 新手入门 https://www.cnblogs.com/subendong/p/7786547.html

kafka如何彻底删除topic及数据 https://blog.csdn.net/belalds/article/details/80575751

Kafka Eagle安装及使用简介(详细教程) https://blog.csdn.net/qq_19524879/article/details/82848797

上一篇 下一篇

猜你喜欢

热点阅读