一、安装zookeeper集群
1、安装jdk1.8
2、下载apache-zookeeper-3.5.7-bin.tar.gz并解压
第1台机器:
mkdir /usr/local/zookeeper/data
mv /usr/local/zookeeper/conf/zoo_sample.cfg /usr/local/zookeeper/conf/zoo.cfg
vim /usr/local/zookeeper/conf/zoo.cfg
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs
clientPort=2181
server.1=172.16.136.144:2888:3888
server.2=172.16.136.145:2888:3888
server.3=172.16.136.146:2888:3888
echo 1 >/usr/local/zookeeper/data/myid
第2台机器(同上):
echo 2 >/usr/local/zookeeper/data/myid
第3台机器(同上):
echo 3 >/usr/local/zookeeper/data/myid
3、依次启动zookeeper集群各节点
./bin/zkServer.sh start
./bin/zkServer.sh status
二、安装kafka集群
1、下载kafka_2.12-2.4.1.tgz并解压
第1台机器:
vim server.properties
broker.id=1
host.name=172.16.136.144
log.dirs=/usr/local/kafka/data
zookeeper.connect=172.16.136.144:2181,172.16.136.145:2181,172.16.136.146:2181
zookeeper.connection.timeout.ms=60000
第2台机器(同上):
broker.id=2
host.name=172.16.136.145
第3台机器(同上):
broker.id=3
host.name=172.16.136.146
2、依次启动kafka集群各节点
./bin/kafka-server-start.sh -daemon config/server.properties
3、测试Kafka集群是否启动成功
./bin/kafka-topics.sh --bootstrap-server node1:9092,node2:9092,node3:9092 --list
打印空、不报错就代表启动成功了
4、主题topic
# 创建名为test的主题
bin/kafka-topics.sh --create --bootstrap-server node1:9092,node2:9092,node3:9092 --topic test
# 查看目前Kafka中的主题
bin/kafka-topics.sh --list --bootstrap-servernode1:9092,node2:9092,node3:9092
生产消息
bin/kafka-console-producer.sh --broker-list node1:9092,node2:9092,node3:9092 --topic test
消费消息
bin/kafka-console-consumer.sh --bootstrap-server node1:9092,node2:9092,node3:9092 --topic test --from-beginning