Bitnami Kafka Virtual Machine

Description

Apache Kafka is publish-subscribe messaging rethought as a distributed commit log.

First steps with the Bitnami Kafka Stack

Welcome to your new Bitnami application! This guide includes some basic information you will need to get started with your application.

How to import a Bitnami Virtual Machine?

Check the following instructions to import a Bitnami Virtual Machine:

Importing a Bitnami Virtual Machine in VirtualBox
  • Select the "File -> Import Appliance" menu option and select the .ova file downloaded from the Bitnami website. Then click "Continue".
  • Once it is imported, click the "Start" button in the VirtualBox toolbar.

For a detailed walkthrough, check our Virtualbox tutorial.

Importing a Bitnami Virtual Machine in a VMware product
  • Select the "File -> Import" menu option and select the .ova file downloaded from the Bitnami website. Then click "Continue".
  • Once the import is complete, click "Finish" to start the virtual machine.

For a detailed walkthrough, check our VMware tutorial, which uses VMware Fusion as an example. To learn how to use our virtual machines with other VMware products, refer to the VMware Workstation documentation or the VMware vSphere documentation.

What credentials do I need?

You need two sets of credentials:

  • The application credentials, consisting of a username and password. These credentials allow you to log in to your new Bitnami application.
  • The server credentials, consisting of an SSH username and password. These credentials allow you to log in to your virtual machine using an SSH client and execute commands at the virtual machine console using the command line.

What is the administrator username set for me to log in to the application for the first time?

Username: user

What is the administrator password?

Password: The administrator password to log in to your application is randomly generated during the first boot. Check the FAQ to learn how to retrieve it.

What SSH username should I use for secure shell access to my application?

SSH username: bitnami

What is my server IP address?

The IP address is displayed on screen at the end of the boot process, but you can check it at any time by running the following command:

  $ sudo ifconfig

Check server IP address

How do I get my SSH key or password?

You can obtain the SSH password from the virtual machine console when it starts up. Click here for more information.

How to start or stop the services?

Each Bitnami stack includes a control script that lets you easily stop, start and restart services. The script is located at /opt/bitnami/ctlscript.sh. Call it without any service name arguments to start all services:

$ sudo /opt/bitnami/ctlscript.sh start

Or use it to restart a single service, such as Apache only, by passing the service name as argument:

$ sudo /opt/bitnami/ctlscript.sh restart apache

Use this script to stop all services:

$ sudo /opt/bitnami/ctlscript.sh stop

Restart the services by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh restart

Obtain a list of available services and operations by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh

What is the default configuration?

Kafka default configuration

Kafka configuration files

The Kafka configuration files are located at the /opt/bitnami/kafka/config/ directory.

Kafka ports

The Kafka server has a single broker running on port 9092. Only conections from localhost are permitted.

Kafka log files

The Kafka log files are created at the /opt/bitnami/kafka/logs/ directory.

Zookeeper default configuration

Zookeeper configuration files

The Zookeeper configuration files are located at the /opt/bitnami/zookeeper/conf/ directory.

Zookeeper ports

By default, the Zookeeper server runs on port 2181. Only conections from localhost are permitted.

What are the default ports?

A port is an endpoint of communication in an operating system that identifies a specific process or a type of service. Bitnami stacks include several services or servers that require a port.

IMPORTANT: Making this application's network ports public is a significant security risk. You are strongly advised to only allow access to those ports from trusted networks. If, for development purposes, you need to access from outside of a trusted network, please do not allow access to those ports via a public IP address. Instead, use a secure channel such as a VPN or an SSH tunnel. Follow these instructions to remotely connect safely and reliably.

Port 22 is the default port for SSH connections.

The Kafka access port is 9092. This port is closed by default. You must open it to enable remote access.

How to connect to Kafka from a different machine?

For security reasons, the Kafka ports in this solution cannot be accessed over a public IP address. To connect to Kafka and Zookeeper from a different machine, you must open ports 9092 and 2181 for remote access. Refer to the FAQ for more information on this.

