云服务器搭建kafka伪分布式环境

本文详细介绍如何在云服务器上搭建Kafka伪分布式集群,并配置Zookeeper进行节点管理。包括安装步骤、配置详解及测试命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景

最近在学习kafka,准备在自己租的云服务器上搭建kafka伪分布式集群,做一些笔记,记录一些踩到的坑。。。

准备

1、jdk1.8
2、zookeeper-3.4.5.tar.gz
3、kafka_2.11-0.11.0.3.tgz
说明:
jdk没什么好说的,使用zookeeper是因为我们搭建的kafka集群会有很多个结点(broker),我们将这些broker托管給zookeeper,用于管理、协调代理;每个Kafka代理通过Zookeeper协调其他Kafka代理。

安装zookeeper

jdk的安装我们这直接过掉…
首先下载安装包,安装包可以自行去官网下载http://zookeeper.apache.org/
上传到:
/usr/local 目录下
解压:

	tar -zxvf zookeeper-3.4.5.tar.gz

移动个位置:

	mv  zookeeper-3.4.5 /usr/zookeeper

进入zookeeper-3.4.5/conf

	cp zoo_sample.cfg  zoo.cfg

修改配置:

	vim 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=/usr/zookeeper/data
# the port at which the clients will connect
clientPort=2181
server.1=hwyuntrx:2888:3888
#hwyuntrx   是主机名  
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

创建/usr/zookeeper/data 并在里面创建myid文件,就是这个名儿,不要改别的,
然后在里面填一个数字,这个数字跟配置文件里面的对应:
在这里插入图片描述

我这里填 1

这样就配置成功了

启动它:

	bin/zookeeper-server-start.sh config/zookeeper.properties

在这里插入图片描述
说明成功!!!

安装kafka

同样拷贝,加压,然后找个位置放好,我这直接来配置了:

进入 config

	vim server.properties

修改几个地方:
1、delete.topic.enable=true前面的注释打开,表示允许删除topic
2、log.dirs=/usr/kafka/logs 说明:/usr/kafka/logs是新建的文件夹 用来存放数据的

这就OK了,一个伪分布式的kafka集群搭建完毕,这个时候还不能进行远程连接,这需要改一下配置才行。
我会在下一篇博客记录。

测试命令:

启动zookeeper

bin/zookeeper-server-start.sh config/zookeeper.properties &

启动kafka:
bin/kafka-server-start.sh config/server.properties

创建topic:
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test1

展示topic
bin/kafka-topics.sh --list --zookeeper localhost:2181

描述topic
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test1

生产者:
bin/kafka-console-producer.sh --broker-list hwyuntrx:9092 --topic test1

消费者:
bin/kafka-console-consumer.sh --zookeeper hwyuntrx:2181 --topic test1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值