192.168.56.115 | 192.168.56.116 | 192.168.56.117 | |
环境 | Centos7 | ||
安装JDK | rpm -ivh jdk-8u151-linux-x64.rpm | ||
安装ZK | wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz tar -zxf zookeeper-3.4.14.tar.gz -C /usr/local/ ln -s /usr/local/zookeeper-3.4.14/ /usr/local/zookeeper mkdir -p /usr/local/zookeeper/{data,logs} | ||
修改ZK配置文件zoo.cfg | cat /usr/local/zookeeper/conf/zoo.cfg tickTime=2000 initLimit=10 syncLimit=5 dataDir=/usr/local/zookeeper/data dataLogDir=/usr/local/zookeeper/logs clientPort=2181 server.1=192.168.56.115:2888:3888 server.2=192.168.56.116:2888:3888 server.3=192.168.56.117:2888:3888 | ||
修改ZK配置文件myid | echo '1' > /usr/local/zookeeper/data/myid | echo '2' > /usr/local/zookeeper/data/myid | echo '3 > /usr/local/zookeeper/data/myid |
启动ZK | /usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/bin/zkServer.sh status #/usr/local/zookeeper/bin/zkServer.sh stop | ||
安装Kafka | wget https://archive.apache.org/dist/kafka/2.4.1/kafka_2.12-2.4.1.tgz tar -zxf kafka_2.12-2.4.1.tgz -C /usr/local/ ln -s /usr/local/kafka_2.12-2.4.1/ /usr/local/kafka mkdir -p /usr/local/kafka/data | ||
修改Kafak配置 | vim /usr/local/kafka/config/server.properties
delete.topic.enable=true log.dirs=/usr/local/kafka/data zookeeper.connect=192.168.56.115:2181,192.168.56.116:2181,192.168.56.117:2181 | ||
修改Kafak配置 | vim /usr/local/kafka/config/server.properties
broker.id=1 listeners=PLAINTEXT://192.168.56.115:9092 | vim /usr/local/kafka/config/server.properties
broker.id=2 listeners=PLAINTEXT://192.168.56.116:9092 | vim /usr/local/kafka/config/server.properties
broker.id=3 listeners=PLAINTEXT://192.168.56.117:9092 |
启动Kafka | nohup /usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties & # /usr/local/kafka/bin/kafka-server-stop.sh /usr/local/kafka/config/server.properties | ||
检查 | ./kafka-topics.sh --bootstrap-server 192.168.56.115:9092 --list | ||
配置环境变量 | echo 'export KAFKA_HOME=/usr/local/kafka' >> /etc/profile echo 'export PATH=$PATH:$KAFKA_HOME/bin' >> /etc/profile source /etc/profile | ||
topic操作 | cd /usr/local/kafka/bin/
#创建topic ./kafka-topics.sh --create --zookeeper 192.168.56.115:2181,192.168.56.116:2181,192.168.56.117:2181 --partitions 3 --replication-factor 3 --topic kafka_test
#查看topic列表 ./kafka-topics.sh --list --zookeeper 192.168.56.115:2181,192.168.56.116:2181,192.168.56.117:2181
#查看topic详情 ./kafka-topics.sh --describe --zookeeper 192.168.56.115:2181,192.168.56.116:2181,192.168.56.117:2181 --topic kafka_test
#创建生产者 /usr/local/kafka/bin/kafka-console-producer.sh --broker-list 192.168.56.115:9092,192.168.56.116:9092,192.168.56.117:9092 --topic kafka_test
#创建消费者
#删除topic ./kafka-topics.sh --delete --zookeeper 192.168.56.115:2181,192.168.56.116:2181,192.168.56.117:2181 --topic kafka_test | ||