Java Kafka - 关闭 (kafka.server.KafkaServer),启动 Kafka-Server-Start 出现问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27381802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 04:16:42  来源:igfitidea点击:

Kafka - shutting down (kafka.server.KafkaServer), problems with starting Kafka-Server-Start

javascalaapache-kafkakafka-consumer-api

提问by Stefan P

I'll start from the beginning. I have openSuse 13.2, i also have jdk_1.7.0_51, scala-2.11.4 and gradle-2.2.1. I have downloaded source of kafka-0.8.2-bet-src and run ./gradlew commands as they where written in readme file. All commands where ran with success, except test (93% where successful, 19 failed) btw i got my releaseTarGz (kafka_2.11-0.8.2-beta.tgz). So everything goes right, i run zookeeper and it's starting right, but when i run kafka-server-start i get:

我将从头开始。我有 openSuse 13.2,我也有 jdk_1.7.0_51、scala-2.11.4 和 gradle-2.2.1。我已经下载了 kafka-0.8.2-bet-src 的源代码并运行 ./gradlew 命令,因为它们写在自述文件中。所有命令都成功运行,除了测试(93% 成功,19 失败)顺便说一句,我得到了我的 releaseTarGz(kafka_2.11-0.8.2-beta.tgz)。所以一切顺利,我运行zookeeper并且它开始正确,但是当我运行kafka-server-start时我得到:

[2014-12-09 14:27:12,496] INFO Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,496] INFO Client environment:java.io.tmpdir=/tmp (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,496] INFO Client environment:java.compiler=<NA> (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,496] INFO Client environment:os.name=Linux (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,497] INFO Client environment:os.arch=amd64 (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,497] INFO Client environment:os.version=3.16.6-2-desktop (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,497] INFO Client environment:user.name=root (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,497] INFO Client environment:user.home=/root (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,497] INFO Client environment:user.dir=/home/stefan/kafka_2.11-0.8.2-beta (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,499] INFO Initiating client connection, connectString=localhost:2181 sessionTimeout=6000 watcher=org.I0Itec.zkclient.ZkClient@4758af63 (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,542] INFO Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2014-12-09 14:27:12,550] INFO Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session (org.apache.zookeeper.ClientCnxn)
[2014-12-09 14:27:12,582] INFO Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x14a2f1b690f0002, negotiated timeout = 6000 (org.apache.zookeeper.ClientCnxn)
[2014-12-09 14:27:12,586] INFO zookeeper state changed (SyncConnected) (org.I0Itec.zkclient.ZkClient)
[2014-12-09 14:27:12,723] INFO Loading logs. (kafka.log.LogManager)
[2014-12-09 14:27:12,746] INFO Logs loading complete. (kafka.log.LogManager)
[2014-12-09 14:27:12,752] INFO Starting log cleanup with a period of 60000 ms. (kafka.log.LogManager)
[2014-12-09 14:27:12,760] INFO Starting log flusher with a default period of 9223372036854775807 ms. (kafka.log.LogManager)
[2014-12-09 14:27:12,813] INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.Acceptor)
[2014-12-09 14:27:12,814] INFO [Socket Server on Broker 0], Started (kafka.network.SocketServer)
[2014-12-09 14:27:12,950] INFO Will not load MX4J, mx4j-tools.jar is not in the classpath (kafka.utils.Mx4jLoader$)
[2014-12-09 14:27:13,078] INFO 0 successfully elected as leader (kafka.server.ZookeeperLeaderElector)
[2014-12-09 14:27:13,263] FATAL [Kafka Server 0], Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
java.net.UnknownHostException: linux-pic4.site: linux-pic4.site: Name or service not known
        at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
        at kafka.server.KafkaHealthcheck.register(KafkaHealthcheck.scala:59)
        at kafka.server.KafkaHealthcheck.startup(KafkaHealthcheck.scala:45)
        at kafka.server.KafkaServer.startup(KafkaServer.scala:124)
        at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:28)
        at kafka.Kafka$.main(Kafka.scala:46)
        at kafka.Kafka.main(Kafka.scala)
Caused by: java.net.UnknownHostException: linux-pic4.site: Name or service not known
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress.lookupAllHostAddr(InetAddress.java:901)
        at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
        at java.net.InetAddress.getLocalHost(InetAddress.java:1469)
        ... 6 more
