How to connect to Kafka from a Windows remote machine
Run the clients using Kerberos (SASL_PLAINTEXT)
To run the clients using Kerberos (SASL_PLAINTEXT), first ensure that Kerberos is configured properly in the environment. Once you get valid tickets, do the following to connect with the Kafka clients:
- If using Kafka Ranger plugin, go to Ranger Admin UI -> Kafka and add a new policy for the user that is used to connect from Windows host pointing to the topic/s that needs access.
- After the Ranger policies are configured, then go to the Windows Host and configure the Kerberos details for the Kafka client connection. To achieve this, do the following:
- Create a file with extension .conf and add the following content:
KafkaClient {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
useTicketCache=false
serviceName="kafka";
keyTab="/path_to_file/file.keytab"
principal="principal_name@REALM.COM";
};
Client {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
keyTab="/path_to_file/file.keytab"
storeKey=true
useTicketCache=false
serviceName="zookeeper"
principal="principal_name@REALM.COM";
};- client: is used to connecting to the Zookeeper and KafkaClient is to connect to the Kafka Brokers.
- principal: is the user that will be used to connect from Windows to the Kafka Brokers (the same user that we add grants in Ranger UI)
- keyTab: is the keytab file that contains the principal specified in "principal".
- With that file created, open a Windows Command Prompt and execute the following command before running any command line:
set KAFKA_OPTS="-Djava.security.auth.login.config=/path_to_conf_file/file.conf"
That command will pass the keytab/principal to the Kafka client. - In the same command prompt, run a Kafka Producer/Consumer using the following commands for Kafka versions <= 1.0:
C:\<preferred location>\kafka_<version>\bin\windows\bin\kafka-console-producer.bat --broker-list <brokerHost>:<brokerPort> --topic <topicName> --security-protocol SASL_PLAINTEXT
For the consumer, use the following command line:C:\<preferred location>\kafka_<version>\bin\windows\bin\kafka-console-consumer.bat --bootstrap-server <brokerHost>:<brokerPort> --topic <topicName> --from-beginning --security-protocol SASL_PLAINTEXT
For Kafka versions > 1.0, use the following producer/consumer command line:C:\<preferred location>\kafka_<version>\bin\windows\bin\kafka-console-producer.bat --broker-list <brokerHost>:<brokerPort> --topic <topicName> --producer-property security.protocol=SASL_PLAINTEXT
For Kafka consumer > 1.0, use the following command lineC:\<preferred location>\kafka_<version>\bin\windows\bin\kafka-console-consumer.bat --bootstrap-server <brokerHost>:<brokerPort> --topic <topicName> --from-beginning
--consumer-property security.protocol=SASL_PLAINTEXT
- Create a file with extension .conf and add the following content:

