Permission denied to run kafka server - apache-kafka

I am trying to run kafka on 3 machines as cluster, I have configured the Zookeeper on all the machines. Now I am trying to start the kafka server on 1 st machine using
bin/kafka-server-start.sh config/server.properties
It is giving error as
bin/kafka-server-start.sh: line 44: /tmp/kafka/kafka_2.11-1.1.0/bin/kafka-
run-class.sh: Permission denied
bin/kafka-server-start.sh: line 44: exec: /tmp/kafka/kafka_2.11-
1.1.0/bin/kafka-run-class.sh: cannot execute: Permission denied
Kafka installation is in the path /tmp/kafka/kafka_2.11-
1.1.0/ , and kafka logs are in the path /var/lib/kafka .
I have logged in as root user. Still I am getting these errors. I Checked the permission of the .sh files in the bin of kafka directory. All those have execute permission for all. Please help me to solve this error.
Below are the links used to configure zookeeper and kafka
http://armourbear.blogspot.com/2015/03/setting-up-multinode-kafka-
cluster.html
http://www.techburps.com/misc/multi-broker-apache-kafka-cluster-setup/64
Thanks in advance

It looks like filesystem permissions problem, make sure that the /tmp is not mounted with noexec option. Or just try to set up kafka in another directory.

Related

Unable to start kafka with zookeeper (kafka.common.InconsistentClusterIdException)

Below the steps I did to get this issue :
Launch ZooKeeper
Launch Kafka : .\bin\windows\kafka-server-start.bat .\config\server.properties
And at the second step the error happens :
ERROR Fatal error during KafkaServer startup. Prepare to shutdown
(kafka.server.KafkaServer)
kafka.common.InconsistentClusterIdException: The Cluster ID
Reu8ClK3TTywPiNLIQIm1w doesn't match stored clusterId
Some(BaPSk1bCSsKFxQQ4717R6Q) in meta.properties. The broker is trying
to join the wrong cluster. Configured zookeeper.connect may be wrong.
at kafka.server.KafkaServer.startup(KafkaServer.scala:220)
at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:44)
at kafka.Kafka$.main(Kafka.scala:84)
at kafka.Kafka.main(Kafka.scala)
When I trigger .\bin\windows\kafka-server-start.bat .\config\server.properties zookeeper console returns :
INFO [SyncThread:0:FileTxnLog#216] - Creating new log file: log.1
How to fix this issue to get kafka running ?
Edit You can access to the proper issue on the right site (serverfault) here
Edit Here is the Answer
I managed to Solve this issue with the following steps :
Just Delete all the log/Data file created (or generated) into
zookeeper and kafka.
Run Zookeper
Run Kafka
[Since this post is open again I post my answer there so you got all on the same post]
** 1. The easiest solution is to remove kafka logs and start again.
** 2. But the root cause is Kafka saved failed cluster ID in meta.properties.**
Try to delete kafka-logs/meta.properties from your tmp folder, which is located in C:/tmp folder by default on windows, and /tmp/kafka-logs on Linux
if kafka is running in docker containers, the log path may be specified by volume config in the docker-compose - see docs.docker.com/compose/compose-file/compose-file-v2/#volumes -- Chris Halcrow
** 3. How to find Kafka log path:**
Open server server.properties file which is located in your kafka folder kafka_2.11-2.4.0\config\server.properties (considering your version of kafka, folder name could be kafka_<kafka_version>):
Then search for entry log.dirs to check where logs locate
log.dirs=/tmp/kafka-logs
For mac, the following steps are needed.
Stop kafka service: brew services stop kafka
open kafka server.properties file: vim /usr/local/etc/kafka/server.properties
find value of log.dirs in this file. For me, it is /usr/local/var/lib/kafka-logs
delete path-to-log.dirs/meta.properties file
start kafka service brew services start kafka
No need to delete the log/data files on Kafka. Check the Kafka error logs and find the new cluster id. Update the meta.properties file with cluster-ID then restart the Kafka.
/home/kafka/logs/meta.properties
To resolve this issue permanently follow below.
Check your zookeeper.properties file and look for dataDirpath and change the path tmp location to any other location which should not be removed after server restart.
/home/kafka/kafka/config/zookeeper.properties
Copy the zookeeper folder and file to the new(below or non tmp) location then restart the zookeeper and Kafka.
cp -r /tmp/zookeeper /home/kafka/zookeeper
Now server restart won’t affect the Kafka startup.
If you use Embedded Kafka with Testcontainers in your Java project like myself, then simply delete your build/kafka folder and Bob's your uncle.
The mentioned meta.properties can be found under build/kafka/out/embedded-kafka.
I had some old volumes lingering around. I checked the volumes like this:
docker volume list
And pruned old volumes:
docker volume prune
And also removed the ones that were kafka:
example:
docker volume rm test_kafka
I deleted the following directories :-
a.) logs directory from kafka-server's configured location i.e. log.dir property path.
b.) tmp directory from kafka broker's location.
log.dirs=../tmp/kafka-logs-1
I was using docker-compose to re-set up Kafka on a Linux server, with a known, working docker-compose.config that sets up a number of Kafka components (broker, zookeeper, connect, rest proxy), and I was getting the issue described in the OP. I fixed this for my dev server instance by doing the following
docker-compose down
backup kafka-logs directory using cp kafka-logs -r kafka-logs-bak
delete the kafka-logs/meta.properties file
docker-compose up -d
Note for users of docker-compose:
My log files weren't in the default location (/tmp/kafka-logs). If you're running Kafka in Docker containers, the log path can be specified by volume config in the docker-compose e.g.
volumes:
- ./kafka-logs:/tmp/kafka-logs
This is specifying SOURCE:TARGET. ./kafka-logs is the source (i.e. a directory named kafka-logs, in the same directory as the docker-compose file). This is then targeted to /tmp/kafka-logs as the mounted volume within the kafka container). So the logs can either be deleted from the source folder on the host machine, or by deleting them from the mounted volume after doing a docker exec into the kafka container.
see https://docs.docker.com/compose/compose-file/compose-file-v2/#volumes
For me, meta.properties was in /usr/local/var/lib/kafka-logs
By removing it, the kafka started working.
I also deleted all the content of the folder containing all data generated by Kafka. I could find the folder in my .yml file:
kafka:
image: confluentinc/cp-kafka:7.0.0
ports:
- '9092:9092'
environment:
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
KAFKA_BROKER_ID: 1
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "true"
volumes:
- ./kafka-data/data:/var/lib/kafka/data
depends_on:
- zookeeper
networks:
- default
Under volumes: stays the location. So, in my case I deleted all files of the data folder located under kafka-data.
I've tried deleting the meta.properties file but didn't work.
In my case, it's solved by deleting legacy docker images.
But the problem with this is that deletes all previous data.
So be careful if you want to keep the old data this is not the right solution for you.
docker rm $(docker ps -q -f 'status=exited')
docker rmi $(docker images -q -f "dangling=true")

/kafka_2.11-2.1.1/kafka_2.11-2.1.1/bin/kafka-run-class.sh: line 306: C:\Program: No such file or directory

I am trying to start kafka broker in windows. I have zookeeper running in my system.
Command used
./bin/kafka-server-start.sh config/server1.properties
Error:
/d/software/kafka_2.11-2.1.1/kafka_2.11-2.1.1/bin/kafka-run-class.sh: line 306: C:\Program: No such file or directory
It was because I was trying to start kafka in windows.
For windows the the kafka scripts are within "bin\windows" directory. When updated my command to include kakfa scripts from windows directory, the issue got resolved.
./bin/windows/kafka-server-start.sh config/server1.properties
Yes it occured with me too. Ran with scripts in windows directory, solved the problem.
./bin/windows/kafka-server-start.sh config/server1.properties

zookeeper + Kafka - Unable to create data directory

I´m using zookeeper 3.4.8 in single node and try to use kafka.
When I run this command:
zookeeper-server-start.sh /usr/local/kafka_2.9.2-0.8.2.2 /config/zookeeper.properties
I get the below error:
[2016-02-22 17:32:41,661] ERROR Unexpected exception, exiting abnormally (org.apache.zookeeper.server.ZooKeeperServerMain)
java.io.IOException: Unable to create data directory /var/zookeeper/version-2
at org.apache.zookeeper.server.persistence.FileTxnSnapLog.<init>(FileTxnSnapLog.java:85)
at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:104)
at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:86)
at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:52)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:116)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)
Any advice?
One reason could be the inappropriate path specified to zoo.config file.
A lot of solutions on the web specifies the path as ":\zookeeper-3.4.7\data".
Instead of the above mentioned format, specify the address as full path from your C: drive to the data folder. It worked for me. (Don't forget to put double slash \ instead of one in case you're on windows)
I got this problem for this setting on Windows PC:
dataDir=c:/data/zoo/
and thus this error:
2016-12-02 15:29:25,327 [myid:] - ERROR [main:ZooKeeperServerMain#64] - Unexpected exception, exiting abnormally
java.io.IOException: Unable to create data directory ??:\data\zoo\version-2
Problem was solved by changing (I have ZooKeeper on C disk unpackaged)
dataDir=/data/zoo/
Also run command line tool as Administrator if needed
I faced the same issue, and this works with
sudo bin/zookeeper-server-start.sh config/zookeeper.properties
You probably don't have permission to write to the directory log.dirs (see zookeeper.properties). Change the directory to a different one, change the permission setting of the current log.dirs directory or run Kafka as different user. You can use the command ls -l /var/zookeeper to see the current permissions and then chmod to change the permissions.
The reason is that zookeeper has no permission. Trying to use the administrator role to install it.
For window's machine
Solved : Use double slashes inside the path while defining the dataDir path
dataDir=E:\\tools\\zookeeperdata\\data
And in my windows 10 system, using zookeeper 3.4.10. the dataDir attribute should setting like :\\\\zookeeper\\\\data, not d:\zookeeper\data. it also can setting as linux file system separator(d:/zookeeper/data). then this problem should be ok. And in linux, I think it permission problem. also it can come across when dataDir is under driver C in windows system.
If you're running the zookeeper in the Windows 10 machine we need to specify the dataDir property something like this
"dataDir=C:\zookeeper-3.4.13\data"
In my windows 10 system, using zookeeper 3.4.13, the following example path is working:
"dataDir=C:\\dev\\tools\\zookeeper-3.4.13\\data"
You have to use double backslashes.
on zoo.cfg you need to change directory to above or anything similar:
dataDir=C:/zookeeper-3.4.14/zookeeper-3.4.14/data
For windows, set dataDir to full path where you have no access restrictions - with no quotes("")
dataDir=C:\\your-path\
dataDir=C:\\zk\tmp\
Note: I have observed the command to fail for some of the path(though full access) and running command prompt as administrator has solved it.
For windows the below too works:
dataDir=C:\\zookeeper-3.4.14\\zookeeper-3.4.14\\data

Apache Kafka error on windows - Couldnot find or load main class QuorumPeerMain

I just downloaded Kafka 2.8.0 from Apache website, and I am trying to setup using the instructions given on the website. But when I try to start zookeper server, I am getting below error:
Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain
My environment is Windows 7 64 bit. I tried to follow below e-mail chain: Apache Email Chain . But still it's having same issue. Can anyone guide me in this? As I am very new to this and couldn't find many information on Google/Apache Kafka email chain.
Run these commands from your Kafka root folder:
cd bin\windows
Then run Zookeper server:
zookeeper-server-start.bat ..\..\config\zookeeper.properties
Then run Kafka server:
kafka-server-start.bat ..\..\config\server.properties
The gotcha here is to run the .bat files from the /bin/windows folder, so after you run your servers with the steps above and want to follow up with the tutorial, make sure you are running the correct batch files to create topics and whatnot, e.g.:
Create a topic:
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
List topics:
kafka-topics.bat --list --zookeeper localhost:2181
This problem happened because you have downloaded wrong version of Kafka. On the official page
you have selected Source download. If you will download the binary, everything will work as expected.
I also got the same problem in Windows platform due to keeping the kafka_2.12-2.3.0 folder in the Program Files. I changed the Kafka directory from Program Files to C:\ drive root directory. It worked fine after executing the following commands:
First, go to the Kafka root folder:
cd C:\kafka_2.12-2.3.0
Run Zookeeper server:
bin\windows\zookeeper-server-start.bat config\zookeeper.properties
Then Run Kafka Server:
bin\windows\kafka-server-start.bat config\server.properties
Had the same error message even though I had the correct Kafka download for my Scala version.
It ended up I was running the non-windows sh file (needed to run the bat in the windows sub-folder) and was running from within the bin folder instead of the root. Moving up to the root Kafka folder and running from there appears to have worked.
C:\kafka_2.10-0.8.2.0>bin\windows\zookeeper-server-start.bat config\zookeeper.properties
I'm running on OS X and I found that having spaces anywhere in the path leading to my Kafka base directory led to this exact error message. Renaming things without spaces solved the problem with no other fix.
As an example, my Kafka install was sitting at /Users/me/Kafka Demo/kafka_2.11-0.9.0.1 which caused that error when I tried to start Zookeeper. All I did was rename things as /Users/me/KafkaDemo/kafka_2.11-0.9.0.1 and everything worked fine.
The solution for windows OS is to do the following:
Download the binary version instead of the source version from the official website of Apache Kafka.
Make sure the JAVA_HOME environment variable does not have a space in it (by default it is installed in Program files), follow the official installation documentation for this.
https://docs.oracle.com/cd/E39271_01/general.300/eid_getting_started/src/tgs_install_jdk.html.
Make sure the JRE path and KAFKA_HOME path do not have spaces in them as well.
Run the zookeeper before starting Kafka.
First Thing: Remove all blank space from the folder name.
Second Thing: Use Powershell
Wrong Path:
d:\kafka node> .\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
Correct Path
d:\kafka_node> .\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
Thanks & Regards
Jaiswar Vipin Kumar R.
Just download the binary and follow the steps mentioned in below link. http://kafka.apache.org/07/quickstart.html
if you are facing errors like
Error: Could not find or load main class org.apache.zookeeper.server.quorum.Quorumpeermain
copy zookeeper.properties from config folder to bin folder and bin/windows folder.
Now start the like
server : run
zookeeper-server-start.bat zookeeper.properties
from bin or bin/windows(if you are in window machine). It should work.
If you are still facing problem, below link would be helpful
http://blog.anilot.tk/2014/08/06/Set-Up-Kafka-On-Windows/
Now try staring the Kafka server.
use the below command if you are using windows: Goto bin/windows and then run
kafka-server-start.bat ../../config/server.properties
if you are trying from shell prompt, goto bin and run below command
kafka-server-start.bat ../config/server.properties
**Make sure server.properties is present in the config folder
Yes, I too faced the same problem and tried this way which was suggested in some comments above,
First I had my Kafka in C:\Program Files, Then I moved the kafka_2.11-2.1.0 folder to C:\ directory and tried the following command and it worked
.\bin\windows\kafka-server-start.bat config\server.properties
P.S - ran the zookeper server before starting kafka
I downloaded latest stable Kafka from Apache and instruction mentioned by Matheus Felipe worked as expected.
I downloaded binary option - Scala 2.11 # http://kafka.apache.org/downloads
I had same problem used zookeeper-3.4.12.
bin directory do not has .bat files and windows directory.
Just exist .com and .sh files.
.com contain operation zookeeper execute.
As you can see, that has to find %JAVA%.
So I just set JAVA=[my java.exe path]. And it works.
I am using below mention command in windows environment.
Confluent_home\bin\windows> zookeeper-server-start.bat ..\..\etc\kafka\zookeeper.properties
if still you are getting the same error, then please verify you folder structure, Is there any space between folder name if yes then replace with either "_" or removed completely.
I was also facing the same error.
Its bit weird. But replacing the root folder name to Kafka resolved my issue. It might help one or others.
Kafka docker for Windows OS
Download the Zookeeper from page https://zookeeper.apache.org/releases.html (3.5.8)
Download the Kafka from page https://kafka.apache.org/downloads (kafka_2.13-2.6.0)
Start Zookeeper
Clone file /conf/zoo_sample.cfg to /conf/zoo.cfg
Configure Zookeeper Admin (in /conf/zoo.cfg file) netty server port by adding this line admin.serverPort=8099 at the end of the zoo.cfg file. This is to avoid the App default port 8080 conflict later.
Run command to start ./zkServer.cmd
Stop Zookeeper
Run command to stop: ./zkServer.cmd stop
Start Kafka
Configure Kafka (in /config/zookeeper.properties file) with the Zookeeper admin port (e.g admin.serverPort=8099)
Run command to start ./kafka-server-start.bat ../../config/server.properties
Stop Kafka
Run command to stop: ./kafka-server-stop.bat
Topics
Run command to create a topic: ./kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test_1
Run command to list all topics: ./kafka-topics.bat --list --zookeeper localhost:2181
Test Topics
Run command to verify if a topic was created: ./kafka-topics.bat --describe --topic test_1 --bootstrap-server localhost:9092
Open terminal to create an event to the topic: ./kafka-console-producer.bat --topic test_1 --bootstrap-server localhost:9092
Open terminal to read the event from the topic: ./kafka-console-consumer.bat --topic test_1 --from-beginning --bootstrap-server localhost:9092
Practical
Write some events into the Topic (at kafka-console-producer terminal): This is an event
Will see the events printed out from reading by the consumer (at kafka-console-consumer terminal) => This is an event
Happy coding!
I was facing the same issue.
Change the JAVA_HOME system variable to the shortened pathname so it contains no space.
Instead of: C:\Program Files\Java\jdk1.8.0_241
Set: C:\Progra~1\Java\jdk1.8.0_241
This error can happen if any kafka .bat file references a malformed JAVA_HOME variable that contains space.
Setting the shortened pathname to the variable avoids the change to another path that contains no space and solves the problem.
I used to meet the issue by running below cmd via git bash tool.
bin/zookeeper-server-start.sh config/zookeeper.properties
Solution: I switched to cygwin tool (http://cygwin.com/) to run the same cmd and I did not see the issue any more.

Zookeeper: FAILED TO WRITE PID

So I'm trying to to get started with Accumulo. I installed Hadoop and it runs w/o problems but when I try to start Zookeeper I get:
JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
-n Starting zookeeper ...
/opt/zookeeper/bin/zkServer.sh: line 103: /tmp/zookeeper/zookeeper_server.pid: No such file or directory
FAILED TO WRITE PID
I've looked around can't seem to find an answer.
I have had the same problem. In my case was useful to start Zookeeper and directly specify a configuration file:
/bin/zkServer.sh start conf/zoo.conf
I have never heard of zookeeper, but it could be a permissions issue trying to write the file zookeeper_server.pid or perhaps the directory /tmp/zookeeper/ doesn't exist and the shell script isn't accounting for that possibility. Check the permissions and existence of those directories.
zookeeper distributed with default conf, uses /tmp/zookeeper as dataDir for just example sake. It is suggested changing this value in /path/to/zookeeper/conf/zoo.cfg to /var/lib/zookeeper.
Creating /var/lib/zookeeper needs root access, so sudo is required. This directory when created will have following permissions.
ls -al /var/lib/zookeeper/
drwxr-xrwx 4 root wheel 128 May 9 14:03 .
When zookeeper is started without root permission, it cannot write to this directory. hence fails with error
... /usr/local/zookeeper/bin/zkServer.sh: line 169: /var/lib/zookeeper/zookeeper_server.pid: Permission denied
FAILED TO WRITE PID
You need to give write permissions to allow user starting zookeeper to write to /var/lib/zookeeper. In my case, as I am using it in local, I used the following command and it worked
sudo chmod o+w /var/lib/zookeeper