CentOS安装Kafka
1.安装jdk1.8和Zookeeper3.4.8,参考上一篇文章https://www.cnblogs.com/dreamer-fish/p/15715369.html
2.安装kafka_2.11-0.10.1.1
参考:https://www.cnblogs.com/panwenbin-logs/p/10369402.html
https://www.cnblogs.com/happydreamzjl/p/12206997.html
tar -zxvf kafka_2.11-0.10.1.1.tgz -C /usr/local
mv /usr/local/kafka_2.11-0.10.1.1 /usr/local/kafka
vim /etc/hosts添加群集各节点解析
vim /usr/local/kafka/config/server.properties,内容如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
broker.id=0 listeners=PLAINTEXT://:9092 port=9092 host.name=kafka01 advertised.host.name=kafka01 num.network.threads=3 num.io.threads=8 socket.send.buffer.bytes=102400 socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 log.dirs=/data1/kafka/logs/kafka num.partitions=1 num.recovery.threads.per.data.dir=1 offsets.topic.replication.factor=2 log.retention.hours=168 log.segment.bytes=1073741824 log.retention.check.interval.ms=300000 zookeeper.connect=10.10.21.77:2181,10.10.21.85:2181,10.10.21.86:2181 zookeeper.connection.timeout.ms=6000
启动kafka服务:
/usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties #-daemon表示后台启动
Jps -m #验证服务是否正常启动
kafka设置开机自启动:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#!/bin/bash #chkconfig:2345 60 20 #description:kafka export JAVA_HOME=/usr/local/java KAFKA_HOME=/usr/local/kafka case $1 in start) su root -c "${KAFKA_HOME}/bin/kafka-server-start.sh -daemon ${KAFKA_HOME}/config/server.properties";; stop) su root ${KAFKA_HOME}/bin/kafka-server-stop.sh;; *) echo "require start|stop" ;; esac
chmod a+x kafka
chkconfig --add kafka
service kafka start|stop
#进入Zookeeper查看kafka进程
/usr/local/zookeeper/bin/zkCli.sh
get /brokers/ids/0 #0、1、2为kafka配置文件中对应的的brokeer id,返回如下: