Linux搭建kafka
一、安装Java
1、查看linux 的系统版本
root@aliyun:~# uname --m
x86_64
2、安装java
mkdir -p /usr/local/java
tar -xf jdk-8u181-linux-x64.tar.gz
mv jdk1.8.0_181 java
vim ~/.bashrc
#set oracle jdk environment
export JAVA_HOME=/usr/local/java ## 这里要注意目录要换成自己解压的jdk 目录
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
update-alternatives --install /usr/bin/java java /usr/local/java/bin/java 300
update-alternatives --install /usr/bin/javac javac /usr/local/java/bin/javac 300
update-alternatives --install /usr/bin/jar jar /usr/local/java/bin/jar 300
update-alternatives --install /usr/bin/javah javah /usr/local/java/bin/javah 300
update-alternatives --install /usr/bin/javap javap /usr/local/java/bin/javap 300
source ~/.bashrc
3、查看自己的java版本
root@aliyun:/usr/local# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
二、安装zookeeper
wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
tar -xf zookeeper-3.4.10.tar.gz
mv zookeeper-3.4.10 zookeeper
cd zookeeper/src/c
./configure
make && make install
三、安装Kafka
wget http://mirror.bit.edu.cn/apache/kafka/2.0.0/kafka_2.11-2.0.0.tgz
mv kafka_2.11-2.0.0.tgz kafka
tar -xf kafka_2.11-2.0.0.tgz
mv kafka_2.11-2.0.0 kafka
四、设置zookeeper 和 kafka的全局命令
vim ~/.bashrc
export PATH=/usr/local/kafka/bin:/usr/local/zookeeper/bin:$PATH
source ~/.bashrc
启动服务
1、启动zookeeper
zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties >> /dev/null &
2、启动kafka
kafka-server-start.sh /usr/local/kafka/config/server.properties >> /dev/null &
3、生产一个TOPIC
kafka-console-producer.sh --broker-list 127.0.0.1:9092 --topic test
4、消费一个TOPIC
kafka-console-consumer.sh --zookeeper 127.0.0.1:2181 --topic test