01_kafka_环境搭建安装_topic管理

这篇具有很好参考价值的文章主要介绍了01_kafka_环境搭建安装_topic管理。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。


安装jdk

配置主机名

  • hostnamectl set-hostname kafka_1

  • /etc/sysconfig/network

HOSTNAME=kafka_1
  • /etc/hosts
ip  kafka_1
  • ping kafka_1 测试

Zookeeper 下载与安装

  • 由于 集群中的 Leader 的监控 和 Topic 元数据 存储在 Zookeeper 中 ,所以需要安装 zk;
  • https://zookeeper.apache.org/releases.html 中选择需要的版本;
  • conf 目录 复制zoo_sample.cfg 为 zoo.cfg, 修改其中的配置 dataDir 指定自己的目录;
  • 启动zk:使用 zkServer.sh start zoo.cfg
cd /opt/pkg/
wget --no-check-certificate  https://dlcdn.apache.org/zookeeper/zookeeper-3.8.2/apache-zookeeper-3.8.2-bin.tar.gz
tar zxf apache-zookeeper-3.8.2-bin.tar.gz
mv apache-zookeeper-3.8.2-bin ../app/
cd /opt/app/apache-zookeeper-3.8.2-bin/
cp zoo_sample.cfg zoo.cfg
./bin/zkServer.sh start zoo.cfg

---
[root@loaclhost bin]# ./zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/app/apache-zookeeper-3.8.2-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone

Kafka 下载与安装

  • https://kafka.apache.org/downloads
cd /opt/pkg/
wget https://downloads.apache.org/kafka/3.5.1/kafka_2.13-3.5.1.tgz
tar zxf kafka_2.13-3.5.1.tgz
mv kafka_2.13-3.5.1 ../app/
cd /opt/app
cd kafka_2.13-3.5.1/
cd config/
cp server.properties server.properties.bak
vim server.properties
---
listeners=PLAINTEXT://kafka_1:9092
og.dirs=./kafka-logs
zookeeper.connect=kafka_1:2181
---

cd ../
./bin/kafka-server-start.sh -daemon config/server.properties
  • 配置: config/server.properties
broker.id
listeners=PLAINTEXT://主机名:9092
log.dirs= # 日志目录
zookeeper.connect=主机名:2181
  • 启动:./bin/kafka-server-start.sh -daemon config/server.properties
  • 停止:./bin/kafka-server-stop.sh

测试

./bin/kafka-topics.sh --bootstrap-server kafka_1:9092 --create --topic topic_01 --partitions 3 --replication-factor 1 # 单机版副本因子为1 多了没有意义
./bin/kafka-console-consumer.sh --bootstrap-server kafka_1:9092 --topic topic_01 --group g1 # 消费者 查看输出
./bin/kafka-console-producer.sh --broker-list kafka_1:9092  --topic topic_01  # 开始输入

root@loaclhost kafka_2.13-3.5.1]# ./bin/kafka-topics.sh --bootstrap-server kafka_1:9092 --create --topic topic_0
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should c
WARNING: Due to limitations in metric names, topics with a period (‘.’) or underscore ('') could collide. To avo
Created topic topic_01.
[root@loaclhost kafka_2.13-3.5.1]# ./bin/kafka-console-consumer.sh --bootstrap-server kafka_1:9092 --topic topic

OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should c


root@loaclhost kafka_2.13-3.5.1]# ./bin/kafka-console-consumer.sh --bootstrap-server kafka_1:9092 --topic topic_01 --group g1
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N


01_kafka_环境搭建安装_topic管理,kafka,kafka,分布式

集群版安装

  • 使用3台主机进行搭建,三台机器上都需要安装 jdk,Zookeeper,Kafka
  • 其中 /etc/hosts 都需要配置好三台主机的ip 主机名映射;
  • 需要额外注意的是,三台主机需要做一次时间同步
yum -y install ntpdate
timedatectl set-timezone Asia/Shanghai
ntpdate ntp1.aliyun.com # aliyun 有ntp1~7, 或者 cn.pool.ntp.org
  • 复制文件到 另外两台主机
[root@kafka_1 pkg]# pwd
/opt/pkg
scp kafka_2.13-3.5.1.tgz root@kafka_2:/opt/pkg 
scp kafka_2.13-3.5.1.tgz root@kafka_3:/opt/pkg
scp apache-zookeeper-3.8.2-bin.tar.gz root@kafka_3:/opt/pkg
scp apache-zookeeper-3.8.2-bin.tar.gz root@kafka_2:/opt/pkg

  • 配置 zoo.cfg:
# 数据目录 每个机器中,此目录下 需要创建 myid文件内容 和server.id 对应 , 可以指定一个绝对目录
dataDir=/opt/app/cluster/apache-zookeeper-3.8.2/dataDir 

server.1=kafka_1:2888:3888
server.2=kafka_2:2888:3888
server.3=kafka_3:2888:3888
4lw.commands.whitelist=*
  • myid生成: echo 1 > /opt/app/cluster/apache-zookeeper-3.8.2/dataDir/myid # 1,2,3

  • 配置: config/server.properties

