centos7安装kafka_2.11
1、下载
官网地址:http://kafka.apache.org/downloads.html
下载:
wget https://www.apache.org/dyn/closer.cgi?path=/kafka/2.2.0/kafka_2.11-2.2.0.tgz
2、解压及目录介绍
tar -xzvf kafka_2.11-2.2.0.tgz
3、配置
- zookeeper配置
只要配置这两个参数就好了
- kafka配置
配置kafka的全局路径
vim /etc/profile
#KAFKA_HOME
export KAFKA_HOME=/usr/local/src/kafka_2.11-2.1.0
export PATH=$PATH:$KAFKA_HOME/bin
vim config/server-1.properties
broker.id=1
listeners=PLAINTEXT://192.168.**.***:9092
log.dirs=/usr/local/src/kafka_2.11-2.1.0/tmp/kafka-logs1
zookeeper.connect=192.168.**.***:2182
vim config/server-2.properties
broker.id=2
listeners=PLAINTEXT://192.168.**.***:9093
log.dirs=/usr/local/src/kafka_2.11-2.1.0/tmp/kafka-logs2
zookeeper.connect=192.168.**.***:2182vim config/server-3.properties
broker.id=3
listeners=PLAINTEXT://192.168.**.***:9094
log.dirs=/usr/local/src/kafka_2.11-2.1.0/tmp/kafka-logs3
zookeeper.connect=192.168.**.***:2182
4、启动zookeeper
zookeeper后台启动:
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties &
5、后台启动kafka
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-1.properties & kafka-server-start.sh -daemon $KAFKA_HOME/config/server-2.properties &
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-3.properties &
6、创建topic
创建topic,包含一个分区,3个副本
bin/kafka-topics.sh --create --zookeeper 192.168.**.***:2181 --replication-factor 3 --partitions 1 --topic my_topic
查看topic
bin/kafka-topics.sh --list --zookeeper 192.168.**.***:2181
7、创建生产者和消费者
创建生产者 bin/kafka-console-producer.sh --broker-list master:9092,master:9093,master:9094 --topic my_topic 创建消费者 /bin/kafka-console-consumer.sh --bootstrap-server master:9092,master:9093,master:9094 --from-beginning --topic my_topic
注: