Kafka集群模式安装(依赖外部Zookeeper)

1.Zookeeper安装

1.1上传解压

上传zookeeper安装包到服务器并解压,(同推荐使用软连接方式访问Zookeeper)

[xyes@kafka-2 bigdata]$ ln -s zookeeper-3.4.12/ zookeeper

1.2修改配置

# 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=/opt/bigdata/data/zookeeper  #持久化数据保存地址
dataLogDir=/opt/bigdata/logs/zookeeper #日志保存地址
# the port at which the clients will connect
clientPort=2181      #客户端端口(保持默认)
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# 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
#以下是各个节点的配置 server.id=主机名:端口:端口,需要和下面配置的myid一致
server.1=kafka-1:2888:3888  
server.2=kafka-2:2888:3888
server.3=kafka-3:2888:3888

最后将配置文件名改为zoo.cfg

1.3下发文件到各节点

scp -r zookeeper-3.4.12/ kafka-2:/opt/bigdata/

1.4配置各节点的myid

在前面配置的dataDir目录里创建myid文件并写入id值,我配置了3个节点,id分别为1,2,3,所以要在第一台机器里执行

[xyes@kafka-1 bigdata]$ cd data/zookeeper/
[xyes@kafka-1 zookeeper]$ echo 1 >myid

第二台

[xyes@kafka-2 bigdata]$ cd data/zookeeper/
[xyes@kafka-2 zookeeper]$ echo 2 >myid

第三台

[xyes@kafka-3 bigdata]$ cd data/zookeeper/
[xyes@kafka-3 zookeeper]$ echo 3 >myid

1.5启动zookeeper

需要分别启动每台机器的zookeeper,当然也可以写借本实现或者zookeeper自己启动

bin/zkServer.sh start

1.6验证是否启动成功

[xyes@kafka-2 zookeeper]$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/bigdata/zookeeper/bin/../conf/zoo.cfg
Mode: follower
或者
[xyes@kafka-3 zookeeper]$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/bigdata/zookeeper/bin/../conf/zoo.cfg
Mode: leader

2.Kafka 安装

2.1上传解压+软连接,不再赘述

2.2 修改配置文件

[xyes@kafka-3 config]$ ll
总用量 68
drwxrwxr-x. 2 xyes xyes 4096 51 21:47 backup
-rw-r--r--. 1 xyes xyes  906 51 21:47 connect-console-sink.properties
-rw-r--r--. 1 xyes xyes  909 51 21:47 connect-console-source.properties
-rw-r--r--. 1 xyes xyes 5807 51 21:47 connect-distributed.properties
-rw-r--r--. 1 xyes xyes  883 51 21:47 connect-file-sink.properties
-rw-r--r--. 1 xyes xyes  881 51 21:47 connect-file-source.properties
-rw-r--r--. 1 xyes xyes 1111 51 21:47 connect-log4j.properties
-rw-r--r--. 1 xyes xyes 2730 51 21:47 connect-standalone.properties
-rw-r--r--. 1 xyes xyes 1221 51 21:47 consumer.properties
-rw-r--r--. 1 xyes xyes 4727 51 21:47 log4j.properties
-rw-r--r--. 1 xyes xyes 1919 51 21:47 producer.properties
-rw-r--r--. 1 xyes xyes 6911 51 21:58 server.properties
-rw-r--r--. 1 xyes xyes 1032 51 21:47 tools-log4j.properties
-rw-r--r--. 1 xyes xyes 1023 51 21:47 zookeeper.properties

这里我们修改server.properties文件
由于配置较多,下面仅列出要修改的属性

broker.id=1 #每个节点都有属于自己的broker.id,需要下发完成之后再修改
port=9092   #绑定端口
host.name=kafka-3 #绑定主机 (每个节点单独配置)
log.dirs=/opt/bigdata/logs/kafka #日志保存地址(可选)
zookeeper.connect=kafka-1:2181,kafka-2:2181,kafka-3:2181  #zookeeper地址,逗号分割

2.3 下发文件到各节点

注意scp完成之后还应该单独修改各节点的broker.id和host.name属性

2.4逐一启动各节点的kafka服务

[xyes@kafka-3 kafka]$ bin/kafka-server-start.sh -daemon config/server.properties 

也可以不选择-deamon从而前台启动,
注意,-daemon 选项一定要站在指点配置文件之前,否则会报错

2.5测试

2.5.1创建topic

/kafka-topics.sh --create --topic helloword --partitions 3 --replication-factor 1 --zookeeper kafka-1:2181,kafka-2:2181,kafka-3:2181

–partitions和 –replication-factor可选

2.5.2启动kafka-console-consumer.sh

/kafka-console-consumer.sh --zookeeper kafka-1:2181,kafka-2:2181,kafka-3:2181 --from-beginning --topic helloword

–from-beginning 可选

2.5.3启动kafka-console-producer.sh生产数据

./kafka-console-producer.sh --broker-list kafka-1:9092,kafka-2:9092,kafka-3:9092 --topic helloword

发现再producer端输入数据consumer端可以接收到数据,到此Kafka基本环境配置完成
另外使用下面命令可以查看已创建的topic详情

[xyes@kafka-2 bin]$ ./kafka-topics.sh --zookeeper kafka-1:2181,kafka-2:2181,kafka-3:2181 --describe --topic helloword
Topic:helloword PartitionCount:3        ReplicationFactor:1     Configs:
        Topic: helloword        Partition: 0    Leader: 1       Replicas: 1     Isr: 1
        Topic: helloword        Partition: 1    Leader: 2       Replicas: 2     Isr: 2
        Topic: helloword        Partition: 2    Leader: 0       Replicas: 0     Isr: 0
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值