[2014-12-09 14:27:13,270] INFO [Kafka Server 0], shutting down (kafka.server.KafkaServer)
[2014-12-09 14:27:13,289] INFO Deregistered broker 0 at path /brokers/ids/0. (kafka.utils.ZkUtils$)
[2014-12-09 14:27:13,295] INFO [Socket Server on Broker 0], Shutting down (kafka.network.SocketServer)
[2014-12-09 14:27:13,323] INFO [Socket Server on Broker 0], Shutdown completed (kafka.network.SocketServer)
[2014-12-09 14:27:13,325] INFO [Kafka Request Handler on Broker 0], shutting down (kafka.server.KafkaRequestHandlerPool)
[2014-12-09 14:27:13,406] INFO [Kafka Request Handler on Broker 0], shut down completely (kafka.server.KafkaRequestHandlerPool)
[2014-12-09 14:27:13,492] INFO New leader is 0 (kafka.server.ZookeeperLeaderElector$LeaderChangeListener)
[2014-12-09 14:27:13,735] INFO [Replica Manager on Broker 0]: Shut down (kafka.server.ReplicaManager)
[2014-12-09 14:27:13,736] INFO [ReplicaFetcherManager on broker 0] shutting down (kafka.server.ReplicaFetcherManager)
[2014-12-09 14:27:13,739] INFO [ReplicaFetcherManager on broker 0] shutdown completed (kafka.server.ReplicaFetcherManager)
[2014-12-09 14:27:13,746] INFO [Replica Manager on Broker 0]: Shut down completely (kafka.server.ReplicaManager)
[2014-12-09 14:27:13,747] INFO Shutting down. (kafka.log.LogManager)
[2014-12-09 14:27:13,765] INFO Shutdown complete. (kafka.log.LogManager)
[2014-12-09 14:27:13,775] INFO Terminate ZkClient event thread. (org.I0Itec.zkclient.ZkEventThread)
[2014-12-09 14:27:13,796] INFO Session: 0x14a2f1b690f0002 closed (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:13,797] INFO EventThread shut down (org.apache.zookeeper.ClientCnxn)
[2014-12-09 14:27:13,797] INFO [Kafka Server 0], shut down completed (kafka.server.KafkaServer)
[2014-12-09 14:27:13,799] FATAL Fatal error during KafkaServerStartable startup. Prepare to shutdown (kafka.server.KafkaServerStartable)
java.net.UnknownHostException: linux-pic4.site: linux-pic4.site: Name or service not known
        at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
        at kafka.server.KafkaHealthcheck.register(KafkaHealthcheck.scala:59)
        at kafka.server.KafkaHealthcheck.startup(KafkaHealthcheck.scala:45)
        at kafka.server.KafkaServer.startup(KafkaServer.scala:124)
        at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:28)
        at kafka.Kafka$.main(Kafka.scala:46)
        at kafka.Kafka.main(Kafka.scala)
Caused by: java.net.UnknownHostException: linux-pic4.site: Name or service not known
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress.lookupAllHostAddr(InetAddress.java:901)
        at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
        at java.net.InetAddress.getLocalHost(InetAddress.java:1469)
        ... 6 more
