centos安装配置kafka

预装环境:

jdk1.8
zookeeper


curl -O http://tar.matosiki.site/tar/kafka_2.11-2.0.0.tgz

tar -zxvf kafka_2.11-2.0.0.tgz -C /opt/

cd /opt/kafka_2.11-2.0.0/

# 修改配置
vim /opt/kafka_2.11-2.0.0/config/server.properties
#每台服务器的broker.id都不能相同
broker.id=101
host.name=192.168.126.100
#监听地址 不能输入0.0.0.0
listeners=PLAINTEXT://192.168.126.100:9092
#在log.retention.hours=168 下追加
advertised.listeners=PLAINTEXT://192.168.126.100:9092

message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880

#设置zookeeper的连接端口
zookeeper.connect=192.168.126.100:2181,192.168.126.101:2181
zookeeper.connection.timeout.ms=1000000
kafka.metrics.polling.interval.secs=5
kafka.metrics.reporters=kafka.metrics.KafkaCSVMetricsReporter
kafka.csv.metrics.dir=/tmp/kafka_metrics
kafka.csv.metrics.reporter.enabled=false

测试环境将内存改小

vim /opt/kafka_2.11-2.0.0/bin/kafka-server-start.sh 
# 1G改成512m
export KAFKA_HEAP_OPTS="-Xmx512m -Xms512m"
# 启动

/opt/kafka_2.11-2.0.0/bin/kafka-server-start.sh -daemon /opt/kafka_2.11-2.0.0/config/server.properties
# 验证启动
jps

# 开启防火墙
firewall-cmd --zone=public --add-port=9092/tcp --permanent
firewall-cmd --reload
#常用命令
#创建topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic MyTopic

#查看topic
bin/kafka-topics.sh --list --zookeeper localhost:2181

# producer生产消息
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic MyTopic

# consumer 消费消息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic MyTopic --from-beginning
本文总阅读量