IMPORTANT: Making this application's network ports public is a significant security risk. You are strongly advised to only allow access to those ports from trusted networks. If, for development purposes, you need to access from outside of a trusted network, please do not allow access to those ports via a public IP address. Instead, use a secure channel such as a VPN or an SSH tunnel. Follow these instructions to remotely connect safely and reliably.

Once you have added the firewall rule and opened the ports, perform these additional steps:

  • Edit your Zookeeper configuration file (/opt/bitnami/zookeeper/conf/zoo.cfg) and comment out the following line:

      clientPortAddress=localhost
    
  • Edit your Kafka configuration file (/opt/bitnami/kafka/config/server.properties). If necessary, uncomment the following line and change the value of the parameter to the public IP address of the server:

      #advertised.host.name=<hostname routable by clients>
    
  • Restart the server to reload the configuration files.

      $ sudo /opt/bitnami/ctlscript.sh restart
    

How to access your application?

Kafka doesn't include a web client or a user interface. Instead, you can connect to your server through SSH or install a third party UI tool for Kafka such Kafka Tool.

How to create a Kafka multi-broker cluster?

This section describes the creation of a multi-broker Kafka cluster with brokers located on different hosts. In this scenario:

  • One server hosts the Zookeeper server and a Kafka broker
  • The second server hosts a a second Kafka broker
  • The third server hosts a producer and a consumer

Kafka cluster

NOTE: Before beginning, ensure that ports 2181 (Zookeeper) and 9092 (Kafka) are open on the first server and port 9092 (Kafka) is open on the second server. Also ensure that remote connections are possible between the three servers (instructions).

Configuring the first server (Zookeeper manager and Kafka broker)

The default configuration may be used as is. However, you must perform the steps below:

  • Delete the contents of the Zookeeper and Kafka temporary directories

     $ sudo rm -rf /opt/bitnami/kafka/tmp/kafka-logs
     $ sudo rm -rf /opt/bitnami/zookeeper/tmp/zookeeper
    
  • Restart the Kafka and Zookeeper services.

     $ sudo /opt/bitnami/ctlscript.sh restart kafka
     $ sudo /opt/bitnami/ctlscript.sh restart zookeeper
    

Configuring the second server (Kafka broker)

  • Edit the /opt/bitnami/kafka/config/server.properties configuration file and update the broker.id parameter.

     broker.id = 1
    

    This broker id must be unique in the Kafka ecosystem.

  • In the same file, update the zookeeper.connect parameter to reflect the public IP address of the first server.

     zookeeper.connect=PUBLIC_IP_ADDRESS_OF_ZOOKEEPER_MANAGER:2181
    
  • Delete the contents of the Zookeeper and Kafka temporary directories

     $ sudo rm -rf /opt/bitnami/kafka/tmp/kafka-logs
     $ sudo rm -rf /opt/bitnami/zookeeper/tmp/zookeeper
    
  • Stop the Zookeeper service.

     $ sudo /opt/bitnami/ctlscript.sh stop zookeeper
    
  • Restart the Kafka service.

     $ sudo /opt/bitnami/ctlscript.sh restart kafka
    

Configuring the third server (Kafka message producer/consumer)

  • Edit the /opt/bitnami/kafka/config/producer.properties file and update the metadata.broker.list parameter with the public IP addresses of the two brokers:

     metadata.broker.list=PUBLIC_IP_ADDRESS_OF_FIRST_KAFKA_BROKER:9092, PUBLIC_IP_ADDRESS_OF_SECOND_KAFKA_BROKER:9092
    
  • Edit the /opt/bitnami/kafka/config/consumer.properties file and update the zookeeper.connect parameter to reflect the public IP address of the first server.

     zookeeper.connect=PUBLIC_IP_ADDRESS_OF_ZOOKEEPER_MANAGER:2181
    
  • Since this host only serves as a producer and a consumer, stop the Kafka and Zookeeper services:

     $ sudo /opt/bitnami/ctlscript.sh stop kafka
     $ sudo /opt/bitnami/ctlscript.sh stop zookeeper
    

Testing the cluster

