kafka下载地址
http://kafka.apache.org/downloads.html
在这里下载kafka_2.11-0.10.0.0.tgz,kafka和zookeeper都用同一个包里的
安装和配置jdk(略过)
JAVA_HOME=/opt/jdk1.8.0_131 CLASSPATH=.:$JAVA_HOME/lib.tools.jar PATH=$JAVA_HOME/bin:$PATH export JAVA_HOME CLASSPATH PATH $ java -version java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) Server VM (build 25.131-b11, mixed mode)
解压后kafka_2.11-0.10.0.0.tgz,
先配置zookeeper
$cd kafka_2.11-0.10.0.0 $vi config/zookeeper.properties dataDir=/data/programs/kafka_2.11-0.10.0.0/data dataLogDir=/data/programs/kafka_2.11-0.10.0.0/logs clientPort=2181 maxClientCnxns=100 tickTime=2000 initLimit=10 配置后直接启动zookeeper $bin/zookeeper-server-start.sh config/zookeeper.properties 如果没有报错,可以转后台启动 $nohup bin/zookeeper-server-start.sh config/zookeeper.properties &
再配置kafka
$ vi config/server.properties broker.id=0 port=9092 host.name=192.168.12.105 num.network.threads=3 num.io.threads=8 socket.send.buffer.bytes=102400 socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 log.dirs=/data/logs/kafka num.partitions=2 num.recovery.threads.per.data.dir=1 log.retention.check.interval.ms=300000 zookeeper.connect=localhost:2181 zookeeper.connection.timeout.ms=6000 启动kafka $ bin/kafka-server-start.sh config/server.properties 如果没有报错,可以转后台启动 $nohup bin/kafka-server-start.sh config/server.properties &
测试kafka
1、创建topic $bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test 2、查看创建的topic $ bin/kafka-topics.sh -list -zookeeper localhost:2181 test 3、生产消息测试 $bin/kafka-console-producer.sh --broker-list 192.168.12.105:9092 --topic test this is test #输入后回车 4、消费消息测试 $bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning this is test
完成以上代表kafka单包机安装成功。
时间: 2024-10-10 10:30:40