【已解決】kafka使用遇到的坑

1. kafka使用文檔

2. 在kafka啓動zookeeper

bin/zookeeper-server-start.sh config/zookeeper.properties

遇到問題:java

[2020-08-06 11:22:05,915] ERROR Unexpected exception, exiting abnormally (org.apache.zookeeper.server.ZooKeeperServerMain)
java.net.BindException: Address already in use
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:433)
        at sun.nio.ch.Net.bind(Net.java:425)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)
        at org.apache.zookeeper.server.NIOServerCnxnFactory.configure(NIOServerCnxnFactory.java:687)
        at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:143)
        at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:106)
        at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:64)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:128)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:82)

解決方式:
輸入命令
node

sudo lsof -i :2181

獲得:apache

COMMAND   PID        USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java      413 zhangjingyi   52u  IPv6 0xbf7b177b8ddf25db      0t0  TCP localhost:55070->localhost:eforward (ESTABLISHED)
java    64540 zhangjingyi  125u  IPv6 0xbf7b177b8ddf035b      0t0  TCP *:eforward (LISTEN)
java    64540 zhangjingyi  129u  IPv6 0xbf7b177b8ddf2b9b      0t0  TCP localhost:eforward->localhost:55070 (ESTABLISHED)
java    64540 zhangjingyi  130u  IPv6 0xbf7b177b8ddf0edb      0t0  TCP localhost:eforward->localhost:55151 (ESTABLISHED)
java    64931 zhangjingyi  122u  IPv6 0xbf7b177b8ddf1a5b      0t0  TCP localhost:55151->localhost:eforward (ESTABLISHED)

解決方式:ui

kill -9 64540

3. 運行kafka

./bin/kafka-server-start.sh config/server.properties

遇到問題spa

ERROR [KafkaServer id=0] Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
org.apache.kafka.common.KafkaException: Socket server failed to bind to 0.0.0.0:9092: Address already in use.
	at kafka.network.Acceptor.openServerSocket(SocketServer.scala:605)
	at kafka.network.Acceptor.<init>(SocketServer.scala:481)
	at kafka.network.SocketServer.createAcceptor(SocketServer.scala:244)
	at kafka.network.SocketServer.$anonfun$createDataPlaneAcceptorsAndProcessors$1(SocketServer.scala:213)
	at kafka.network.SocketServer.$anonfun$createDataPlaneAcceptorsAndProcessors$1$adapted(SocketServer.scala:211)
	at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:62)
	at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:55)
	at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:49)
	at kafka.network.SocketServer.createDataPlaneAcceptorsAndProcessors(SocketServer.scala:211)
	at kafka.network.SocketServer.startup(SocketServer.scala:122)
	at kafka.server.KafkaServer.startup(KafkaServer.scala:266)
	at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:44)
	at kafka.Kafka$.main(Kafka.scala:82)
	at kafka.Kafka.main(Kafka.scala)
Caused by: java.net.BindException: Address already in use
	at sun.nio.ch.Net.bind0(Native Method)
	at sun.nio.ch.Net.bind(Net.java:433)
	at sun.nio.ch.Net.bind(Net.java:425)
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)
	at kafka.network.Acceptor.openServerSocket(SocketServer.scala:601)
	... 13 more

輸入命令.net

lsof -n -i :9092 | grep LISTEN

獲得scala

java    64931 zhangjingyi  127u  IPv6 0xbf7b177b8ddf201b      0t0  TCP *:XmlIpcRegSvc (LISTEN)

解決方式:3d

kill -9 64931

4. 再啓動kafka

./bin/kafka-server-start.sh config/server.properties

遇到問題code

Connection to node 0 (bogon/192.168.124.2:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2020-08-06 11:42:41,445] WARN [Controller id=0, targetBrokerId=0] Connection to node 0 (bogon/192.168.124.2:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2020-08-06 11:42:41,557] WARN [Controller id=0, targetBrokerId=0] Connection to node 0 (bogon/192.168.124.2:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2020-08-06 11:42:41,663] WARN [Controller id=0, targetBrokerId=0] Connection to node 0 (bogon/192.168.124.2:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2020-08-06 11:42:41,770] WARN [Controller id=0, targetBrokerId=0] Connection to node 0 (bogon/192.168.124.2:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2020-08-06 11:42:41,878] WARN [Controller id=0, targetBrokerId=0] Connection to node 0 (bogon/192.168.124.2:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

修改 server.properties
添加配置:
orm

listeners=PLAINTEXT://localhost:9092
advertised.listeners=PLAINTEXT://localhost:9092

在這裏插入圖片描述

  1. 再啓動kafka
./bin/kafka-server-start.sh config/server.properties

started運行成功

[2020-08-06 11:51:07,209] INFO [KafkaServer id=0] started (kafka.server.KafkaServer)
相關文章
相關標籤/搜索