设为首页 加入收藏

TOP

【kafka】Centos7安装kafka
2019-04-20 02:21:42 】 浏览:67
Tags:kafka Centos7 安装
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kisscatforever/article/details/86091136

一、前言

前一段时间在通知系统中,用到了kafka,刚开始的时候是通过本地安装的kafka来运行的,本地安装的kafka。后来在项目中,使用的是阿里的kafka,阿里的也是今年8月开始推出的。这里先记录一下本地安装kafka的过程。

二 、kafka介绍

kafka,先说说小编最初认识是在学习mq的时候,当时知道使用的mq有很多种,rocketmq,rabbitmq等等。后来在项目中选择了rabbitmq,主要是因为选择了spring cloud stream框架,结合rabbitmq做异步消费。当时spring cloud stream支持两种,一个是rabbitmq,一个是kafka。后来换了公司后,公司用的多的就是kafka,所以结合以前的经验,就用了spring cloud stream kafka。

Introduction

在这里插入图片描述
Apache Kafka is a distributed streaming platform. What exactly does that mean
A streaming platform has three key capabilities:

  • Publish and subscribe to streams of records, similar to a message queue or enterprise messaging system.
  • Store streams of records in a fault-tolerant durable way.
  • Process streams of records as they occur.

Kafka is generally used for two broad classes of applications:

  • Building real-time streaming data pipelines that reliably get data between systems or applications
  • Building real-time streaming applications that transform or react to the streams of data
  • To understand how Kafka does these things, let’s dive in and explore Kafka’s capabilities from the bottom up.

First a few concepts:

  • Kafka is run as a cluster on one or more servers that can span multiple datacenters.
  • The Kafka cluster stores streams of records in categories called topics.
  • Each record consists of a key, a value, and a timestamp.

Kafka has four core APIs:

  • The Producer API allows an application to publish a stream of records to one or more Kafka topics.
  • The Consumer API allows an application to subscribe to one or more topics and process the stream of records produced to them.
  • The Streams API allows an application to act as a stream processor, consuming an input stream from one or more topics and producing an output stream to one or more output topics, effectively transforming the input streams to output streams.
  • The Connector API allows building and running reusable producers or consumers that connect Kafka topics to existing applications or data systems. For example, a connector to a relational database might capture every change to a table.

三、Centos 7 安装 Kafka

下面小编先在这篇博客整理一下如何在centos7安装kafka:

通过ftp将kafka安装包kafka_2.11-0.9.0.1.tgz上传到服务器 /home/temp目录下
执行命令tar -xvf kafka_2.11-0.9.0.1.tgz 解压上传的kafka安装包

在这里插入图片描述

执行命令 ll 查看解压的安装包
在这里插入图片描述

执行命令 mv kafka_2.11-0.9.0.1 /home/kafka 将解压后的kafka移动到 /home目录下并重命名为kafka

在这里插入图片描述

执行命令 cd /home/kafka 进入kafka目录
在这里插入图片描述

1 配置并启动zookeeper
执行命令 mkdir zklogs 创建zookeeper日志文件存放路径
在这里插入图片描述
执行命令 vi config/zookeeper.properties 修改zookeeper的配置信息
在这里插入图片描述
按一下键盘上的 i 键进入编辑模式,将光标移动到日志文件存放路径配置信息所在行,并修改dataDir=/tmp/zookeeper 为dataDir=/home/kafka/zklogs
在这里插入图片描述

修改好后按下键盘上的Esc 键后 输入:wq 并按下Enter键保存修改的信息并退出,注意这里的:也是要输入的
在这里插入图片描述
执行nohup ./bin/zookeeper-server-start.sh ./config/zookeeper.properties & 命令后台启动zookeeper
在这里插入图片描述
执行命令ps -ef | grep zookeeper 查看zookeeper是否启动成功,出现类型如下信息表示成功启动
在这里插入图片描述

2 配置并启动kafka
执行命令 vi config/server.properties 修改kafka的配置信息
在这里插入图片描述
按一下键盘上的 i 键进入编辑模式,修改advertised.host.name和advertised.port信息,这里的两个参数在客户端发送和接收消息的时候会使用到,要配置成可访问的ip和端口,修改前如下图
在这里插入图片描述
修改后参考下图
在这里插入图片描述
修改log.dirs=/tmp/kafka-logs为log.dirs=/home/kafka/logs 该参数为kafka日志文件存放路径
在这里插入图片描述
修改每个topic的默认分区参数num.partitions,默认是1,具体合适的取值需要根据服务器配置进程确定
在这里插入图片描述
修改完成后按下键盘上的Esc 键后 输入:wq 并按下Enter键 保存修改的信息并退出,注意这里的:也是要输入的
在这里插入图片描述
执行命令 nohup ./bin/kafka-server-start.sh ./config/server.properties & 后台启动kafka
在这里插入图片描述
执行命令ps -ef | grep kafka查看kafka是否启动成功
在这里插入图片描述
截图的后半部分如下,出现server.properties结尾的进程信息表示kafka启动成功

在这里插入图片描述
到此kafka安装启动成功!

说明:kafka 2.0 发版后,配置文件有所不一样。这个要注意

四、小结

通过这个安装,以及使用发现kafka安装还是很简单的,如果是自己管理kafka的话,需要很好的服务器集群,kafka会从存储一段时间stream,过期后就删除,所以传入的消息很大的话,就要求kafka 的存储很大。另外kafka也有对单次消息大小的限制,这些都在参数配置里面。这个单次消息大小困扰了我很久,修改了很多次都没有成功。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇【Kafka】阿里云消息队列kafka 结.. 下一篇kafka如何获取所有topic   ..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目