首页 > 系统相关 >ubuntu下安装zookeeper和kafka伪集群

ubuntu下安装zookeeper和kafka伪集群

时间:2023-01-26 19:31:40浏览次数:65  
标签:bin zookeeper 192.168 kafka ubuntu 2.2 2.12


1.创建目录
mkdir -p /zookeeper/zkp-1 /zookeeper/zkp-2 /zookeeper/zkp-3
2.下载zookeeper
链接地址:​​​http://mirror.bit.edu.cn/apache/zookeeper/​​​ 命令下载:
cd /zookeeper/zkp-1
wget ​​http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.5.5/apache-zookeeper-3.5.5-bin.tar.gz​​ 3.解压
tar -zxvf apache-zookeeper-3.5.5-bin.tar.gz
复制到zkp-2和zkp-3
cp -R /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin /zookeeper/zkp-2
cp -R /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin /zookeeper/zkp-3
4.修改配置文件
cd /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin/conf
vim zoo.cfg

tickTime=2000
dataDir= /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin/data
clientPort=2181
initLimit=5
syncLimit=2
server.1=192.168.0.79:2888:3888
server.2=192.168.0.79:4888:5888
server.3=192.168.0.79:6888:7888

cd /zookeeper/zkp-2/apache-zookeeper-3.5.5-bin/conf
vim zoo.cfg

tickTime=2000
dataDir=/zookeeper/zkp-2/apache-zookeeper-3.5.5-bin/data
clientPort=2182
initLimit=5
syncLimit=2
server.1=192.168.0.79:2888:3888
server.2=192.168.0.79:4888:5888
server.3=192.168.0.79:6888:7888

cd /zookeeper/zkp-3/apache-zookeeper-3.5.5-bin/conf
vim zoo.cfg

tickTime=2000
dataDir=/zookeeper/zkp-3/apache-zookeeper-3.5.5-bin/data
clientPort=2183
initLimit=5
syncLimit=2
server.1=192.168.0.79:2888:3888
server.2=192.168.0.79:4888:5888
server.3=192.168.0.79:6888:7888

5.创建数据目录
mkdir -p /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin/data
mkdir -p /zookeeper/zkp-2/apache-zookeeper-3.5.5-bin/data
mkdir -p /zookeeper/zkp-3/apache-zookeeper-3.5.5-bin/data
6.写入myid文件
cd /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin/data
echo ‘1’ > myid
cd /zookeeper/zkp-2/apache-zookeeper-3.5.5-bin/data
echo ‘2’ > myid
cd /zookeeper/zkp-3/apache-zookeeper-3.5.5-bin/data
echo ‘3’ > myid
7.启动,三个都执行
cd /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin/bin
./zkServer.sh start
cd /zookeeper/zkp-2/apache-zookeeper-3.5.5-bin/bin
./zkServer.sh start
cd /zookeeper/zkp-3/apache-zookeeper-3.5.5-bin/bin
./zkServer.sh start

打印日志启动:./zkServer.sh start-foreground
8.查看jps结果
jps
8099 Jps
6808 QuorumPeerMain
6746 QuorumPeerMain
8014 QuorumPeerMain

kafka伪集群安装

1.创建目录
mkdir -p /kafka/kafka-1 /kafka/kafka-2 /kafka/kafka-3
2.下载kafka
链接:​​​http://kafka.apache.org/downloads​​​ cd /kafka/kafka-1
wget ​​http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.2.1/kafka_2.12-2.2.1.tgz​​ 3.解压
tar -zxvf kafka_2.12-2.2.1.tgz
复制到kafka-2和kafka-3
cp -R /kafka/kafka-1/kafka_2.12-2.2.1 /kafka/kafka-2/kafka_2.12-2.2.1
cp -R /kafka/kafka-1/kafka_2.12-2.2.1 /kafka/kafka-3/kafka_2.12-2.2.1
4.修改配置文件
cd /kafka/kafka-1/kafka_2.12-2.2.1/config
vim server.properties
(listeners=PLAINTEXT://wzj-ThinkPad-Edge-E440:9092//这个参数非常重要,想要外网访问docker内的集群,只能配置主机名,不能配置IP地址,命令hostname, ​​配置文件时注意参数broker.id​​,log.dirs,zookeeper.connect)

broker.id=1
listeners=PLAINTEXT://192.168.0.79:9092
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/kafka/kafka-1/kafka_2.12-2.2.1/logs
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=192.168.0.79:2181,192.168.0.79:2182,192.168.0.79:2183
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0
# 可删除topic
delete.topic.enable=true
# 每间隔1秒钟时间,刷数据到磁盘
log.flush.interval.ms=1000
# 保留三天,也可以更短
log.retention.hours=72

cd /kafka/kafka-2/kafka_2.12-2.2.1/config
vim server.properties

broker.id=2
listeners=PLAINTEXT://192.168.0.79:9093
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/kafka/kafka-2/kafka_2.12-2.2.1/logs
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=192.168.0.79:2181,192.168.0.79:2182,192.168.0.79:2183
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0
# 可删除topic
delete.topic.enable=true
# 每间隔1秒钟时间,刷数据到磁盘
log.flush.interval.ms=1000
# 保留三天,也可以更短
log.retention.hours=72

cd /kafka/kafka-3/kafka_2.12-2.2.1/config
vim server.properties

broker.id=3
listeners=PLAINTEXT://192.168.0.79:9094
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/kafka/kafka-3/kafka_2.12-2.2.1/logs
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=192.168.0.79:2181,192.168.0.79:2182,192.168.0.79:2183
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0
# 可删除topic
delete.topic.enable=true
# 每间隔1秒钟时间,刷数据到磁盘
log.flush.interval.ms=1000
# 保留三天,也可以更短
log.retention.hours=72

4.启动,三个都执行
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-server-start.sh /kafka/kafka-1/kafka_2.12-2.2.1/config/server.properties &

cd /kafka/kafka-2/kafka_2.12-2.2.1
bin/kafka-server-start.sh /kafka/kafka-2/kafka_2.12-2.2.1/config/server.properties &

cd /kafka/kafka-3/kafka_2.12-2.2.1
bin/kafka-server-start.sh /kafka/kafka-3/kafka_2.12-2.2.1/config/server.properties &

后台启动方式:
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-server-start.sh -daemon /kafka/kafka-1/kafka_2.12-2.2.1/config/server.properties

cd /kafka/kafka-2/kafka_2.12-2.2.1
bin/kafka-server-start.sh -daemon /kafka/kafka-2/kafka_2.12-2.2.1/config/server.properties

cd /kafka/kafka-3/kafka_2.12-2.2.1
bin/kafka-server-start.sh -daemon /kafka/kafka-3/kafka_2.12-2.2.1/config/server.properties

netstat lntp|grep 9092
5.测试kafka集群
#创建topic
cd /kafka/kafka-1/kafka_2.12-2.2.1

bin/kafka-topics.sh --create --zookeeper 192.168.0.79:2181,192.168.0.79:3181,192.168.0.79:4181 --replication-factor 3 --partitions 3 --topic test
#显示topic信息
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-topics.sh --describe --zookeeper 192.168.0.79:2181,192.168.0.79:3181,192.168.0.79:4181 --topic test
#列出topic
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-topics.sh --list --zookeeper 192.168.0.79:2181,192.168.0.79:3181,192.168.0.79:4181
#创建 producer
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-console-producer.sh --broker-list master:9092 -topic test
#创建 consumer
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-console-consumer.sh --zookeeper 192.168.0.79:2181,192.168.0.79:3181,192.168.0.79:4181 -topic test --from-beginning
#删除topic
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-topics.sh --delete --zookeeper 192.168.0.79:2181,192.168.0.79:3181,192.168.0.79:4181 --topic test
#查询topic内容
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicName --from-beginning
6.关闭kafka
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-server-stop.sh /kafka/kafka-1/kafka_2.12-2.2.1/config/server.properties

cd /kafka/kafka-2/kafka_2.12-2.2.1
bin/kafka-server-stop.sh /kafka/kafka-2/kafka_2.12-2.2.1/config/server.properties

cd /kafka/kafka-3/kafka_2.12-2.2.1
bin/kafka-server-stop.sh /kafka/kafka-3/kafka_2.12-2.2.1/config/server.properties
7.关闭zookeeper
cd /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin
bin/zkServer.sh stop conf/zoo.cfg

cd /zookeeper/zkp-2/apache-zookeeper-3.5.5-bin
bin/zkServer.sh stop conf/zoo.cfg

cd /zookeeper/zkp-3/apache-zookeeper-3.5.5-bin
bin/zkServer.sh stop conf/zoo.cfg


标签:bin,zookeeper,192.168,kafka,ubuntu,2.2,2.12
From: https://blog.51cto.com/u_15943246/6023686

相关文章

  • Install Go 1.19 in windows 11 & Ubuntu 20.04
    TheGoProgrammingLanguagehttps://go.dev/DownloadandinstallGo1.19withwingethttps://winget.run/pkg/GoLang/Go.1.19注意:需要使用VPN代理,从google下载。ht......
  • [Debian/Ubuntu]apt 和 apt-get 之间有什么区别?
    [Linux]apt和apt-get之间有什么区别?-知乎https://zhuanlan.zhihu.com/p/350690109最后结大家提供两点使用上的建议:apt可以看作apt-get和apt-cache命令的子集,......
  • ubuntu 18.04 安装 opencv3.4.1 以及 opencv_contrib 3.4.1] 亲测可用
    1、首先下载opencv和opencv_contrib的库contrib库:​​https://github.com/opencv/opencv_contrib/releases​​​opencv版本:​​https://opencv.org/releases.html​​2、......
  • Ubuntu下安装RabbitMQ
    设置Erlang仓库curl-1sLf\'https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/setup.deb.sh'\|sudo-Ebash设置rabbitmq仓库curl-1sLf\'h......
  • Ubuntu虚拟机不显示ipv4地址 (虚拟机无法连接网络)
    相信很多朋友都遇到过虚拟机连接不上网络或者说使用ifconfig不显示ipv4网络地址的情况,就想下图一样:  网上请教很多大神都说更改“网络连接”为“NAT模式”,但是试了无......
  • 【Linux】Ubuntu镜像索引
    ✨Ubuntu镜像索引Ubuntu官方网站似乎UbuntuARM镜像并不容易寻找可以点击如下链接前往Ubuntu镜像索引选择需要版本http://cdimage.ubuntu.com/可以非常方便地下载到Des......
  • 如何在 Ubuntu 中卸载 deb 包 | Linux 中国
    如何在Ubuntu中卸载deb包|Linux中国原创 邀你一起加入 Linux中国 2022-08-0120:08 发表于海南收录于合集#译者:geekpi364个 导读:删除.deb文件的最简单和......
  • Ubuntu安装到一半时U盘被拔,无法重新安装,如何解决?
    提问: (有另一台运行Windows11的笔记本)在实体机上安装Ubuntu,硬盘已被格式化、正在安装系统文件时,U盘松动了一下,导致安装被中断。重新插入U盘进入BIOS,发现找不到U盘和Window......
  • 【ubuntu基础】linux常用命令总结
    前言 常用命令查看cpu内存使用情况tophtop 解压文件至某个目录tar-zxvfaaa.tar.gz-C/path/to/untar/​​ 删除size为0的文件​​find.-name"*"-typef-size0c......
  • 在虚拟机中安装 Ubuntu 步骤
    在虚拟机中安装Ubuntu步骤安装前的准备和基本安装设置语言环境安装常用软件1.安装前的准备和基本安装1.1安装前的准备访问http://cn.ubuntu.com/download/下载Ubuntu......