1、下载kafka安装包
wget http://mirrors.cnnic.cn/apache/kafka/0.8.2.1/kafka_2.11-0.8.2.1.tgz
2、复制到安装目录
cp kafka_2.11-0.8.2.1.tgz /usr/local/
3、解压
cd /usr/local/
tar -zxvf kafka_2.11-0.8.2.1.tgz
4、修改配置
cd kafka_2.11-0.8.2.1
cd config
vi server.properties
进行host配置,如需被其它主机调用可配置IP
host.name=localhost
6、启动
#启动zookeeper
/usr/local/kafka_2.11-0.8.2.1/bin/zookeeper-server-start.sh /usr/local/kafka_2.11-0.8.2.1/config/zookeeper.properties > /var/tmp/zk-server-start.log &
#启动kafka
/usr/local/kafka_2.11-0.8.2.1/bin/kafka-server-start.sh /usr/local/kafka_2.11-0.8.2.1/config/server.properties > /var/tmp/kafka-server-start.log &
7、测试
#producer
/usr/local/kafka_2.11-0.8.2.1/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
#consumer
/usr/local/kafka_2.11-0.8.2.1/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
在 producer 输入: message
在 consumer 显示: message
表示已安装启动成功
#创建topic test2
/usr/local/kafka_2.11-0.8.2.1/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test2
#列出当前的所有topic
/usr/local/kafka_2.11-0.8.2.1/bin/kafka-topics.sh --list --zookeeper localhost:2181