kafka 下载: http://archive.apache.org/dist/kafka/0.11.0.0/kafka_2.11-0.11.0.0.tgz
zookeeper 下载、安装、配置
1、在 /kafkadir/test_do_v2/ 目录下,下载: https://archive.apache.org/dist/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz ,并解压到当前目录
2、mkdir -p /kafkadir/test_do_v2/svr_cfg/zookeeper/data
3、cd zookeeper-3.4.10/conf/
4、cp zoo_sample.cfg zoo.cfg
5、vim zoo.cfg
initLimit=10
syncLimit=5
dataDir=/kafkadir/test_do_v2/svr_cfg/zookeeper/data
clientPort=2181
6、vim /etc/profile
export ZOOKEEPER_HOME=/kafkadir/test_do_v2/svr_cfg/zookeeper/
export PATH=.:$ZOOKEEPER_HOME/bin:$JAVA_HOME/bin:$PATH
7、source /etc/profile
8、启动zookeeper服务
/kafkadir/test_do_v2/zookeeper-3.4.10/bin/zookeeper-3.4.10/bin/zkServer.sh start
kafaka
@ vim server.properties
broker.id=1
port=9092
host.name=localhost
log.dirs=/kafkadir/test_do_v2/svr_cfg/kafka/logs
zookeeper.connect=localhost:2181
listeners=PLAINTEXT://10.0.1.211:9092
如果需要远程访问则按照如下配置
advertised.listeners=PLAINTEXT://10.0.1.211:9092
host.name=0.0.0.0
@ vim zookeeper.properties
dataDir=/kafkadir/test_do_v2/svr_cfg/kafka/zookeeper/data
clientPort=2181
host.name=localhost
@ vim producer.properties
zookeeper.connect=localhost:2181
@ vim consumer.properties
zookeeper.connect=localhost:2181
测试
创建topic
bin/kafka-topics.sh --create --topic test --replication-factor 1 --partitions 1 --zookeeper localhost:2181
查看topic内容
bin/kafka-topics.sh --describe --zookeeper localhost:2181, localhost:2181, localhost:2181 --topic test
查看所有topic
bin/kafka-topics.sh --list --zookeeper localhost:2181
删除(需要server.properties中设置delete.topic.enable=true否则只是标记删除或者直接重启)
bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic topicname
启动顺序:
cd /kafkadir/test_do_v2/kafka_2.11-0.11.0.0;./bin/zookeeper-server-start.sh config/zookeeper.properties
cd /kafkadir/test_do_v2/kafka_2.11-0.11.0.0;./bin/kafka-server-start.sh config/server.properties
其他的生产者和消费者就随意了
cd /kafkadir/test_do_v2/kafka_2.11-0.11.0.0;bin/kafka-console-producer.sh --broker-list 10.0.1.211:9092 --topic test
cd /kafkadir/test_do_v2/kafka_2.11-0.11.0.0; bin/kafka-console-consumer.sh --bootstrap-server 10.0.1.211:9092 --topic test --from-beginning