Confluent/Kafka

来自Gea-Suan Lin's Wiki
跳到导航 跳到搜索

Confluent/Kafka指的是Confluent所包装的Apache Kafka,里面有些路径与设定档的设法与官方版本不同。

防火墙

Kafka的主机对外需要开这些Port:

  • 9092/tcp
  • 32181/tcp(JMX)

设定

server.properties

修改/etc/kafka/server.propertiesbroker.id设定,让他自动产生而不需要自己指定:

#broker.id=0
broker.id.generation.enable=true

修改listeners设定,虽然预设值会听正确的界面,但因为这个资讯会被注册到ZooKeeper里面,所以需要注册正确的界面资讯:

#listeners=PLAINTEXT://:9092
listeners=PLAINTEXT://10.1.1.1:9092

如果ZooKeeperKafka不同服务器,需要修改/etc/kafka/server.propertieszookeeper.connect的值,像是这样:

#zookeeper.connect=localhost:2181
zookeeper.connect=internal-test-kafka-zookeeper-123456789.us-east-1.elb.amazonaws.com:2181

在正式环境上可以设定对应的Replication数量,避免当单一机器有问题的时候产生错误:

offsets.topic.replication.factor=3
transaction.state.log.replication.factor=3
transaction.state.log.min.isr=2

其他

另外可以设定/lib/systemd/system/confluent-kafka.service.d/30-options.conf(目录可能会需要自己建立),让Kafka吃满内存(这边假设是8 GB的内存,保留1 GB给系统与其他情境使用),以及开启JMX监控机制,跑在Port 32181:

[Service]
Environment=JMX_PORT=32181
Environment=KAFKA_HEAP_OPTS="-Xmx7g -Xms7g"
Environment=KAFKA_JMX_OPTS="-Djava.rmi.server.hostname=${hostip} -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.rmi.port=32181 -Dcom.sun.management.jmxremote.port=32181 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

对应的指令:

sudo mkdir /lib/systemd/system/confluent-kafka.service.d/
echo -e '[Service]\nEnvironment=JMX_PORT=32181\nEnvironment=KAFKA_HEAP_OPTS="-Xmx7g -Xms7g"\nEnvironment=KAFKA_JMX_OPTS="-Djava.rmi.server.hostname=${hostip} -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.rmi.port=32181 -Dcom.sun.management.jmxremote.port=32181 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"' | sudo tee /lib/systemd/system/confluent-kafka.service.d/30-options.conf

设完后就可以让systemd重读设定后启动:

sudo systemctl daemon-reload
sudo systemctl enable confluent-kafka
sudo service confluent-kafka start
sudo service confluent-kafka status

然后就可以设定前端的load balancer了。

相关连结

外部链接