NOTE: The following commands should be executed on the third server (Kafka message producer/consumer).
  • Create a new topic.

     $ /opt/bitnami/kafka/bin/kafka-topics.sh --create --zookeeper PUBLIC_IP_ADDRESS_OF_FIRST_KAFKA_BROKER:2181 --replication-factor 2 --partitions 1 --topic multiBroker
    
  • Produce some messages by running the command below and then entering some messages, each on a separate line. Enter Ctrl-C to end.

     $ /opt/bitnami/kafka/bin/kafka-console-producer.sh --broker-list PUBLIC_IP_ADDRESS_OF_FIRST_KAFKA_BROKER:9092 --topic multiBroker
     this is a message
     this is another message
     ^C
    
  • Consume the messages. The consumer will connect to the cluster and retrieve and display the messages you entered in the previous step.

     $ /opt/bitnami/kafka/bin/kafka-console-consumer.sh --zookeeper PUBLIC_IP_ADDRESS_OF_FIRST_KAFKA_BROKER:2181 --topic multiBroker --from-beginning
     this is a message
     this is another message
     ^C
    

How can I run a command in the Bitnami Kafka Stack?

Log in to the server console as the bitnami user and run the command as usual. The required environment is automatically loaded for the bitnami user.

How to run a Kafka producer and consumer from the server itself?

You can run the following example to publish and collect your first message:

  • Declare a new topic. The Kafka server is configured to use the server's public IP address:

     $ /opt/bitnami/kafka/bin/kafka-topics.sh --create --zookeeper 127.0.0.1:2181 --replication-factor 1 --partitions 1 --topic test
    

    We use --replication-factor to indicate how many servers are going to have a copy of the logs, and --partitions to choose the number of partitions for the topic we are creating.

  • Start a new producer on the same Kafka server and generates a message in the topic. Remember to replace SERVER-IP with your server's public IP address. Enter CTRL-D to end the message.

     $ /opt/bitnami/kafka/bin/kafka-console-producer.sh --broker-list SERVER-IP:9092 --topic test
    
     this is my first message 
    
  • Collect and display the first message in the consumer:

     $ /opt/bitnami/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
    

How to start/stop the Kafka server?

To start the Kafka server, access your machine and execute the following:

$ sudo /opt/bitnami/ctlscript.sh start kafka

To stop the Kafka server, execute the following:

$ sudo /opt/bitnami/ctlscript.sh stop kafka

Remember that the Zookeeper server must be running in order for Kafka to work properly.

How to start/stop the Zookeeper server?

To start the Zookeeper server, access your machine and execute the following:

$ sudo /opt/bitnami/ctlscript.sh start zookeeper

To stop the Zookeeper server, execute the following:

$ sudo /opt/bitnami/ctlscript.sh start zookeeper

How to create a full backup of Kafka?

Backup

The Bitnami Kafka Stack is self-contained and the simplest option for performing a backup is to copy or compress the Bitnami stack installation directory. To do so in a safe manner, you will need to stop all servers, so this method may not be appropriate if you have people accessing the application continuously.

Follow these steps:

  • Change to the directory in which you wish to save your backup:

      $ cd /your/directory
    
  • Stop all servers:

      $ sudo /opt/bitnami/ctlscript.sh stop
    
  • Create a compressed file with the stack contents:

      $ sudo tar -pczvf application-backup.tar.gz /opt/bitnami
    
  • Restart all servers:

      $ sudo /opt/bitnami/ctlscript.sh start
    

You should now download or transfer the application-backup.tar.gz file to a safe location.

Restore

Follow these steps:

  • Change to the directory containing your backup:

      $ cd /your/directory
    
  • Stop all servers:

      $ sudo /opt/bitnami/ctlscript.sh stop
    
  • Move the current stack to a different location:

      $ sudo mv /opt/bitnami /tmp/bitnami-backup
    
  • Uncompress the backup file to the original directoryv

      $ sudo tar -pxzvf application-backup.tar.gz -C /
    
  • Start all servers:

      $ sudo /opt/bitnami/ctlscript.sh start
    

If you want to create only a database backup, refer to these instructions for MySQL and PostgreSQL.

How to debug Kafka and Zookeeper errors?

The main Kafka log file is created at /opt/bitnami/kafka/logs/server.log.

The main Zookeeper log file is created at /opt/bitnami/zookeeper/tmp/zookeeper.out.

virtualMachine

Bitnami Documentation