[2014-12-09 14:27:13,802] INFO [Kafka Server 0], shutting down (kafka.server.KafkaServer)
[2014-12-09 14:27:12,496] INFO Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,496] INFO Client environment:java.io.tmpdir=/tmp (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,496] INFO Client environment:java.compiler=<NA> (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,496] INFO Client environment:os.name=Linux (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,497] INFO Client environment:os.arch=amd64 (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,497] INFO Client environment:os.version=3.16.6-2-desktop (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,497] INFO Client environment:user.name=root (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,497] INFO Client environment:user.home=/root (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,497] INFO Client environment:user.dir=/home/stefan/kafka_2.11-0.8.2-beta (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,499] INFO Initiating client connection, connectString=localhost:2181 sessionTimeout=6000 watcher=org.I0Itec.zkclient.ZkClient@4758af63 (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:12,542] INFO Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2014-12-09 14:27:12,550] INFO Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session (org.apache.zookeeper.ClientCnxn)
[2014-12-09 14:27:12,582] INFO Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x14a2f1b690f0002, negotiated timeout = 6000 (org.apache.zookeeper.ClientCnxn)
[2014-12-09 14:27:12,586] INFO zookeeper state changed (SyncConnected) (org.I0Itec.zkclient.ZkClient)
[2014-12-09 14:27:12,723] INFO Loading logs. (kafka.log.LogManager)
[2014-12-09 14:27:12,746] INFO Logs loading complete. (kafka.log.LogManager)
[2014-12-09 14:27:12,752] INFO Starting log cleanup with a period of 60000 ms. (kafka.log.LogManager)
[2014-12-09 14:27:12,760] INFO Starting log flusher with a default period of 9223372036854775807 ms. (kafka.log.LogManager)
[2014-12-09 14:27:12,813] INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.Acceptor)
[2014-12-09 14:27:12,814] INFO [Socket Server on Broker 0], Started (kafka.network.SocketServer)
[2014-12-09 14:27:12,950] INFO Will not load MX4J, mx4j-tools.jar is not in the classpath (kafka.utils.Mx4jLoader$)
[2014-12-09 14:27:13,078] INFO 0 successfully elected as leader (kafka.server.ZookeeperLeaderElector)
[2014-12-09 14:27:13,263] FATAL [Kafka Server 0], Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
java.net.UnknownHostException: linux-pic4.site: linux-pic4.site: Name or service not known
        at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
        at kafka.server.KafkaHealthcheck.register(KafkaHealthcheck.scala:59)
        at kafka.server.KafkaHealthcheck.startup(KafkaHealthcheck.scala:45)
        at kafka.server.KafkaServer.startup(KafkaServer.scala:124)
        at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:28)
        at kafka.Kafka$.main(Kafka.scala:46)
        at kafka.Kafka.main(Kafka.scala)
Caused by: java.net.UnknownHostException: linux-pic4.site: Name or service not known
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress.lookupAllHostAddr(InetAddress.java:901)
        at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
        at java.net.InetAddress.getLocalHost(InetAddress.java:1469)
        ... 6 more
[2014-12-09 14:27:13,270] INFO [Kafka Server 0], shutting down (kafka.server.KafkaServer)
[2014-12-09 14:27:13,289] INFO Deregistered broker 0 at path /brokers/ids/0. (kafka.utils.ZkUtils$)
[2014-12-09 14:27:13,295] INFO [Socket Server on Broker 0], Shutting down (kafka.network.SocketServer)
[2014-12-09 14:27:13,323] INFO [Socket Server on Broker 0], Shutdown completed (kafka.network.SocketServer)
[2014-12-09 14:27:13,325] INFO [Kafka Request Handler on Broker 0], shutting down (kafka.server.KafkaRequestHandlerPool)
[2014-12-09 14:27:13,406] INFO [Kafka Request Handler on Broker 0], shut down completely (kafka.server.KafkaRequestHandlerPool)
[2014-12-09 14:27:13,492] INFO New leader is 0 (kafka.server.ZookeeperLeaderElector$LeaderChangeListener)
[2014-12-09 14:27:13,735] INFO [Replica Manager on Broker 0]: Shut down (kafka.server.ReplicaManager)
[2014-12-09 14:27:13,736] INFO [ReplicaFetcherManager on broker 0] shutting down (kafka.server.ReplicaFetcherManager)
[2014-12-09 14:27:13,739] INFO [ReplicaFetcherManager on broker 0] shutdown completed (kafka.server.ReplicaFetcherManager)
[2014-12-09 14:27:13,746] INFO [Replica Manager on Broker 0]: Shut down completely (kafka.server.ReplicaManager)
[2014-12-09 14:27:13,747] INFO Shutting down. (kafka.log.LogManager)
[2014-12-09 14:27:13,765] INFO Shutdown complete. (kafka.log.LogManager)
[2014-12-09 14:27:13,775] INFO Terminate ZkClient event thread. (org.I0Itec.zkclient.ZkEventThread)
[2014-12-09 14:27:13,796] INFO Session: 0x14a2f1b690f0002 closed (org.apache.zookeeper.ZooKeeper)
[2014-12-09 14:27:13,797] INFO EventThread shut down (org.apache.zookeeper.ClientCnxn)
[2014-12-09 14:27:13,797] INFO [Kafka Server 0], shut down completed (kafka.server.KafkaServer)
[2014-12-09 14:27:13,799] FATAL Fatal error during KafkaServerStartable startup. Prepare to shutdown (kafka.server.KafkaServerStartable)
java.net.UnknownHostException: linux-pic4.site: linux-pic4.site: Name or service not known
        at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
        at kafka.server.KafkaHealthcheck.register(KafkaHealthcheck.scala:59)
        at kafka.server.KafkaHealthcheck.startup(KafkaHealthcheck.scala:45)
        at kafka.server.KafkaServer.startup(KafkaServer.scala:124)
        at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:28)
        at kafka.Kafka$.main(Kafka.scala:46)
        at kafka.Kafka.main(Kafka.scala)
