# su - kafka<\/pre>\nwget https:\/\/www-us.apache.org\/dist\/kafka\/2.2.0\/kafka_2.12-2.2.0.tgz -O kafka.tgz<\/pre>\nNow that the Apache Kafka binary has been downloaded, now we need to extract it in our Kafka user directory<\/p>\n
$ tar -xzvf kafka.tgz --stripe 1<\/pre>\n<\/span>Step 5: Configure Apache Kafka<\/span><\/h2>\nIt is time to configure Apache Kafka. By default, we are not allowed to delete topics, categories or groups in which messages can be posted. To change this behavior, we need to edit the default configuration.<\/p>\n
$ nano ~\/config\/server.properties<\/pre>\nAppend the following line to the last line of the configuration file.<\/p>\n
delete.topic.enable = true<\/p>\n
<\/span>Step 6: Create a System Unit File for Apache Kafka<\/span><\/h2>\nZookeeper is required for running Kafka. Kafka uses zookeeper, so we’ll need to first start an instance of the Zookeeper server prior to starting the Apache Kafka service. In this tutorial, we will use the convenience script packaged with Kafka to get a quick-and-dirty single-node Zookeeper instance.<\/p>\n
Open a new file at the filepath \/etc\/systemd\/system\/zookeeper.service<\/code>, and open it in your preferred text editor. We’ll be using nano<\/code> for this tutorial.<\/p>\n$ sudo nano \/etc\/systemd\/system\/zookeeper.service<\/pre>\nPaste the following lines into it:<\/p>\n
[Unit]\r\nRequires=network.target remote-fs.target\r\nAfter=network.target remote-fs.target\r\n[Service]\r\nType=simple\r\nUser=kafka\r\nExecStart=\/home\/kafka\/bin\/zookeeper-server-start.sh \/home\/kafka\/config\/zookeeper.properties\r\nExecStop=\/home\/kafka\/bin\/zookeeper-server-stop.sh\r\nRestart=on-abnormal\r\n[Install]\r\nWantedBy=multi-user.target\r\n<\/pre>\nNow, let’s create a system unit file for kafka at the filepath \/etc\/systemd\/system\/kafka.service<\/code>:<\/p>\n$ sudo nano \/etc\/systemd\/system\/kafka.service<\/pre>\nPaste the following lines into the file:<\/p>\n
[Unit]\r\nRequires=zookeeper.service\r\nAfter=zookeeper.service\r\n[Service]\r\nType=simple\r\nUser=kafka\r\nExecStart=\/bin\/sh -c '\/home\/kafka\/bin\/kafka-server-start.sh \/home\/kafka\/config\/server.properties > \/home\/kafka\/kafka.log 2>&1'\r\nExecStop=\/home\/kafka\/bin\/kafka-server-stop.sh\r\nRestart=on-abnormal\r\n[Install]\r\nWantedBy=multi-user.target\r\n<\/pre>\nThe new system units have been added, so let’s enable Apache Kafka to automatically run on boot, and then run the service.<\/p>\n
$ sudo systemctl enable kafka\r\n$ sudo systemctl start kafka<\/pre>\n