Zookeeper+Kafka集群部署

Zookeeper+Kafka集群部署

主机规划:

10.200.3.85    Kafka+ZooKeeper

10.200.3.86    Kafka+ZooKeeper

10.200.3.87    Kafka+ZooKeeper

软件下载地址:

#wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
#wget http://mirror.bit.edu.cn/apache/kafka/1.1.0/kafka_2.12-1.1.0.tgz

三台主机hosts文件一致:

# cat /etc/hosts
10.200.3.85 ZooKeeper-Kafka-01
10.200.3.86 ZooKeeper-Kafka-02
10.200.3.87 ZooKeeper-Kafka-03

一、安装zookeeper

1.在master节点上操作:

[[email protected]01 src]# tar -zxvf zookeeper-3.4.10.tar.gz -C /usr/local/
[[email protected]-Kafka-01 src]# cd ..
[[email protected]-Kafka-01 local]# ln -s zookeeper-3.4.10 zookeeper
[[email protected]-Kafka-01 local]# cd zookeeper/conf/
[[email protected]-Kafka-01 conf]# cp zoo_sample.cfg zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/tmp/zookeeper
clientPort=2181
server.1=ZooKeeper-Kafka-01:2888:3888
server.2=ZooKeeper-Kafka-02:2888:3888
server.3=ZooKeeper-Kafka-03:2888:3888

2.创建dataDir目录创建/tmp/zookeeper

# 在master节点上

[[email protected]01 conf]# mkdir /tmp/zookeeper
[[email protected]-Kafka-01 conf]# touch /tmp/zookeeper/myid
[[email protected]-Kafka-01 conf]# echo 1 > /tmp/zookeeper/myid

3.将zookeeper文件复制到另外两个节点:

[[email protected]01 local]# scp -r zookeeper-3.4.10/ 10.200.3.86:/usr/local/
[[email protected]-Kafka-01 local]# scp -r zookeeper-3.4.10/ 10.200.3.87:/usr/local/

4.在两个slave节点创建目录和文件

#ZooKeeper-Kafka-02节点:

[[email protected]02 local]# ln -s zookeeper-3.4.10 zookeeper
[[email protected]-Kafka-02 local]# mkdir /tmp/zookeeper
[[email protected]-Kafka-02 local]# touch /tmp/zookeeper/myid
[[email protected]-Kafka-02 local]# echo 2 > /tmp/zookeeper/myid

#ZooKeeper-Kafka-03节点

[[email protected]03 local]# ln -s zookeeper-3.4.10 zookeeper
[[email protected]-Kafka-03 local]# mkdir /tmp/zookeeper
[[email protected]-Kafka-03 local]# touch /tmp/zookeeper/myid
[[email protected]-Kafka-03 local]# echo 3 > /tmp/zookeeper/myid

5.分别在每个节点上启动 zookeeper测试:

[[email protected]01 zookeeper]# ./bin/zkServer.sh start
[[email protected]-Kafka-02 zookeeper]# ./bin/zkServer.sh start
[[email protected]-Kafka-03 zookeeper]# ./bin/zkServer.sh start

6.查看状态:

[[email protected]01 zookeeper]# ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[[email protected]-Kafka-02 zookeeper]# ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[[email protected]-Kafka-03 zookeeper]# ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower

至此zookeeper集群安装成功!!!

Kafka集群安装配置

1.安装:

[[email protected]01 src]# tar -zxvf kafka_2.12-1.1.0.tgz -C /usr/local/
[[email protected]-Kafka-01 src]# cd ..
[[email protected]-Kafka-01 local]# ln -s kafka_2.12-1.1.0 kafka

2.修改server.properties文件

[[email protected]01 local]# cd kafka/config/
[[email protected]-Kafka-01 config]# vim server.properties
# master为0
broker.id=0
# 连接
zookeeper.connect=ZooKeeper-Kafka-01:2181,ZooKeeper-Kafka-02:2181,ZooKeeper-Kafka-03:2181
# 可删除topic
delete.topic.enable=true

3.将 kafka_2.12-1.1.0 文件夹复制到另外两个节点下

[[email protected]01 local]# scp -r kafka_2.12-1.1.0/ 10.200.3.86:/usr/local/
[[email protected]-Kafka-01 local]# scp -r kafka_2.12-1.1.0/ 10.200.3.87:/usr/local/

并修改每个节点对应的 server.properties 文件的 broker.id:

