centos8安装kafka(单机方式)
一,下载kafka
1,官网地址
http://kafka.apache.org/downloads.html
2,下载
[ source]# wget http://mirror.bit.edu.cn/apache/kafka/2.4.0/kafka_2.13-2.4.0.tgz
说明:架构森林是一个专注架构的博客,对应的源码可以访问这里获取
说明:作者邮箱:
二,解压:
[ source]# tar -zxvf kafka_2.13-2.4.0.tgz [ source]# mv kafka_2.13-2.4.0 /usr/local/soft/
三,启动zookeeper
[ source]# systemctl status zookeeper 如果状态不是running则: [ source]# systemctl start zookeeper
四,创建日志目录:
[ source]# cd /data/logs/ [ logs]# mkdir kafkalogs [ logs]# chmod 777 kafkalogs
五,配置kafka的日志目录
[ ~]# vi /usr/local/soft/kafka_2.13-2.4.0/config/server.properties
只修改log.dirs的值,设置为自定义的kafka日志目录
log.dirs=/data/logs/kafkalogs
六,配置环境变量
[ ~]# vi /etc/profile
说明:增加kafka的所在目录变量,如下两行
export KAFKA_HOME=/usr/local/soft/kafka_2.13-2.4.0 export PATH=$PATH:$KAFKA_HOME/bin
七,启动服务/停止服务
启动kafka
[ ~]# /usr/local/soft/kafka_2.13-2.4.0/bin/kafka-server-start.sh -daemon /usr/local/soft/kafka_2.13-2.4.0/config/server.properties
停止kafka
[ ~]# /usr/local/soft/kafka_2.13-2.4.0/bin/kafka-server-stop.sh
八,测试kafka服务启动后端口是否绑定:
telnet到默认的端口9092
[ ~]# telnet localhost 9092 Trying ::1... Connected to localhost. Escape character is ‘^]‘.
九,用systemd管理kafka服务
1,创建service文件
[ ~]# vi /etc/systemd/system/kafka.service
文件内容为:
[Unit] Description=Apache Kafka server (broker) After=network.target zookeeper.service [Service] Type=forking User=root Group=root Environment=JAVA_HOME=/usr/local/soft/jdk-13.0.2 ExecStart=/usr/local/soft/kafka_2.13-2.4.0/bin/kafka-server-start.sh -daemon /usr/local/soft/kafka_2.13-2.4.0/config/server.properties ExecStop=/usr/local/soft/kafka_2.13-2.4.0/bin/kafka-server-stop.sh #Restart=on-failure [Install] WantedBy=multi-user.target
注意:Environment=JAVA_HOME=/usr/local/soft/jdk-13.0.2
这一行必须有,否则启动和关停时会报错
2,测试启动、停止kafka服务
启动
[ ~]# systemctl start kafka
停止
[ ~]# systemctl stop kafka
十,解决一个问题:
kafka-server-stop.sh不能正常关闭kafka
说明:此问题在fedora30上存在,centos8上面未发现:
修改一下脚本即可:
[ system]# vi /usr/local/soft/kafka_2.13-2.4.0/bin/kafka-server-stop.sh
把得到进程id的命令改成用jps获取 修改为:
#PIDS=$(ps ax | grep -i ‘kafka\.Kafka‘ | grep java | grep -v grep | awk ‘{print $1}‘) PIDS=$(jps -lm | grep -i ‘kafka.Kafka‘ | awk ‘{print $1}‘)
说明:jps最好加上绝对路径
十一,查看本地已安装的kafka的版本:进入到kafka安装目录下的libs目录下面,可以看到kafka_2.13-2.4.0.jar这个文件,
也可以用命令来获取:
[ libs]# find ./ -name \*kafka_\* | head -1 | grep -o ‘\kafka[^\n]*‘ kafka_2.13-2.4.0.jar
说明:2.13是Scala 的版本,2.4.0就是你kafka的版本
十二,查看本地centos的版本:
[ lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core)