kafka搭建

举报
菜鸟级攻城狮 发表于 2021/02/28 08:08:42 2021/02/28
【摘要】 注意:前期步骤,最小化安装,配置yum,安装bash-completion,安装vim,安装net-tools,关闭防火墙,关闭SELINUX,hosts表,免密登录。1、上传并解压kafka[root@win1 soft]# tar -zxvf kafka_2.11-2.1.0.tgz2、创建logfile文件夹[root@win1 kafka_2.11-2.1.0]# mkdir -p ...

注意:前期步骤,最小化安装,配置yum,安装bash-completion,安装vim,安装net-tools,关闭防火墙,关闭SELINUXhosts表,免密登录。

1、上传并解压kafka

[root@win1 soft]# tar -zxvf kafka_2.11-2.1.0.tgz

2、创建logfile文件夹

[root@win1 kafka_2.11-2.1.0]# mkdir -p /hadoop/soft/kafka_2.11-2.1.0/logfile

3、编辑config中的properties配置文件(主要修改4个参数broker.idlistenerslog.dirszookeeper.connect)

[root@win1 config]# vi server.properties

# Licensed to the Apache Software Foundation (ASF) under one or more

# The ASF licenses this file to You under the Apache License, Version 2.0

# (the "License"); you may not use this file except in compliance with

# the License.  You may obtain a copy of the License at

#

#    http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.

 

# see kafka.server.KafkaConfig for additional details and defaults

 

############################# Server Basics #############################

 

# The id of the broker. This must be set to a unique integer for each broker.

broker.id=0   #每节点填写不一致,节点10,节点21,节点3,填写2

 

############################# 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://win1:9092   #每个节点填写自己的IP地址或主机名,端口号保持一致。

 

# 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

#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

 

num.network.threads=3

 

# The number of threads that the server uses for processing requests, which may include disk I/O

 

# 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 separated list of directories under which to store log files

log.dirs=/hadoop/soft/kafka_2.11-2.1.0/logfile   #每节点一致

 

# 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

 

############################# Internal Topic Settings  #############################

# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"

offsets.topic.replication.factor=1

transaction.state.log.replication.factor=1

transaction.state.log.min.isr=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.

# 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.

# 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

############################# Log Retention Policy #############################

 

# 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 unless the remaining

# segments 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=win1:2181,win2:2181,win3:2181   #可写主机名或IP地址

 

# Timeout in ms for connecting to zookeeper

zookeeper.connection.timeout.ms=6000

 

4 拷贝kafka文件夹到所有节点。

[root@win1 kafka_2.11-2.1.0]# scp -pr /hadoop/soft/kafka_2.11-2.1.0 win2:/hadoop/soft

[root@win1 kafka_2.11-2.1.0]# scp -pr /hadoop/soft/kafka_2.11-2.1.0 win3:/hadoop/soft

拷贝后记得修改23broker.idlisteners

5 3个节点修改环境变量。

[root@win1 ~]# vi /root/.bashrc

JAVA_HOME=/hadoop/soft/jdk1.8.0_161

ZK_HOME=/hadoop/soft/zookeeper-3.4.12

KAFKA_HOME=/hadoop/soft/kafka_2.11-2.1.0

 

PATH=$JAVA_HOME/bin:$PATH:$ZK_HOME/bin:$KAFKA_HOME/bin

 

CLASS_PATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar

6加载环境变量

[root@win1 ~]# source /root/.bashrc

73个节点后台启动kafka

#kafka-server-start.sh /hadoop/soft/kafka_2.11-2.1.0/config/server.properties 1>/dev/null 2>&1 &

8、查看kafka进程

[root@win1 ~]# jps

12563 Kafka

10535 QuorumPeerMain

16971 Jps

 

[root@win1 ~]# ps -ef |grep kafka

root      12563  11747  0 08:43 pts/1    00:00:40 java -Xmx1G -Xms1G -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -Djava.awt.headless=true -Xloggc:/hadoop/soft/kafk_2.11-2.1.0/bin/../logs/kafkaServer-gc.log后略

9、创建topic

[root@win1 ~]# kafka-topics.sh --create --zookeeper 125.221.44.11:2181 --replication-factor 3 --partitions 1 --topic testA

10、查看topic列表

[root@win1 ~]# kafka-topics.sh --list --zookeeper 125.221.44.11:2181

11查看testA

[root@win1 ~]# kafka-topics.sh --describe --zookeeper 125.221.44.11:2181 --topic testA

12测试数据收发(在发消息前先执行下一步骤的命令)

[root@win1 ~]# kafka-console-producer.sh --broker-list 125.221.44.11:9092 --topic testA

>yutian

>great

13、在另一台测试接收(前一步骤发送的消息的同时,回在另一节点同时接收)

[root@win2 ~]# kafka-console-consumer.sh --bootstrap-server 125.221.44.11:9092 --from-beginning --topic testA

yutian

great

 

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。