[[email protected]02 config]# cat server.properties |grep broker.id
broker.id=1
[[email protected]-Kafka-03 config]# cat server.properties |grep broker.id
broker.id=2

4.启动服务

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

Zookeeper+Kafka集群测试

创建topic:

[[email protected]01 kafka]# bin/kafka-topics.sh --create --zookeeper ZooKeeper-Kafka-01:2181, ZooKeeper-Kafka-02:2181, ZooKeeper-Kafka-03:2181 --replication-factor 3 --partitions 3 --topic test

显示topic:

[[email protected]01 kafka]# bin/kafka-topics.sh --describe --zookeeper ZooKeeper-Kafka-01:2181, ZooKeeper-Kafka-02:2181, ZooKeeper-Kafka-03:2181 --topic test

列出topic:

[[email protected]01 kafka]# bin/kafka-topics.sh --list --zookeeper ZooKeeper-Kafka-01:2181, ZooKeeper-Kafka-02:2181, ZooKeeper-Kafka-03:2181
test

创建 producer(生产者);

# 在master节点上 测试生产消息

[[email protected]01 kafka]# bin/kafka-console-producer.sh --broker-list ZooKeeper-Kafka-01:9092 -topic test
>hello world
>[2018-04-03 12:18:25,545] INFO Updated PartitionLeaderEpoch. New: {epoch:0, offset:0}, Current: {epoch:-1, offset:-1} for Partition: test-0. Cache now contains 0 entries. (kafka.server.epoch.LeaderEpochFileCache)
this is example ...
>[2018-04-03 12:19:16,342] INFO Updated PartitionLeaderEpoch. New: {epoch:0, offset:0}, Current: {epoch:-1, offset:-1} for Partition: test-2. Cache now contains 0 entries. (kafka.server.epoch.LeaderEpochFileCache)
welcome to china
>[2018-04-03 12:20:53,141] INFO Updated PartitionLeaderEpoch. New: {epoch:0, offset:0}, Current: {epoch:-1, offset:-1} for Partition: test-1. Cache now contains 0 entries. (kafka.server.epoch.LeaderEpochFileCache)

创建 consumer(消费者):

# 在ZooKeeper-Kafka-02节点上 测试消费

[[email protected]02 kafka]# bin/kafka-console-consumer.sh --zookeeper ZooKeeper-Kafka-01:2181, ZooKeeper-Kafka-02:2181, ZooKeeper-Kafka-03:2181 -topic test --from-beginning
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
this is example ...
hello world
[2018-04-03 12:20:53,145] INFO Updated PartitionLeaderEpoch. New: {epoch:0, offset:0}, Current: {epoch:-1, offset:-1} for Partition: test-1. Cache now contains 0 entries. (kafka.server.epoch.LeaderEpochFileCache)
welcome to china

#在ZooKeeper-Kafka-03节点上 测试消费

[[email protected]03 kafka]# bin/kafka-console-consumer.sh --zookeeper ZooKeeper-Kafka-01:2181, ZooKeeper-Kafka-02:2181, ZooKeeper-Kafka-03:2181 -topic test --from-beginning
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
welcome to china
hello world
this is example ...

然后在 producer 里输入消息,consumer 中就会显示出同样的内容,表示消费成功

删除 topic 和关闭服务

[[email protected]01 kafka]# bin/kafka-topics.sh --delete --zookeeper ZooKeeper-Kafka-01:2181, ZooKeeper-Kafka-02:2181, ZooKeeper-Kafka-03:2181 --topic test

启动服务:

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

停止服务:

bin/kafka-server-stop.sh

至此Zookeeper+Kafka集群配置成功.

参考文档:https://blog.csdn.net/jiecxy/article/details/52348120

原文地址:https://www.cnblogs.com/saneri/p/8762168.html

时间: 2024-12-10 20:00:49

Zookeeper+Kafka集群部署的相关文章

ELK5.2+kafka+zookeeper+filebeat集群部署

