1. 程式人生 > 實用技巧 >CentOS7 kafka安裝

CentOS7 kafka安裝

cd /opt
下載對應的kafka https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/
tar -xvf kafka_2.12-2.2.1.tgz -C /opt

修改對應的配置
#叢集內id從0開始,不能重複
sed -i 's$broker.id=0$broker.id=1$g' /opt/kafka_2.12-2.2.1/config/server.properties
#替換為當前節點ip
sed -i 's$#listeners=PLAINTEXT://:9092$listeners=PLAINTEXT://192.168.6.117:9092$g' /opt/kafka_2.12
-2.2.1/config/server.properties #設定副本數量為3(預設1) sed -i 's$num.partitions=1$num.partitions=3$g' /opt/kafka_2.12-2.2.1/config/server.properties #設定zk sed -i 's$zookeeper.connect=localhost:2181$zookeeper.connect=192.168.6.117:2181,192.168.6.118:2181,192.168.6.119:2181$g' /opt/kafka_2.12-2.2.1/config/server.properties #設定超時時間 sed
-i 's$zookeeper.connection.timeout.ms=6000$zookeeper.connection.timeout.ms=60000$g' /opt/kafka_2.12-2.2.1/config/server.properties #啟動kafka ./kafka-server-start.sh -daemon ../config/server.properties #增加kafka服務並設定為開機啟動 cat > /usr/lib/systemd/system/kafka.service <<"EOF" [Unit] Description=Kafka service After
=network.target zookeeper.service [Service] Type=simple PIDFile=/var/run/kafka.pid ExecStart=/opt/kafka_2.12-2.2.1/bin/kafka-server-start.sh ../config/server.properties ExecStop=/opt/kafka_2.12-2.2.1/bin/kafka-server-stop.sh [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable kafka #定期清理日誌 cat > /opt/kafka_2.12-2.2.1/bin/clean_kafka_logs.sh << "EOF" #!/bin/bash find /opt/kafka_2.12-2.2.1/logs/ -type f -mtime +7|xargs rm -rf EOF chmod +x /opt/kafka_2.12-2.2.1/bin/clean_kafka_logs.sh 執行crontab -e,加入一行 0 0 * * * /bin/bash /opt/kafka_2.12-2.2.1/bin/clean_kafka_logs.sh 調整已有topic副本數目 kafka-topics.sh --alter --zookeeper localhost:2181 --partitions 10 --topic mytopic