在Apache Kafka中启动多个代理时出错-

时间:2019-06-28 01:21:28

标签: apache-kafka

我是Apache Kafka的菜鸟。我正在阅读《 Apache Kafka快速入门指南》一书,并按照其步骤配置环境。因此,我首先成功地使用了Confluent平台(Kafka和Zookeeper)。接下来,我正在尝试初始化多个代理,但是当broker.id = 2启动时出现错误。我做了以下步骤:

1-我创建了一个名为config / server.properties的文件夹
        mark-1.properties和mark-2.properties

2-接下来,我写了mark-1.properties和
        mark-2.properties:

    broker.id=1
    port=9093
    log.dirs=/tmp/mark-1-logs

    broker.id=2
    port=9094
    log.dirs=/tmp/mark-2-logs

3-在Confluent已经运行的情况下,我输入了以下命令:         行:

    ./bin/kafka-server-start ./mark/mark-1.properties &

     and in other command line window

    ./bin/kafka-server-start ./mark/mark-2.properties &

输出错误为:

    [2019-06-28 00:35:26,535] ERROR Fatal error during KafkaServer     
    startup. Prepare to shutdown (kafka.server.KafkaServer)
    kafka.common.InconsistentBrokerIdException: Configured broker.id 2     
    doesn't match stored broker.id 1 in meta.properties. If you moved 
    your data, make sure your configured broker.id matches. If you 
    intend to create a new broker, you should remove all data in your 
    data directories (log.dirs).

我已按照书中所有说明和论坛进行操作,但是错误         坚持。我能做什么?

我希望多个代理独立运行。

所有日志错误:

    [2019-06-28 15:06:51,018] INFO Registered kafka:type=kafka.Log4jController MBean (kafka.utils.Log4jControllerRegistration$)
[2019-06-28 15:06:52,717] INFO Registered signal handlers for TERM, INT, HUP (org.apache.kafka.common.utils.LoggingSignalHandler)
[2019-06-28 15:06:52,721] INFO starting (kafka.server.KafkaServer)
[2019-06-28 15:06:52,722] INFO Connecting to zookeeper on localhost:2181 (kafka.server.KafkaServer)
[2019-06-28 15:06:52,753] INFO [ZooKeeperClient Kafka server] Initializing a new session to localhost:2181. (kafka.zookeeper.ZooKeeperClient)
[2019-06-28 15:06:52,768] INFO Client environment:zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,768] INFO Client environment:host.name=ip-172-31-72-19.ec2.internal (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,768] INFO Client environment:java.version=11.0.3 (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,768] INFO Client environment:java.vendor=Oracle Corporation (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,768] INFO Client environment:java.home=/usr/lib/jvm/java-11-openjdk-amd64 (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,769] INFO Client environment:java.class.path=/opt/kafka/kafka_2.12-2.3.0/bin/../libs/activation-1.1.1.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/aopalliance-repackaged-2.5.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/argparse4j-0.7.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/audience-annotations-0.5.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/commons-lang3-3.8.1.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/connect-api-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/connect-basic-auth-extension-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/connect-file-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/connect-json-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/connect-runtime-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/connect-transforms-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/guava-20.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/hk2-api-2.5.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/hk2-locator-2.5.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/hk2-utils-2.5.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jackson-annotations-2.9.9.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jackson-core-2.9.9.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jackson-databind-2.9.9.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jackson-dataformat-csv-2.9.9.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jackson-datatype-jdk8-2.9.9.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jackson-jaxrs-base-2.9.9.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jackson-jaxrs-json-provider-2.9.9.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jackson-module-jaxb-annotations-2.9.9.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jackson-module-paranamer-2.9.9.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jackson-module-scala_2.12-2.9.9.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jakarta.annotation-api-1.3.4.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jakarta.inject-2.5.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jakarta.ws.rs-api-2.1.5.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/javassist-3.22.0-CR2.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/javax.servlet-api-3.1.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/javax.ws.rs-api-2.1.1.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jaxb-api-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jersey-client-2.28.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jersey-common-2.28.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jersey-container-servlet-2.28.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jersey-container-servlet-core-2.28.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jersey-hk2-2.28.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jersey-media-jaxb-2.28.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jersey-server-2.28.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jetty-client-9.4.18.v20190429.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jetty-continuation-9.4.18.v20190429.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jetty-http-9.4.18.v20190429.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jetty-io-9.4.18.v20190429.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jetty-security-9.4.18.v20190429.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jetty-server-9.4.18.v20190429.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jetty-servlet-9.4.18.v20190429.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jetty-servlets-9.4.18.v20190429.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jetty-util-9.4.18.v20190429.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jopt-simple-5.0.4.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/jsr305-3.0.2.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/kafka-clients-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/kafka-log4j-appender-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/kafka-streams-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/kafka-streams-examples-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/kafka-streams-scala_2.12-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/kafka-streams-test-utils-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/kafka-tools-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/kafka_2.12-2.3.0-sources.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/kafka_2.12-2.3.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/log4j-1.2.17.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/lz4-java-1.6.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/maven-artifact-3.6.1.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/metrics-core-2.2.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/osgi-resource-locator-1.0.1.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/paranamer-2.8.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/plexus-utils-3.2.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/reflections-0.9.11.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/rocksdbjni-5.18.3.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/scala-library-2.12.8.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/scala-logging_2.12-3.9.0.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/scala-reflect-2.12.8.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/slf4j-api-1.7.26.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/slf4j-log4j12-1.7.26.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/snappy-java-1.1.7.3.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/spotbugs-annotations-3.1.9.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/validation-api-2.0.1.Final.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/zkclient-0.11.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/zookeeper-3.4.14.jar:/opt/kafka/kafka_2.12-2.3.0/bin/../libs/zstd-jni-1.4.0-1.jar (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,771] INFO Client environment:java.library.path=/usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,771] INFO Client environment:java.io.tmpdir=/tmp (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,772] INFO Client environment:java.compiler=<NA> (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,772] INFO Client environment:os.name=Linux (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,772] INFO Client environment:os.arch=amd64 (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,772] INFO Client environment:os.version=4.15.0-1041-aws (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,772] INFO Client environment:user.name=root (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,772] INFO Client environment:user.home=/root (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,773] INFO Client environment:user.dir=/opt/kafka/kafka_2.12-2.3.0 (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,774] INFO Initiating client connection, connectString=localhost:2181 sessionTimeout=6000 watcher=kafka.zookeeper.ZooKeeperClient$ZooKeeperClientWatcher$@58e1d9d (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:52,819] INFO [ZooKeeperClient Kafka server] Waiting until connected. (kafka.zookeeper.ZooKeeperClient)
[2019-06-28 15:06:52,862] INFO Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2019-06-28 15:06:52,876] INFO Socket connection established to localhost/127.0.0.1:2181, initiating session (org.apache.zookeeper.ClientCnxn)
[2019-06-28 15:06:52,887] INFO Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x100000ec2640001, negotiated timeout = 6000 (org.apache.zookeeper.ClientCnxn)
[2019-06-28 15:06:52,910] INFO [ZooKeeperClient Kafka server] Connected. (kafka.zookeeper.ZooKeeperClient)
[2019-06-28 15:06:53,309] INFO Cluster ID = LM8y5RcXQJCMJeIJlmi34A (kafka.server.KafkaServer)
[2019-06-28 15:06:53,329] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
kafka.common.InconsistentBrokerIdException: Configured broker.id 2 doesn't match stored broker.id 1 in meta.properties. If you moved your data, make sure your configured broker.id matches. If you intend to create a new broker, you should remove all data in your data directories (log.dirs).
    at kafka.server.KafkaServer.getBrokerIdAndOfflineDirs(KafkaServer.scala:715)
    at kafka.server.KafkaServer.startup(KafkaServer.scala:214)
    at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
    at kafka.Kafka$.main(Kafka.scala:84)
    at kafka.Kafka.main(Kafka.scala)