Caused by: java.net.UnknownHostException: linux-pic4.site: Name or service not known
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress.lookupAllHostAddr(InetAddress.java:901)
        at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
        at java.net.InetAddress.getLocalHost(InetAddress.java:1469)
        ... 6 more
[2014-12-09 14:27:13,802] INFO [Kafka Server 0], shutting down (kafka.server.KafkaServer)

This is my server.properties file:

这是我的 server.properties 文件:

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
# 
#    http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# see kafka.server.KafkaConfig for additional details and defaults

############################# Server Basics #############################

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0

############################# Socket Server Settings #############################

# The port the socket server listens on
port=9092

# Hostname the broker will bind to. If not set, the server will bind to all interfaces
#host.name=localhost

# Hostname the broker will advertise to producers and consumers. If not set, it uses the
# value for "host.name" if configured.  Otherwise, it will use the value returned from
# java.net.InetAddress.getCanonicalHostName().
#advertised.host.name=<hostname routable by clients>

# The port to publish to ZooKeeper for clients to use. If this is not set,
# it will publish the same port that the broker binds to.
#advertised.port=<port accessible by clients>

# The number of threads handling network requests
num.network.threads=3

# The number of threads doing disk I/O
num.io.threads=8

# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=65536

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


############################# Log Basics #############################

# A comma seperated list of directories under which to store log files
log.dirs=/tmp/kafka-logs

# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=1

# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk. 
# There are a few important trade-offs here:
#    1. Durability: Unflushed data may be lost if you are not using replication.
#    2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
#    3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks. 
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining
# segments don't drop below log.retention.bytes.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according 
# to the retention policies
log.retention.check.interval.ms=300000

# By default the log cleaner is disabled and the log retention policy will default to just delete segments after their retention expires.
# If log.cleaner.enable=true is set the cleaner will be enabled and individual logs can then be marked for log compaction.
log.cleaner.enable=false

############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=2000

And my /etc/hosts file:

还有我的 /etc/hosts 文件:

#
# hosts         This file describes a number of hostname-to-address
#               mappings for the TCP/IP subsystem.  It is mostly
#               used at boot time, when no name servers are running.
#               On small systems, this file can be used instead of a
#               "named" name server.
# Syntax:
#    
# IP-Address  Full-Qualified-Hostname  Short-Hostname
#

127.0.0.1       localhost

# special IPv6 addresses
::1             localhost ipv6-localhost ipv6-loopback

fe00::0         ipv6-localnet

ff00::0         ipv6-mcastprefix
ff02::1         ipv6-allnodes
ff02::2         ipv6-allrouters
ff02::3         ipv6-allhosts

Could anyone help me?

有人可以帮助我吗?

采纳答案by Gwen Shapira

You need to add your hostname to /etc/hosts: 127.0.0.1 localhost linux-pic4.site

您需要将您的主机名添加到 /etc/hosts: 127.0.0.1 localhost linux-pic4.site

See here for deeper explanation: InetAddress.getLocalHost() throws UnknownHostException

在这里查看更深入的解释: InetAddress.getLocalHost() throws UnknownHostException

回答by tedwon

Recommends use host.name property on the server.properties configuration file.

建议在 server.properties 配置文件中使用 host.name 属性。

Hostname the broker will bind to. If not set, the server will bind to all interfaces

代理将绑定到的主机名。如果没有设置,服务器将绑定到所有接口

host.name=yourhostname

or

或者

host.name=localhost