javaapache-kafkajaas

How to add JVM parameters to Apache Kafka?


When configuring authentication for kafka, the document mentioned that JVM parameters need to be added when starting kafka server. like:

-Djava.security.auth.login.config=/etc/kafka/kafka_server_jaas.conf

Since we are using bin/kafka-server-start.sh to start the server, the document didn't mention where to specify the JVM parameters.

Modifying the kafka-server-start.sh or kafka-server-class.sh is not a good idea, then what will be the right way to add the parameter at the start?


Solution

  • I'd recommend to use the KAFKA_OPTS environment variable for this.

    This environment variable is recognized by Kafka, and defaults to the empty string (= no settings). See the following code snippet from bin/kafka-run-class.sh in the Kafka source code:

    # Generic jvm settings you want to add
    if [ -z "$KAFKA_OPTS" ]; then
      KAFKA_OPTS=""
    fi
    

    So, for example, you can do:

    $ export KAFKA_OPTS="-Djava.security.auth.login.config=/etc/kafka/kafka_server_jaas.conf"
    $ bin/kafka-server-start.sh
    

    or

    $ KAFKA_OPTS="-Djava.security.auth.login.config=/etc/kafka/kafka_server_jaas.conf" bin/kafka-server-start.sh