[2019-06-28 15:06:53,333] INFO shutting down (kafka.server.KafkaServer)
[2019-06-28 15:06:53,350] INFO [ZooKeeperClient Kafka server] Closing. (kafka.zookeeper.ZooKeeperClient)
[2019-06-28 15:06:53,365] INFO EventThread shut down for session: 0x100000ec2640001 (org.apache.zookeeper.ClientCnxn)
[2019-06-28 15:06:53,387] INFO Session: 0x100000ec2640001 closed (org.apache.zookeeper.ZooKeeper)
[2019-06-28 15:06:53,393] INFO [ZooKeeperClient Kafka server] Closed. (kafka.zookeeper.ZooKeeperClient)
[2019-06-28 15:06:53,423] INFO shut down completed (kafka.server.KafkaServer)
[2019-06-28 15:06:53,427] ERROR Exiting Kafka. (kafka.server.KafkaServerStartable)
[2019-06-28 15:06:53,479] INFO shutting down (kafka.server.KafkaServer)

3 个答案:

答案 0 :(得分:0)

您是否以相同的./bin/Kafka-server-start文件开头?

如果是这样,则应将所有kafka文件复制到另一个目录。

在同一启动目录下,不能仅指定不同的配置文件启动kafka。

答案 1 :(得分:0)

亲爱的,错误是我的。我在新的kafka代理配置属性中使用关于port和log.dir的命令编写了行重复项。

感谢您的关注!

下面是正确的配置文件片段:

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

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

# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://:9093

# Hostname and port the broker will advertise to producers and consumers. If not set, 
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3

# The number of threads that the server uses for processing requests, which may include 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=102400

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


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

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

答案 2 :(得分:0)

当我尝试在本地 Windows 机器上运行 kafka(单个动物园管理员和单个代理)时,我遇到了这个错误 - kafka.common.InconsistentBrokerIdException

以下更改对我有用 -

zookeeper.properties 集合中 -

dataDir=C:/Kafka/data/zookeeperlogs

server.properties 集合中 -

log.dirs=C:/Kafka/data/brokerlogs

父目录(C:/Kafka/data)以前不同,这造成了不同。