内网离线搭建之----kafka集群

2023-12-25 18:59:43

1.系统版本

虚拟机192.168.9.184
虚拟机192.168.9.185
虚拟机192.168.9.186

系统 centos7 7.6.1810

2.依赖下载

ps:置顶资源里已经下载好了,直接用!!!!!!!!!

zookeeper:

http://archive.apache.org/dist/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz

kafka地址:

https://archive.apache.org/dist/kafka/0.10.1.1/kafka_2.11-0.10.1.1.tgz

jdk:

1.8版本 可以自己找

3.zookeeper安装

1.解压

tar -zxvf zookeeper-3.4.13.tar.gz -C /root

2.创建存放数据日志地址

cd zookeeper-3.4.13 mkdir zkData mkdir zkLogs

3.修改配置文件

cd conf 
cp zoo_sample.cfg zoo.cfg 
vi zoo.cfg

配置文件修改内容:

dataDir=/root/zookeeper-3.4.13/zkData 
dataLogDir=/root/zookeeper-3.4.13/zkLogs

server.1=192.168.9.184:2888:3888 
server.2=192.168.9.185:2888:3888 
server.3=192.168.9.186:2888:3888

4.添加标识

cd /root/zookeeper-3.4.13/zkData 
echo 1 > myid

集群每台服务器添加不一样的id? 184 185 186分别为1 2 3

5.启动

/root/zookeeper-3.4.13/bin/zkServer.sh start

/root/zookeeper-3.4.13/bin/zkServer.sh stop

6.配置快捷命令


vi /etc/profile

#末尾添加
export ZOOKEEPER_HOME=/root/zookeeper-3.4.13
export PATH=$PATH:$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf

?刷新配置

source /etc/profile

7.快捷指令

zkServer.sh start
zkServer.sh stop

4.kafka安装

1.解压

tar -zxvf kafka_2.12-2.1.1.tgz

2.创建存放数据日志地址

cd kafka_2.12-2.1.1 mkdir Data

3.修改配置文件(注意自己的解压地址)

/root/kafka_2.12-2.1.1/config

vi server.properties
broker.id=1

log.dirs=/root/kafka_2.12-2.1.1/kafka-logs 

zookeeper.connect=192.168.9.186:2181,192.168.9.184:2181,192.168.9.185:2181

ps:broker.id? 集群中不能重复

4.启动

/root/kafka_2.12-2.1.1/bin/kafka-server-start.sh /root/kafka_2.12-2.1.1/config/server.properties &

5.配置快捷命令


vi /etc/profile

#末尾添加
export KAFKA_HOME=/root/kafka/kafka_2.12-2.1.1
export PATH=$PATH:$KAFKA_HOME/bin

生效

source /etc/profile

6.重新启动

kafka-server-start.sh /root/kafka_2.12-2.1.1/config/server.properties &

5.常用命令

zookeeper常用命令(需配置快捷命令)

zkServer.sh start
zkServer.sh status
zkServer.sh stop
zkServer.sh restart

kafka常用命令(需配置快捷命令)

启动

kafka-topics.sh --bookafka-server-start.sh /root/kafka_2.12-2.1.1/config/server.properties &

查看状态

jps -l

创建topic

kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 3 --topic test

topic 详细分区信息(注意避坑)

kafka-topics.sh --bootstrap-server localhost:9092 --describe 

#kafka版本《2.2 查询分区、topic等涉及到zookeeper的命令 
# --bootstrap-server 替换--zookeeper 

kafka-topics.sh --zookeeper localhost:9092 --describe 

#具体topic查看 不加<> 
kafka-topics.sh --zookeeper localhost:2181 --describe --topic <topic_name>

topic信息

kafka-topics.sh --zookeeper localhost:2181 --list

查看Kafka Consumer的状态:

kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group

#OR

kafka-consumer-groups.sh --zookeeper localhost:9092 --describe --group

6.常见问题

1.

#kafka版本<2.2? 查询分区、topic等涉及到zookeeper的命令?
# --bootstrap-server 替换--zookeeper?

2.启动kafka失败 ,配置没问题情况下

ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING
	at kafka.zookeeper.ZooKeeperClient.$anonfun$waitUntilConnected$3(ZooKeeperClient.scala:268)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at kafka.utils.CoreUtils$.inLock(CoreUtils.scala:251)
	at kafka.zookeeper.ZooKeeperClient.waitUntilConnected(ZooKeeperClient.scala:264)
	at kafka.zookeeper.ZooKeeperClient.<init>(ZooKeeperClient.scala:97)
	at kafka.zk.KafkaZkClient$.apply(KafkaZkClient.scala:1694)
	at kafka.server.KafkaServer.createZkClient$1(KafkaServer.scala:348)
	at kafka.server.KafkaServer.initZkClient(KafkaServer.scala:372)
	at kafka.server.KafkaServer.startup(KafkaServer.scala:202)
	at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
	at kafka.Kafka$.main(Kafka.scala:75)
	at kafka.Kafka.main(Kafka.scala)
  • 检查防火墙
  • 修改配置文件server.properties

  • zookeeper.connection.timeout.ms=60000

文章来源:https://blog.csdn.net/qq_27437073/article/details/135110037
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。