在GCP 上安装kafka

本文档详细介绍了如何在Google Cloud Platform (GCP)上安装和配置Kafka。首先,你需要在GCP上创建一个运行CentOS 7的虚拟机实例。接着,将进行Zookeeper和Kafka的安装,包括修改zookeeper.properties和server.properties配置文件。安装完成后,启动Zookeeper和Kafka。最后,通过验证步骤,包括在两个独立的终端上创建topic、producer和consumer,确保Kafka运行正常。

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

安装kafka

准备

  • 在GCP上创建Centos 7 的VM实例
    安装步骤
# Installing dependencies
sudo su
yum install -y wget nano java

# Automatically creating the Zookeeper myid file
mkdir /tmp/zookeeper
touch /tmp/zookeeper/myid
echo "ZOOKEEPER-ID" > tmp/zookeeper/myid

# Downloading and extracting Kafka
wget http://mirror.ox.ac.uk/sites/rsync.apache.org/kafka/0.10.2.1/kafka_2.12-0.10.2.1.tgz
tar -xvzf kafka_2.12-0.10.2.1.tgz
cd kafka_2.12-0.10.2.1

修改zookeeper.properties

nano config/zookeeper.properties

# In milliseconds
tickTime=2000

# In ticks
initLimit=10
syncLimit=5
maxClientCnxns=30

# All Zookeeper servers need to be aware of other Zookeepers part of the cluster
server.1=localhost:2888:3888

修改server.properties配置

nano config/server.properties
# Broker id needs to be unique for each Kafka server
broker.id=0

# This will be the Zookeeper servers created before
zookeeper.connect=localhost:2181

# Examples of hostnames - kafka-1, kafka-2, kafka-3
host.name=localhost

启动zookeeper和kafka

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

验证
开启俩个终端,在终端1上创建topic 和producer


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

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

在终端2 上创建consumer

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

这里写图片描述
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值