1. 程式人生 > >centos7安裝kafka_2.11

centos7安裝kafka_2.11

1.0 *** profile path tor partition pro oot .html

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、配置

  1. zookeeper配置
    只要配置這兩個參數就好了
    技術分享圖片
  2. 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.**.***:2182

    vim 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

註:

技術分享圖片

centos7安裝kafka_2.11