Mistakes to Avoid when Connecting to Kafka on VirtualBox

I installed Apache Kafka on CentOS7 using VirtualBox and it worked fine on the virtual machine. However, when I used Java APIs on Windows to connect to Kafka on VirtualBox, I ran into some problems. Here are some tips to avoid connection errors.

1. Firewall Problem

Kafka listens on TCP port 9092 by default. Make sure that you open port 9092 on your VM for remote access. You can either disable/stop the firewall on your CentOS7 system or just expose port 9092.

# Check firewall status
firewall-cmd --state
# Stop firewall
systemctl stop firewalld.service
# Disable firewall on system startup
systemctl disable firewalld.service

2. Virtualbox Network Settings

You have to configure the network between guest VM and host in VirtualBox to connect to Kafka server. Hit the settings button, choose network and select 'Bridged Adapter' or 'Host-only Adapter' mode.

By selecting Bridged Adapter, your guest operating system will work on the same network as does your host. In host-only networking, a network completely contained within the host computer is created.

Check your VM IP address by typing ifconfig in shell.

Then we have to modify the config/server.properties file to configure Kafka listeners and advertised.listeners. Remember to stop and restart Kafka after the modification.

Finally, we can connect to Kafka on CentOS7 using Java APIs.

Properties properties = new Properties();      
AdminClient  adminClient = AdminClient.create(properties);


VirtualBox network configuration

Manage your firewall on CentOS7

Connecting to Kafka on VirtualBox from Windows

  • By Yuechun Wang
  • Published 2020-12-27
  • The materials on this website may be freely copied and distributed for noncommercial personal use only so long as our copyright notice and website address is included.
  • Comments