前提已经安装JDK:【Linux】安装JDK8,查看java进程、查看jdk安装路径
1、下载kafka和zookeeper,本文放在/home/kafka目录下
直接下载:wget https://archive.apache.org/dist/kafka/2.2.1/kafka_2.11-2.1.1.tgz
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
下载好上传到Linux
https://archive.apache.org/dist/kafka/2.2.1/
https://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/
2、解压kafka和zookeeper
tar -zxvf zookeeper-3.4.6.tar.gz
tar -zxvf kafka_2.11-2.1.1.tgz
3、修改zookeeper
环境变量设置
vim /etc/profile
按i编辑,文件最后添加
export ZOOKEEPER=/home/kafka/zookeeper-3.4.6/
export PATH=$PATH:$ZOOKEEPER/bin
按ESC,再按:wq退出
重新加载配置文件
source /etc/profile
复制一个zoo.cfg
cp /home/kafka/zookeeper-3.4.6/conf/zoo_sample.cfg /home/kafka/zookeeper-3.4.6/conf/zoo.cfg
创建两个文件夹
mkdir /home/kafka/zookeeper-3.4.6/data
mkdir /home/kafka/zookeeper-3.4.6/log
修改zoo.cfg
进入配置文件后,按i
vi /home/kafka/zookeeper-3.4.6/conf/zoo.cfg
内容
dataDir=/home/kafka/zookeeper-3.4.6/data
dataLogDir=/home/kafka/zookeeper-3.4.6/log
clientPort=2182
按ESC,再按:wq
4、启动zookeeper
/home/kafka/zookeeper-3.4.6/bin/zkServer.sh start
5、修改kafka
创建文件夹
mkdir /home/kafka/kafka_2.11-2.1.1/log
修改配置文件
vi /home/kafka/kafka_2.11-2.1.1/config/server.properties
按i进入编辑,修改
log.dirs=/home/kafka/kafka_2.11-2.1.1/log
zookeeper.connect=localhost:2182
按ESC,再按:wq退出
6、启动kafka
/home/kafka/kafka_2.11-2.1.1/bin/kafka-server-start.sh /home/kafka/kafka_2.11-2.1.1/config/server.properties
后台启动:/home/kafka/kafka_2.11-2.1.1/bin/kafka-server-start.sh -daemon /home/kafka/kafka_2.11-2.1.1/config/server.properties
7、查看kafka启动
netstat -lnp|grep 9092
或者
jps
8、启动生产者/home/kafka/kafka_2.11-2.1.1/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic helloKafka
9、启动消费者/home/kafka/kafka_2.11-2.1.1/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic helloKafka
参考文章:https://blog.csdn.net/weixin_39984161/article/details/91971731