安装并启动Kafkaapache
1.下载最新版Kafka(当前为kafka_2.12-2.3.0)并解压:bash
> wget http://mirror.bit.edu.cn/apache/kafka/2.3.0/kafka_2.12-2.3.0.tgzoop
> tar zxvf kafka_2.12-2.3.0.tgzthis
2. 检查Java 环境是否正确:日志
> cd kafka_2.12-2.3.0server
> bin/kafka-topics.shblog
如果没法成功执行,则检查 Java 环境是否正确配置(此例中使用Java 8)ip
3. 将kafka执行脚本目录加入环境变量:hadoop
> vi ~/.bash_profileget
> export PATH="$PATH:/home/hadoop/kafka_2.12-2.3.0/bin"
4. 启动Zookeeper
> zookeeper-server-start.sh config/zookeeper.properties
查看 config/zookeeper.properties 文件,能够看到基本配置:
# the directory where the snapshot is stored.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
其中须要将dataDir修改成非/tmp 目录,以将数据持久化,例如:
dataDir=/home/hadoop/kafka_2.12-2.3.0/data/zookeeper
而后重启zookeeper:
> zookeeper-server-start.sh config/zookeeper.properties
以后能够在dataDir目录下查看到zookeeper数据目录:
> pwd
/home/hadoop/kafka_2.12-2.3.0/data/zookeeper/version-2
5. 启动Kafka
首先修改 conf/server.properties 文件,能够看到日志文件地址为:
# A comma separated list of directories under which to store log files
log.dirs=/tmp/kafka-logs
修改此路径为非/tmp目录,以落盘log数据,例如:
log.dirs=/home/hadoop/kafka_2.12-2.3.0/data/kafka-logs
而后启动Kafka:
> kafka-server-start.sh config/server.properties
查看 data/kafka-logs,能够看到如下文件:
> ls
cleaner-offset-checkpoint meta.properties replication-offset-checkpoint
log-start-offset-checkpoint recovery-point-offset-checkpoint