#注意:在zookeeper配置文件中或者后面不能跟注释文字,不然会报错!
#说明:
tickTime: 这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
2888端口:表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;
3888端口:表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口
7、分别在kafka1和kafka2服务器上创建datadir目录
mkdir -p /opt/kafka/data
mkdir -p /opt/kafka/data/zookeeper
8、分别写入id
[root@kafka1 opt]# echo "1" > /opt/kafka/data/zookeeper/myid
[root@kafka2 ~]# echo "2" > /opt/kafka/data/zookeeper/myid
#注意ID不能一样
9、启动zookeeper集群
cd /opt/zookeeper/
bin/zkServer.sh start
10、启动效果
[rootkafka1 ~]# netstat -nlpt | grep -E "2181|2888|3888"
tcp 0 0 :::2181 :::* LISTEN 33644/java
tcp 0 0 ::ffff:10.1.1.247:3888 :::* LISTEN 33644/java
[root@kafka2 ~]# netstat -nlpt | grep -E "2181|2888|3888"
tcp 0 0 :::2181 :::* LISTEN 35016/java
tcp 0 0 ::ffff:10.1.1.248:2888 :::* LISTEN 35016/java #哪台是leader,那么他就拥有2888端口
tcp 0 0 ::ffff:10.1.1.248:3888 :::* LISTEN 35016/java
二、kafka集群搭建
1、配置文件
[root@kafka1 opt]# cat /opt/kafka/config/server.properties | grep -v '^#'|grep -v '^$'
broker.id=1
listeners=PLAINTEXT://172.16.81.131: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=/opt/kafka/data/kafka-logs
num.partitions=10
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=172.16.81.131:2181,172.16.81.132:2181
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0
[root@kafka2 ~]# cat /opt/kafka/config/server.properties | grep -v '^#'|grep -v '^$'
broker.id=2
listeners=PLAINTEXT://172.16.81.132: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=/opt/kafka/data/kafka-logs
num.partitions=10
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=172.16.81.131:2181,172.16.81.132:2181
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0
#注意:broker.id不能相同
2、启动kafka集群
/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties &
3、启动效果
[root@kafka1 opt]# netstat -lntp
Active Internet connections (only servers)