安装jdk略,zookeeper略
创建消息持久化目录
/mnt/hadoop/kafka/kafkaLogs
下载kafka
wget http://www-eu.apache.org/dist/kafka/0.10.2.1/kafka_2.11-0.10.2.1.tgz
tar –zxvf kafka_2.11-0.10.2.1.tgz –C /mnt/Hadoop
修改配置
config/
vi server.properties
broker.id=0 一个节点一个号,顺序排列
delete.topic.enable=true 设置true,否则只是标记删除
auto.create.topics.enable=false 关闭自动创建topic
listeners=PLAINTEXT://0.0.0.0:9092
advertised.listeners=PLAINTEXT://ip:9092 监听地址,kafka-0.9以后,舍弃advertised.host.name
log.dirs=/mnt/hadoop/kafka/kafkaLogs 消息持久化目录
zookeeper.connect=ip:2181 调zk集群
scp –r /mnt/hadoop/kafka root@ip:/mnt/ hadoop/
在其他节点上修改server.properties
broker.id=1 数字依次排序
listeners=PLAINTEXT://0.0.0.0:9093
advertised.listeners=PLAINTEXT://ip:9093
开启kafka 进程名为kafka,在每个节点下运行
nohup bin/kafka-server-start.sh -daemon config/server.properties &
停止kafka
bin/kafka-server-stop.sh
kafka常用操作命令:
查看当前服务器中的所有topic
bin/kafka-topics.sh --list --zookeeper bigdata1:2181
创建topic
./kafka-topics.sh --create --zookeeper bigdata1:2181 --replication-factor 1 --partitions 3 --topic first
删除topic
sh bin/kafka-topics.sh --delete --zookeeper bigdata1:2181 --topic test
需要server.properties中设置delete.topic.enable=true否则只是标记删除或者直接重启。
通过shell命令发送消息
kafka-console-producer.sh --broker-list bigdata1:9092 --topic itheima
通过shell消费消息
sh bin/kafka-console-consumer.sh --zookeeper bigdata1:2181 --from-beginning --topic test1
查看消费位置
sh kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper bigdata1:2181 --group testGroup
查看某个Topic的详情
sh kafka-topics.sh --topic test --describe --zookeeper bigdata1:2181
单节点下的多个broker:
创建消息持久化目录
kafkaLogs-1
kafkaLogs-2
在config下复制
cp server.properties server-1.properties
cp server.properties server-2.properties
server-1.properties:
listeners=PLAINTEXT://0.0.0.0:9093
advertised.listeners=PLAINTEXT://ip:9093
broker.id=0
log.dirs=/mnt/hadoop/kafka/kafkaLogs-1
server-2.properties:
listeners=PLAINTEXT://0.0.0.0:9094
advertised.listeners=PLAINTEXT://ip:9094
broker.id=1
log.dirs=/mnt/hadoop/kafka/kafkaLogs-2
JMX_PORT=9997 /mnt/hadoop/kafka/bin/kafka-server-start.sh -daemon /mnt/hadoop/kafka/config/server-1.properties &
JMX_PORT=9998 /mnt/hadoop/kafka/bin/kafka-server-start.sh -daemon /mnt/hadoop/kafka/config/server-2.properties &