架构图 考虑到日志系统的可扩展性以及目前的资源(部分功能复用),整个ELK架构如下: 架构解读 : (整个架构从左到右,总共分为5层) 第一层.数据采集层 最左边的是业务服务器集群,上面安装了filebeat做日志采集,同时把采集的日志分别发送给两个logstash服务(2.187.2.189) 第二层.数据处理层,数据缓存层 logstash服务把接受到的日志经过格式处理,转存到本地的kafka broker+zookeeper 集群中. 第三层.数据转发层 这个单独的Logstash(2.1

zookeeper+kafka集群安装之二

zookeeper+kafka集群安装之二 此为上一篇文章的续篇, kafka安装需要依赖zookeeper, 本文与上一篇文章都是真正分布式安装配置, 可以直接用于生产环境. zookeeper安装参考: http://blog.csdn.net/ubuntu64fan/article/details/26678877 首先了解几个kafka中的概念: kafka是一个消息队列服务器,服务称为broker, 消息发送者称为producer, 消息接收者称为consumer; 通常我们部署多个b

大数据技术之_10_Kafka学习_Kafka概述+Kafka集群部署+Kafka工作流程分析+Kafka API实战+Kafka Producer拦截器+Kafka Streams

第1章 Kafka概述1.1 消息队列1.2 为什么需要消息队列1.3 什么是Kafka1.4 Kafka架构第2章 Kafka集群部署2.1 环境准备2.1.1 集群规划2.1.2 jar包下载2.2 Kafka集群部署2.3 Kafka命令行操作第3章 Kafka工作流程分析3.1 Kafka 生产过程分析3.1.1 写入方式3.1.2 分区(Partition)3.1.3 副本(Replication)3.1.4 写入流程3.2 Broker 保存消息3.2.1 存储方式3.2.2 存储策

3、Kafka集群部署

Kafka集群部署 1)解压安装包 [ip101]$ tar -zxvf kafka_2.11-0.11.0.0.tgz -C /opt/app/ 2)修改解压后的文件名称 [ip101]$ mv kafka_2.11-0.11.0.0/ kafka 3)在/opt/app/kafka目录下创建logs文件夹 [ip101]$ mkdir logs 4)修改配置文件 [ip101]$ cd config/ [[email protected] config]$ vi server.propert

zookeeper+kafka集群安装之一

zookeeper+kafka集群安装之一 准备3台虚拟机, 系统是RHEL64服务版. 1) 每台机器配置如下: $ cat /etc/hosts ... # zookeeper hostnames: 192.168.8.182 zk1 192.168.8.183 zk2 192.168.8.184 zk3 2) 每台机器上安装jdk, zookeeper, kafka, 配置如下: $ vi /etc/profile ... # jdk, zookeeper, kafka export KA

Centos7安装zookeeper+kafka集群

Centos7安装zookeeper+kafka集群 1  Zookeeper和kafka简介 1)  ZooKeeper 是一个分布式的.分层级的文件系统,能促进客户端间的松耦合,并提供最终一致的,用于管理.协调Kafka代理,zookeeper集群中一台服务器作为Leader,其它作为Follower 2)  Apache Kafka 是分布式发布-订阅消息系统,kafka对消息保存时根据Topic进行归类,每个topic将被分成多个partition(区),每条消息在文件中的位置称为off

Kafka集群部署

一. 关于kafka Kafka是一种高吞吐量的分布式发布订阅消息系统,它可以处理消费者规模的网站中的所有动作流数据. 这种动作(网页浏览,搜索和其他用户的行动)是在现代网络上的许多社会功能的一个关键因素. 这些数据通常是由于吞吐量的要求而通过处理日志和日志聚合来解决. 对于像Hadoop的一样的日志数据和离线分析系统,但又要求实时处理的限制,这是一个可行的解决方案.Kafka的目的是通过Hadoop的并行加载机制来统一线上和离线的消息处理,也是为了通过集群机来提供实时的消费. 关于Kafka的

4 kafka集群部署及生产者java客户端编程 + kafka消费者java客户端编程

本博文的主要内容有   kafka的单机模式部署 kafka的分布式模式部署 生产者java客户端编程 消费者java客户端编程 运行kafka ,需要依赖 zookeeper,你可以使用已有的 zookeeper 集群或者利用 kafka自带的zookeeper. 单机模式,用的是kafka自带的zookeeper, 分布式模式,用的是外部安装的zookeeper,即公共的zookeeper. Step 6: Setting up a multi-broker cluster So far w

Kafka集群部署及測试

题记 眼下我们对大数据进行研究方向以Spark为主,当中Spark Streaming是能够接收动态数据流并进行处理.那么Spark Streaming支持多源的数据发送端,比如TCP.ZeroMQ.自然也包含Kafka,并且Kafka+SparkStreaming的技术融合也比較经常使用并且成熟,所以我们须要搭建一个Kafka集群进行流数据的測试. -------------------------------------------------------------------------