3台虚拟机均进行以下操作:
// 解压下载好的kafka压缩包并重命名
cd /usr/local
wget http://mirror.bit.edu.cn/apache/kafka/1.0.0/kafka_2.11-1.0.0.tgz
tar -zxvf kafka_2.11-1.0.0.tgz
mv kafka_2.12-0.11.0.0 kafka
// 修改配置文件
vi ./kafka/config/server.properties
需要修改的内容如下(192.168.212.169)
broker.id=0
listeners=PLAINTEXT://192.168.131.130:9092
zookeeper.connect=192.168.131.130:2181,192.168.131.131:2181,192.168.131.132:2181
需要修改的内容如下(192.168.212.170)
broker.id=1
listeners=PLAINTEXT://192.168.212.170:9092
zookeeper.connect=192.168.131.130:2181,192.168.131.131:2181,192.168.131.132:2181
需要修改的内容如下(192.168.212.171)
broker.id=2
listeners=PLAINTEXT://192.168.212.171:9092
zookeeper.connect=192.168.131.130:2181,192.168.131.131:2181,192.168.131.132:2181
// 在系统环境中配置kafka的路径
vi /etc/profile
// 在文件最下方添加kafka路径
export KAFKA_HOME=/usr/local/kafka
// 多路径PATH写法为PATH=${ZOOKEEPER_HOME}/bin:${KAFKA_HOME}/bin:$PATH
PATH=${KAFKA_HOME}/bin:$PATH
export PATH
// 使修改完的环境变量生效
source /etc/profile
192.168.212.169:2181,192.168.212.172:2181,192.168.212.173:2181
Kafka集群环境测试
1、开启3台虚拟机的zookeeper程序
/usr/local/zookeeper/bin/zkServer.sh start
开启成功后查看zookeeper集群的状态
/usr/local/zookeeper/bin/zkServer.sh status
出现Mode:follower或是Mode:leader则代表成功
2、在后台开启3台虚拟机的kafka程序(cd /usr/local/kafka)
./bin/kafka-server-start.sh -daemon config/server.properties
3、在其中一台虚拟机(192.168.131.130)创建topic
/usr/local/kafka/bin/kafka-topics.sh –create –zookeeper 192.168.131.130:2181 –replication-factor 3 –partitions 1 –topic my-replicated-topic
// 查看创建的topic信息
/usr/local/kafka/bin/kafka-topics.sh –describe –zookeeper 192.168.131.130:2181 –topic my-replicated-topic