centos7下kafka集群搭建

centos7下kafka集群搭建概述集群安装或者单机安装都可以,这里介绍集群安装。Kafka本身安装包也自带了zookeeper,也可以使用其自带的zookeeper。建议试用自己安装的zookeeper,本教程试用单独安装的zookeeper。安装环境3台centos7虚拟机:10.15.21.6210.10.182.16810.10.182.169kafka_2.10-0.10.2.0zookeeper-3.4.9

大家好,又见面了,我是你们的朋友全栈君。

概述

集群安装或者单机安装都可以,这里介绍集群安装。Kafka本身安装包也自带了zookeeper,也可以使用其自带的zookeeper。建议试用自己安装的zookeeper,本教程试用单独安装的zookeeper。

安装环境

3台centos7虚拟机:10.15.21.62 10.10.182.168 10.10.182.169
kafka_2.10-0.10.2.0
zookeeper-3.4.9
jdk-1.8.0(安装不做赘述)

环境初始化

定义目录结构。

mkdir /opt/zookeeper
mkdir /opt/zkdata
mkdir /opt/zkdatalog
mkdir /opt/kafka

下载软件

cd /opt/zookeeper
wget https://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
cd /opt/kafka/
wget http://mirror.bit.edu.cn/apache/kafka/0.10.2.0/kafka_2.10-0.10.2.0.tgz

Zookeeper集群搭建

  1. 修改配置文件
    cd /opt/zookeeper/
    tar –xvf  zookeeper-3.4.9.tar.gz
    cd zookeeper-3.4.9/conf
    cp zoo_sample.cfg zoo.cfg
    vi zoo.cfg
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/opt/zookeeper/zkdata
dataLogDir=/opt/zookeeper/zkdatalog
# the port at which the clients will connect
clientPort=2181
server.1=zk1:2888:3888
server.2=zk2:2888:3888
server.3=zk3:2888:3888
# the maximum number of client connections.
# increase this if you need to handle more clients

server.1 这个1是服务器的标识也可以是其他的数字, 表示这个是第几号服务器,用来标识服务器,这个标识后续会用到。
第一个端口是master和slave之间的通信端口,默认是2888,第二个端口是leader选举的端口。默认3888。
修改完成后,保存即可。
server1:

    echo "1" > /opt/zookeeper/zkdata/myid

server2:

    echo "2" > /opt/zookeeper/zkdata/myid

server3:

    echo "3" > /opt/zookeeper/zkdata/myid

3.启动服务并查看
依次启动服务然后再查看服务状态

cd /opt/zookeeper/zookeeper-3.4.9/bin
    ./zkServer.sh start
    ./zkServer.sh status

Kafka集群搭建

  1. 修改配置文件
cd /opt/kafka/kafka_2.10-0.10.2.0/config/
vi server.config
# The id of the broker. This must be set to a unique integer for each broker. broker.id=1 #当前机器在集群中的唯一标识 # Switch to enable topic deletion or not, default value is false delete.topic.enable=true ############################# Socket Server Settings ############################# # The address the socket server listens on. It will get the value returned from # java.net.InetAddress.getCanonicalHostName() if not configured. # FORMAT: # listeners = listener_name://host_name:port # EXAMPLE: # listeners = PLAINTEXT://your.host.name:9092 listeners=PLAINTEXT://10.15.21.62:9092 #监听端口 # Hostname and port the broker will advertise to producers and consumers. If not set, # it uses the value for "listeners" if configured. Otherwise, it will use the value # returned from java.net.InetAddress.getCanonicalHostName(). advertised.listeners=PLAINTEXT://10.15.21.62:9092 #提供给生产者,消费者的端口号。可以不设置则使用listeners的值 # Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details #listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL # The number of threads handling network requests num.network.threads=4 # The number of threads doing disk I/O num.io.threads=30 # The send buffer (SO_SNDBUF) used by the socket server socket.send.buffer.bytes=102400 # The receive buffer (SO_RCVBUF) used by the socket server socket.receive.buffer.bytes=102400 # The maximum size of a request that the socket server will accept (protection against OOM) socket.request.max.bytes=104857600 ############################# Log Basics ############################# # A comma seperated list of directories under which to store log files log.dirs=/tmp/kafka-logs # The default number of log partitions per topic. More partitions allow greater # parallelism for consumption, but this will also result in more files across # the brokers. num.partitions=1#默认的分区数 # The number of threads per data directory to be used for log recovery at startup and flushing at shutdown. # This value is recommended to be increased for installations with data dirs located in RAID array. 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. # 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. # The number of messages to accept before forcing a flush of data to disk #log.flush.interval.messages=10000 # The maximum amount of time a message can sit in a log before we force a flush #log.flush.interval.ms=1000 ############################# Log Retention Policy ############################# # The following configurations control the disposal of log segments. The policy can # be set to delete segments after a period of time, or after a given size has accumulated. # A segment will be deleted whenever *either* of these criteria are met. Deletion always happens # from the end of the log. # The minimum age of a log file to be eligible for deletion due to age log.retention.hours=168 # A size-based retention policy for logs. Segments are pruned from the log as long as the remaining # segments don't drop below log.retention.bytes. Functions independently of log.retention.hours. #log.retention.bytes=1073741824 # The maximum size of a log segment file. When this size is reached a new log segment will be created. log.segment.bytes=1073741824 # The interval at which log segments are checked to see if they can be deleted according # to the retention policies log.retention.check.interval.ms=300000 ############################# Zookeeper ############################# # Zookeeper connection string (see zookeeper docs for details). # This is a comma separated host:port pairs, each corresponding to a zk # server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002". # You can also append an optional chroot string to the urls to specify the # root directory for all kafka znodes. zookeeper.connect= zk1:2181,zk2:2181,zk3:2181 #zookeeper连接地址 # Timeout in ms for connecting to zookeeper zookeeper.connection.timeout.ms=6000 
  1. 启动kafka集群并测试
    在集群每个主机内执行:
cd /opt/kafka/kafka_2.10-0.10.2.0/bin/
./kafka-server-start.sh -daemon ../config/server.properties
  1. 验证是否安装成功
    任意一台主机创建一个topic
./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

在一台主机上启动消费者消费消息

./kafka-console-consumer.sh --zookeeper zk1:2181,zk2:2181,zk3:2181 --topic test

在另一一台主机上发布消息

./kafka-console-producer.sh --broker-list 10.15.21.62:9092,10.10.182.168:9092,10.10.182.169:9092 --topic test

输入要发布的信息,并按回车。
将会看到消费者消费了消息。说明安装成功。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/135289.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 深入浅出讲解Optional包装类

    深入浅出讲解Optional包装类Optional是JDK8的新特性,首先这个类是被final修饰的,并且这个类只有一个Object的超类,下面是这个类的结构。我们可以看到一共也没多少方法,所以我觉得就从这个类开始,养成阅读源码的习惯,再合适不过了。Optional的作用在写这篇博客之前,看过好多相关的资料,大体上来说这个类就是用来解决万恶的空指针异常,用来避免繁琐的!=null代码而存在的。那你也太…

    2022年9月21日
    1
  • 三万字详解SpringClould高可用流量防护组件Sentinel哨兵(含源码例子)[通俗易懂]

    三万字详解SpringClould高可用流量防护组件Sentinel哨兵(含源码例子)[通俗易懂]文章目录一、断路器1.1.为什么使用断路器?1.2.断路器两大常用组件Sentinel和Hystrix对比二、sentinel主要特性三、sentinel两个部分、三步骤3.1.两部分3.2.三步骤四、使用核心库(如果已经引入了springcloudalibabajar不需要单独选择版本,只需直接引用)一、断路器1.1.为什么使用断路器?在微服务架构中,我们将系统拆分成了很多服务单元,各单元的应用间通过服务注册与订阅的方式互相依赖。由于每个单元都在不同的进程中运行,依赖通过远程

    2022年6月2日
    34
  • 小草客户端android2.2.4 g,小草客户端android2.2.5-小草app安卓版客户端android2.2.5预约 v2.2.5-优盘手机站…[通俗易懂]

    小草客户端android2.2.4 g,小草客户端android2.2.5-小草app安卓版客户端android2.2.5预约 v2.2.5-优盘手机站…[通俗易懂]小草客户端android2.2.5是一款很真实的线上社交互动平台,超多年轻人选择在这里,和大家展开精彩的互动玩法,有什么想法都可以大胆的表达出来,在这里认识自己喜欢的人,让你从此以后不会再觉得孤单了,这些精彩的玩法,给你带来了不少的乐趣体验。小草客户端android2.2.5特色:1、打造最真实的交友互动软件,简洁的界面设计吸引了很多人来体验。2、在这里能够轻松结交到全国各地的单身朋友,参与到热门…

    2022年6月15日
    55
  • 用KCPTun进行加速

    用KCPTun进行加速来源:https://blog.csdn.net/Crapefruit/article/details/86669794VPS端在命令行键入:mkdirkcptuncdkcptunwget

    2022年8月4日
    53
  • pandas小记:pandas索引和选择

    pandas小记:pandas索引和选择http://blog.csdn.net/pipisorry/article/details/18012125检索/选择索引选择时建议全部使用loc(尤其是修改df原本数据时),原因是最下面说的视图和显示拷贝。dataframe列选择和Series一样,在DataFrame中的一列可以通过字典记法或属性来检索,返回Series:frame2[0]#选择第0列,最新版的好像…

    2022年7月22日
    8
  • bool型函数「建议收藏」

    bool型函数「建议收藏」bool介绍C++中bool函数如果值非零就为True,为零就是False。比如写数据结构的时候,有时候需要判断一下链表是不是为空,这时候需要用到bool函数,再者,你看到bool就知道这个函数返回值只是用于判断真假。bool函数返回的只有true和false。而int会返回各种数字,但是你关心的不是数字的多少,而是这个数字为不为0.所以这种情况用bool会更加简洁,规范,你看到bo…

    2022年6月5日
    31

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号