broker.id=0 # 需要修改 1,2 
listeners=PLAINTEXT://kafka_1:9092 # 主机名和当前机器对应
log.dirs=/opt/app/cluster/kafka_2.13-3.5.1/log_dirs # 日志目录
zookeeper.connect=kafka_1:2181,kafka_2:2181,kafka_3:2181
  • 启动zk 和 kafka:
cd /opt/app/cluster/apache-zookeeper-3.8.2/
./bin/zkServer.sh start zoo.cfg
cd /opt/app/cluster/kafka_2.13-3.5.1
./bin/kafka-server-start.sh -daemon config/server.properties
  • 报错:

Using config: /opt/app/cluster/apache-zookeeper-3.8.2/bin/…/conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Error contacting service. It is probably not running.文章来源地址https://www.toymoban.com/news/detail-733570.html

  • 原因是防火墙没关:
 systemctl status firewalld
#● firewalld.service - firewalld - dynamic firewall daemon
#   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
#   Active: active (running) since Sun 2023-08-27 19:48:04 CST; 2h 32min ago
#     Docs: man:firewalld(1)
# Main PID: 649 (firewalld)
#   CGroup: /system.slice/firewalld.service
#           └─649 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
#           
systemctl disable firewalld

测试

./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --create --topic topic01 --partitions 3 --replication-factor 3  # 创建 topic
./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --create --topic topic02 --partitions 3 --replication-factor 3  # 创建 topic
./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --list # 查看
./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --describe --topic topic02 # 查看详细描述
./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --alter --topic topic02 --partitions 4   # 修改分区数量,只能增不能减,设置小于3则报错
./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --delete --topic topic02  # 删除topic
	
---
# 消息的生产与消费/订阅
./bin/kafka-console-producer.sh --broker-list kafka_1:9092,kafka_2:9092,kafka_3:9092 --topic topic01 # 生产
./bin/kafka-console-consumer.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --topic topic01 --group g1 --property print.key=true  --property print.value=true  --property key.separator=, # 消费
---
# 查看消费组信息
./bin/kafka-consumer-groups.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --list g1  # 查看
./bin/kafka-consumer-groups.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --describe --group g1  # 查看详情

输出

[root@kafka_1 kafka_2.13-3.5.1]# ./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --create --topic topic01 --partitions 3 --replication-factor 3
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Created topic topic01.
[root@kafka_1 kafka_2.13-3.5.1]# ./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --create --topic topic02 --partitions 3 --replication-factor 3
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Created topic topic02.
[root@kafka_1 kafka_2.13-3.5.1]# ./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --list
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
topic01
topic02

[root@kafka_1 kafka_2.13-3.5.1]# ./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --describe --topic topic02
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Topic: topic02  TopicId: _s44mBQqTLaSmVWcZA2GTw PartitionCount: 3       ReplicationFactor: 3    Configs:
        Topic: topic02  Partition: 0    Leader: 2       Replicas: 2,0,1 Isr: 2,1
        Topic: topic02  Partition: 1    Leader: 1       Replicas: 1,2,0 Isr: 1,2
        Topic: topic02  Partition: 2    Leader: 0       Replicas: 0,1,2 Isr: 0,1,2

[root@kafka_1 kafka_2.13-3.5.1]# ./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --alter --topic topic02 --partitions 4

[root@kafka_1 kafka_2.13-3.5.1]# ./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --describe --topic topic02
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Topic: topic02  TopicId: _s44mBQqTLaSmVWcZA2GTw PartitionCount: 4       ReplicationFactor: 3    Configs:
        Topic: topic02  Partition: 0    Leader: 2       Replicas: 2,0,1 Isr: 2,1
        Topic: topic02  Partition: 1    Leader: 1       Replicas: 1,2,0 Isr: 1,2
        Topic: topic02  Partition: 2    Leader: 0       Replicas: 0,1,2 Isr: 0,1,2
        Topic: topic02  Partition: 3    Leader: 2       Replicas: 2,1,0 Isr: 2,1

[root@kafka_1 kafka_2.13-3.5.1]# ./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --list
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
topic01
topic02
[root@kafka_1 kafka_2.13-3.5.1]# ./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --delete --topic topic02
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
[root@kafka_1 kafka_2.13-3.5.1]# ./bin/kafka-topics.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --list
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
topic01

---
# 生产者
[root@kafka_1 kafka_2.13-3.5.1]# ./bin/kafka-console-producer.sh --broker-list kafka_1:9092,kafka_2:9092,kafka_3:9092 --topic topic01
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
>123
>123
>key=123
>


# 消费者
[root@kafka_1 kafka_2.13-3.5.1]# ./bin/kafka-console-consumer.sh --bootstrap-server kafka_1:9092,kafka_2:9092,kafka_3:9092 --topic topic01 --group g1 --property print.key=true  --property print.value=true  --property key.separator=,
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N



null,123
null,123
null,key=123

