kafka集群安装

kafka集群:

kafka-1:192.168.19.202

kafka-2:192.168.19.203

1、部署zookeeper集群

以下步骤集群每个节点都要做,特别的步骤再做说明。

添加hosts

[root@kafka-1 ~]# vim /etc/hosts

192.168.19.202 kafka-1

192.168.19.203 kafka-2

安装jdk,安装zookeeper,添加环境变量参考kafka安装

编辑配置文件zoo.cfg

[root@kafka-1 ~]# vim /usr/zookeeper-3.4.8/conf/zoo.cfg

server.1=192.168.19.202:2888:3888

server.2=192.168.19.203:2888:3888

[root@kafka-1 ~]# vim /usr/zookeeper-3.4.8/conf/zoo.cfg

dataDir=/data/zookeeper/data

[root@kafka-1 ~]# mkdir -p /data/zookeeper/data

[root@kafka-1 ~]# cd /data/zookeeper/data/

[root@kafka-1 data]# ls

[root@kafka-1 data]# echo 1 > myid

[root@kafka-1 data]# ls

myid

[root@kafka-1 data]# cat myid

1


[root@kafka-2 ~]# cd /data/zookeeper/data/

[root@kafka-2 data]# echo 2 > myid

[root@kafka-2 data]# ls

myid

[root@kafka-2 data]# cat myid

2

myid的数值与zoo.cfg里“server.1”的数字对应


服务启动

[root@kafka-1 bin]# zkServer.sh start

ZooKeeper JMX enabled by default

Using config: /usr/zookeeper-3.4.8/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

查看状态

[root@kafka-1 bin]# zkServer.sh status

ZooKeeper JMX enabled by default

Using config: /usr/zookeeper-3.4.8/bin/../conf/zoo.cfg

Mode: leader

[root@kafka-2 bin]# zkServer.sh start

ZooKeeper JMX enabled by default

Using config: /usr/zookeeper-3.4.8/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

查看状态

[root@kafka-1 bin]# zkServer.sh status

ZooKeeper JMX enabled by default

Using config: /usr/zookeeper-3.4.8/bin/../conf/zoo.cfg

Mode: follower

安装kafka--参考kafka安装

kafka配置,编辑配置文件server.properties

[root@kafka-1 config]# vim server.properties

broker.id=1(正整数,唯一)

host.name=192.168.19.202(可有可无)

log.retention.hours=168

message.max.byte=5242880

default.replication.factor=2

replica.fetch.max.bytes=5242880

zookeeper.connect=192.168.19.202:2181,192.168.19.203:2181(指定zookeeper集群)

[root@kafka-2 config]# vim server.properties

broker.id=2

host.name=192.168.19.203

log.retention.hours=168

message.max.byte=5242880

default.replication.factor=2

replica.fetch.max.bytes=5242880

zookeeper.connect=192.168.19.202:2181,192.168.19.203:2181

kafka开启

[root@kafka-1 kafka_2.11-0.11.0.1]# ./bin/kafka-server-start.sh config/server.properties &

[1] 2614

[root@kafka-2 kafka_2.11-0.11.0.1]# ./bin/kafka-server-start.sh config/server.properties &

[1] 2625

[root@kafka-1 kafka_2.11-0.11.0.1]# jps

2526 QuorumPeerMain

3780 Jps

3485 Kafka

[root@kafka-2 kafka_2.11-0.11.0.1]# jps

3765 Jps

3478 Kafka

2532 QuorumPeerMain

创建topic

[root@kafka-1 kafka_2.11-0.11.0.1]# ./bin/kafka-topics.sh --create --zookeeper 192.168.19.202:2181,192.168.19.203:2181 --replication-factor 2 --partitions 1 --topic xia

Created topic "xia".

查看已创建的topic

[root@kafka-1 kafka_2.11-0.11.0.1]# ./bin/kafka-topics.sh --list --zookeeper 192.168.19.202:2181,192.168.19.203:2181

xia

发送消息(192.168.19.202)

[root@kafka-1 kafka_2.11-0.11.0.1]# ./bin/kafka-console-producer.sh --broker-list 192.168.19.202:9092 --topic xia

>this is a test too

接收消息(192.168.19.203)

[root@kafka-2 kafka_2.11-0.11.0.1]# ./bin/kafka-console-consumer.sh --zookeeper 192.168.19.202:2181,192.168.19.203:2181 --topic xia --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 a test too

this is a test too

你可能感兴趣的:(kafka集群安装)