Kafka 安装配置
kafka下载:https://www.apache.org/dyn/closer.cgi?path=/kafka/0.8.1/kafka_2.10-0.8.1.tgz分别在三台服务器上安装kafka:tar zxvf kafka_2.10-0.8.1.tgz修改每台服务器的config/server.properties brokerid: 唯一,填数字,本
·
kafka下载:https://www.apache.org/dyn/closer.cgi?path=/kafka/0.8.1/kafka_2.10-0.8.1.tgz
分别在三台服务器上安装kafka:
tar zxvf kafka_2.10-0.8.1.tgz
修改每台服务器的config/server.properties
broker.id: 唯一,填数字,本文中分别为132/133/134
host.name:唯一,填服务器IP,之前配置时,把中间的'.'给忘写了,导致kafka集群形同虚设(基本只有leader机器在起作用),以及一系列莫名其妙的问题,伤啊
zookeeper.connect=192.168.40.134:2181,192.168.40.132:2181,192.168.40.133:2181
先启动zookeeper服务: bin/zkServer.sh start (本文中zookeeper为独立安装,具体过程在此不细述)
再在每台机器上执行: bin/kafka-server-start.sh config/server.properties
你将会看到如下信息:
<span style="font-family:Microsoft YaHei;font-size:14px;">[2014-04-02 02:42:14,220] INFO Verifying properties (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,281] INFO Property broker.id is overridden to 0 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,281] INFO Property log.cleaner.enable is overridden to false (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,281] INFO Property log.dirs is overridden to /tmp/kafka-logs (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,282] INFO Property log.retention.check.interval.ms is overridden to 60000 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,282] INFO Property log.retention.hours is overridden to 168 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,282] INFO Property log.segment.bytes is overridden to 536870912 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,282] INFO Property num.io.threads is overridden to 8 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,283] INFO Property num.network.threads is overridden to 2 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,283] INFO Property num.partitions is overridden to 2 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,283] INFO Property port is overridden to 9092 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,283] INFO Property socket.receive.buffer.bytes is overridden to 1048576 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,284] INFO Property socket.request.max.bytes is overridden to 104857600 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,284] INFO Property socket.send.buffer.bytes is overridden to 1048576 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,284] INFO Property zookeeper.connect is overridden to 192.168.40.134:2181,192.168.40.132:2181,192.168.40.133:2181 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,284] INFO Property zookeeper.connection.timeout.ms is overridden to 1000000 (kafka.utils.VerifiableProperties)
[2014-04-02 02:42:14,309] INFO [Kafka Server 0], starting (kafka.server.KafkaServer)
[2014-04-02 02:42:14,312] INFO [Kafka Server 0], Connecting to zookeeper on 192.168.40.134:2181,192.168.40.132:2181,192.168.40.133:2181 (kafka.server.KafkaServer)
[2014-04-02 02:42:14,334] INFO Starting ZkClient event thread. (org.I0Itec.zkclient.ZkEventThread)
[2014-04-02 02:42:14,348] INFO Client environment:zookeeper.version=3.3.3-1203054, built on 11/17/2011 05:47 GMT (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,348] INFO Client environment:host.name=ubuntu (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,348] INFO Client environment:java.version=1.6.0_37 (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,348] INFO Client environment:java.vendor=Sun Microsystems Inc. (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,348] INFO Client environment:java.home=/etc/local/jdk1.6.0_37/jre (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,349] INFO Client environment:java.class.path=:/usr/local/kafka_2.10-0.8.1/bin/../core/build/dependant-libs-2.8.0/*.jar:/usr/local/kafka_2.10-0.8.1/bin/../perf/build/libs//kafka-perf_2.8.0*.jar:/usr/local/kafka_2.10-0.8.1/bin/../clients/build/libs//kafka-clients*.jar:/usr/local/kafka_2.10-0.8.1/bin/../examples/build/libs//kafka-examples*.jar:/usr/local/kafka_2.10-0.8.1/bin/../contrib/hadoop-consumer/build/libs//kafka-hadoop-consumer*.jar:/usr/local/kafka_2.10-0.8.1/bin/../contrib/hadoop-producer/build/libs//kafka-hadoop-producer*.jar:/usr/local/kafka_2.10-0.8.1/bin/../libs/jopt-simple-3.2.jar:/usr/local/kafka_2.10-0.8.1/bin/../libs/kafka_2.10-0.8.1.jar:/usr/local/kafka_2.10-0.8.1/bin/../libs/log4j-1.2.15.jar:/usr/local/kafka_2.10-0.8.1/bin/../libs/metrics-annotation-2.2.0.jar:/usr/local/kafka_2.10-0.8.1/bin/../libs/metrics-core-2.2.0.jar:/usr/local/kafka_2.10-0.8.1/bin/../libs/scala-library-2.10.1.jar:/usr/local/kafka_2.10-0.8.1/bin/../libs/slf4j-api-1.7.2.jar:/usr/local/kafka_2.10-0.8.1/bin/../libs/snappy-java-1.0.5.jar:/usr/local/kafka_2.10-0.8.1/bin/../libs/zkclient-0.3.jar:/usr/local/kafka_2.10-0.8.1/bin/../libs/zookeeper-3.3.4.jar:/usr/local/kafka_2.10-0.8.1/bin/../core/build/libs/kafka_2.8.0*.jar (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,349] INFO Client environment:java.library.path=/etc/local/jdk1.6.0_37/jre/lib/amd64/server:/etc/local/jdk1.6.0_37/jre/lib/amd64:/etc/local/jdk1.6.0_37/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,349] INFO Client environment:java.io.tmpdir=/tmp (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,349] INFO Client environment:java.compiler=<NA> (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,349] INFO Client environment:os.name=Linux (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,349] INFO Client environment:os.arch=amd64 (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,349] INFO Client environment:os.version=3.8.0-29-generic (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,349] INFO Client environment:user.name=root (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,349] INFO Client environment:user.home=/root (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,349] INFO Client environment:user.dir=/usr/local/kafka_2.10-0.8.1 (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,352] INFO Initiating client connection, connectString=192.168.40.134:2181,192.168.40.132:2181,192.168.40.133:2181 sessionTimeout=6000 watcher=org.I0Itec.zkclient.ZkClient@7ed75415 (org.apache.zookeeper.ZooKeeper)
[2014-04-02 02:42:14,412] INFO Opening socket connection to server /192.168.40.134:2181 (org.apache.zookeeper.ClientCnxn)
[2014-04-02 02:42:14,779] INFO Socket connection established to ubuntu.local/192.168.40.134:2181, initiating session (org.apache.zookeeper.ClientCnxn)
[2014-04-02 02:42:14,805] INFO Session establishment complete on server ubuntu.local/192.168.40.134:2181, sessionid = 0x14521d0059e0000, negotiated timeout = 6000 (org.apache.zookeeper.ClientCnxn)
[2014-04-02 02:42:14,811] INFO zookeeper state changed (SyncConnected) (org.I0Itec.zkclient.ZkClient)
[2014-04-02 02:42:15,045] INFO Log directory '/tmp/kafka-logs' not found, creating it. (kafka.log.LogManager)
[2014-04-02 02:42:15,072] INFO Starting log cleanup with a period of 60000 ms. (kafka.log.LogManager)
[2014-04-02 02:42:15,077] INFO Starting log flusher with a default period of 9223372036854775807 ms. (kafka.log.LogManager)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[2014-04-02 02:42:15,170] INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.Acceptor)
[2014-04-02 02:42:15,176] INFO [Socket Server on Broker 0], Started (kafka.network.SocketServer)
[2014-04-02 02:42:15,310] INFO Will not load MX4J, mx4j-tools.jar is not in the classpath (kafka.utils.Mx4jLoader$)
[2014-04-02 02:42:15,387] INFO 0 successfully elected as leader (kafka.server.ZookeeperLeaderElector)
[2014-04-02 02:42:15,527] INFO Registered broker 0 at path /brokers/ids/0 with address ubuntu:9092. (kafka.utils.ZkUtils$)
[2014-04-02 02:42:15,571] INFO [Kafka Server 0], started (kafka.server.KafkaServer)
[2014-04-02 02:42:15,654] INFO New leader is 0 (kafka.server.ZookeeperLeaderElector$LeaderChangeListener)
</span>
创建topic:
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic mykafka
查看Topic:
bin/kafka-topics.sh --list --zookeeper localhost:2181
显示Topic:mykafka
查看详细信息:
bin/kafktopics.sh --describe --zookeeper 192.168.40.132:2181Topic:mykafka PartitionCount:1 ReplicationFactor:3 Configs:Topic: mykafka Partition: 0 Leader: 133 Replicas: 133,134,132 Isr: 134发送消息:bin/kafka-console-producer.sh --broker-list 192.168.40.134:9092 --topic mykafka
23423
^C
bin/kafka-console-producer.sh --brokelist 192.168.40.134:9092 --topic mykafka
4533
如果出现以下信息,则需要下载slftj-nop-1.5.jar,并将其cp至kafka的libs目录下:<span style="font-family:Microsoft YaHei;font-size:14px;">SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. </span>
接收消息:
bin/kafka-console-consumer.sh --zookeeper 192.168.40.133:2181 --topic mykafka --from-beginning
sfsa
asdg
sfa
asfda
sadf
1
3
4
5
23423
4533
更多推荐
已为社区贡献1条内容
所有评论(0)