到了这里,关于01_kafka_环境搭建安装_topic管理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 头歌Hadoop 开发环境搭建及HDFS初体验(第2关:配置开发环境 - Hadoop安装与伪分布式集群搭建)

    注: 1 头歌《Hadoop 开发环境搭建及HDFS初体验》三关在一个实验环境下,需要三关从前往后按顺序评测,跳关或者实验环境结束后重新打开 不能单独评测通过 2 复制粘贴请用右键粘贴,CTRL+C/V不管用哦~ 第1关:配置开发环境 - JavaJDK的配置: 解压: 配置环境变量: 细节: vi

    2024年02月08日
    浏览(118)
  • hadoop01_完全分布式搭建

    Hadoop运行模式包括: 本地模式 (计算的数据存在Linux本地,在一台服务器上 自己测试)、 伪分布式模式 (和集群接轨 HDFS yarn,在一台服务器上执行)、 完全分布式模式 。 本地模式 :(hadoop默认安装后启动就是本地模式,就是将来的数据存在Linux本地,并且运行MR程序的时

    2024年02月04日
    浏览(31)
  • 【分布式应用】kafka集群、Filebeat+Kafka+ELK搭建

    主要原因是由于在高并发环境下,同步请求来不及处理,请求往往会发生阻塞。比如大量的请求并发访问数据库,导致行锁表锁,最后请求线程会堆积过多,从而触发 too many connection 错误,引发雪崩效应。 我们使用消息队列,通过异步处理请求,从而缓解系统的压力。消息队

    2024年02月16日
    浏览(28)
  • ZooKeeper之分布式环境搭建--仲裁模式与伪分布式环境搭建

    相关知识 为了完成本关任务,你需要掌握:1.ZooKeeper单节点安装方法,2.命令行基本操作。 ZooKeeper之仲裁模式 standlone 模式运行ZooKeeper,便于评估,开发,测试和学习。但是在实际生产中,使用ZooKeeper均以仲裁模式( quorum mode )运行, quorum mode 具有一组ZooKeeper服务器,这一组

    2024年02月05日
    浏览(38)
  • Spark单机伪分布式环境搭建、完全分布式环境搭建、Spark-on-yarn模式搭建

    搭建Spark需要先配置好scala环境。三种Spark环境搭建互不关联,都是从零开始搭建。 如果将文章中的配置文件修改内容复制粘贴的话,所有配置文件添加的内容后面的注释记得删除,可能会报错。保险一点删除最好。 上传安装包解压并重命名 rz上传 如果没有安装rz可以使用命

    2024年02月06日
    浏览(58)
  • 【大数据工具】Kafka伪分布式、分布式安装和Kafka-manager工具安装与使用

    Kafka 安装包下载地址:https://archive.apache.org/dist/kafka/ 1. Kafka 伪分布式安装 1. 上传并解压 Kafka 安装包 使用 FileZilla 或其他文件传输工具上传 Kafka 安装包: kafka_2.11-0.10.0.0.tgz 解压安装包 2. 编辑配置文件 3. 拷贝并修改配置文件 分别修改 server2.properties、server3.properties 4. 创建日志

    2024年02月14日
    浏览(34)
  • docker搭建Elk+Kafka+Filebeat分布式日志收集系统

    目录 一、介绍 二、集群环境 三、ES集群 四、Kibana  五、Logstash 六、Zookeeper 七、Kafka 八、Filebeat 八、Nginx (一)架构图  (二)组件介绍 1.Elasticsearch 是一个基于Lucene的搜索服务器。提供搜集、分析、存储数据三大功能。它提供了一个分布式多用户能力的全文搜索引擎,基于

    2024年02月04日
    浏览(40)
  • Kafka/Spark-01消费topic到写出到topic

    消费者代码 注意点 consumerConfigs是定义的可变的map的类型的,具体如下 consumerConfigs.put(ConsumerConfig.GROUP_ID_CONFIG , groupId)是为了不限制groupId特意写的传参 是使用自带的kafka工具类createDirectStream方法去消费kafak 的数据,详细参数解释如下 Subscribe传参需要指定泛型,这边指定string,

    2024年02月09日
    浏览(26)
  • 【Kafka专栏】windows搭建Kafka环境 & 详细教程(01)

    官网:https://kafka.apache.org/quickstart 中文官网:https://kafka.apachecn.org/1/#apache-kafka Apache Kafka 是一个开源分布式事件流平台,已被数千家公司用于高性能数据管道、流分析、数据集成和关键任务应用程序 Kafka和Zookeeper之间的关系可以概括为紧密的合作关系。Kafka是一个高性能、可

    2024年04月25日
    浏览(26)
  • HBase 伪分布式环境搭建 - 头歌

    mkdir /app cd /opt tar -zxvf hbase-2.1.1-bin.tar.gz -C /app cd /app cd hbase-2.1.1 cd conf echo $JAVA_HOME /usr/lib/jvm/jdk1.8.0_111 vim hbase-env.sh 进入文件,找到下图中红色框框内的路径,将#去掉,把=号后面的路径改成/usr/lib/jvm/jdk1.8.0_111。注意:记得先按A,才能改。 按esc键,输入  :wq  ,回车。 vim hb

    2024年04月28日
    浏览(27)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包