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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM