阅读目录:
1. 关闭防火墙和Selinux
2. 安装所需环境JDK,Zookeeper
3. 下载Kafka 1.0.0版本
4. 配置Kafka
5. 启动Kafka并验证
6. 报错及解决
7. 说明
1. 关闭防火墙和Selinux
Linux的防火墙是咱们新手的噩梦,很多情况会出现能ping通,但是访问不了Web页面。所以开始就干掉它!
1.1 关闭防火墙
[root@localhost ~]# /etc/init.d/iptables stop iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ]
1.2 开机自动关闭防火墙
[root@localhost ~]# chkconfig iptables off
1.3 查看Selinux状态
[root@localhost ~]# sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: enforcing Mode from config file: enforcing Policy MLS status: enabled Policy deny_unknown status: allowed Max kernel policy version: 28
1.4 关闭selinux
[root@localhost ~]# vim /etc/selinux/config
修改 SELINUX=disabled
注:永久开启->改成:2. 安装所需环境JDK,Zookeeper
JDK直接参考本文:
Zookeeper直接参考本文:
3. 下载Kafka 1.0.0版本
注:创建一个kafka消息目录,主要存放kafka消息
[root@localhost /]# mkdir /usr/local/kafka [root@localhost /]# mkdir /usr/local/kafka/kafka-logs
3.1 下载Kafka 1.0.0版本
[root@localhost /]# cd /usr/local/kafka [root@localhost kafka]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/1.0.0/kafka_2.12-1.0.0.tgz
3.2 解压
[root@localhost kafka]# tar -zxvf kafka_2.12-1.0.0.tgz
4. 配置并启动Kafka
4.1 进入到config目录
[root@localhost kafka]# cd /usr/local/kafka/kafka_2.12-1.0.0/config
4.2 备份并修改server.properties
[root@localhost config]# cp server.properties server.properties.bak [root@localhost config]# vim server.properties
修改标红的三行,
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.# see kafka.server.KafkaConfig for additional details and defaults
############################# Server Basics #############################
# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0############################# Socket Server Settings #############################
# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured. # FORMAT: # listeners = listener_name://host_name:port # EXAMPLE: # listeners = PLAINTEXT://your.host.name:9092 #listeners=PLAINTEXT://:9092port=9092
#这是你本机的ip地址 host.name=172.17.44.141
# returned from java.net.InetAddress.getCanonicalHostName(). #advertised.listeners=PLAINTEXT://your.host.name:9092 num.network.threads=3# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400 socket.request.max.bytes=104857600 ############################# Log Basics ############################## A comma seperated list of directories under which to store log files
log.dirs=/usr/local/kafka/kafka-logs# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across # the brokers. num.partitions=1....
4.3 配置Kafka环境变量
[root@localhost config]# vim /etc/profile
在文本末最后一行添加如下代码:
export KAFKA_HOME=/usr/local/kafka/kafka_2.12-1.0.0
export PATH=$KAFKA_HOME/bin:$PATH
保存退出。
4.4 使配置立即生效
[root@localhost config]# source /etc/profile
5. 启动Kafka并验证
5.1 启动zookeeper服务
[root@localhost config]# /usr/local/zookeeper/zookeeper-3.4.11/bin/zkServer.sh start
5.2 进入到kafka的bin目录
[root@localhost config]# cd /usr/local/kafka/kafka_2.12-1.0.0
5.3 启动kafka
[root@localhost kafka_2.12-1.0.0]# bin/kafka-server-start.sh config/server.properties &
5.4 验证
[root@localhost kafka_2.12-1.0.0]# jps 3584 Jps 3299 QuorumPeerMainl 3519 Kafka
5.5 关闭kafka命令
[root@localhost kafka_2.12-1.0.0]# bin/kafka-server-stop.sh
6. 报错及解决
启动kafka报错
[root@localhost kafka_2.12-1.0.0]# bin/kafka-server-start.sh config/server.properties & Exception in thread "main" java.lang.UnsupportedClassVersionError: kafka/Kafka : Unsupported major.minor version 52.0
解决:请查看kafka对应的jdk版本,此次选用JDK版本为1.8
7. 说明
说明:本次使用
操作系统:CentOS 6.8 64位
Kafka版本:1.0.0
JDK版本:1.8.0_144
注:如遇到下载链接失效,可以尝试访问: