欢迎访问:鲁春利的工作笔记,学习是一种信仰,让时间考验坚持的力量。
Kafka主要的shell脚本有
[hadoop@nnode kafka0.8.2.1]$ ll 总计 80 -rwxr-xr-x 1 hadoop hadoop 943 2015-02-27 kafka-console-consumer.sh -rwxr-xr-x 1 hadoop hadoop 942 2015-02-27 kafka-console-producer.sh -rwxr-xr-x 1 hadoop hadoop 870 2015-02-27 kafka-consumer-offset-checker.sh -rwxr-xr-x 1 hadoop hadoop 946 2015-02-27 kafka-consumer-perf-test.sh -rwxr-xr-x 1 hadoop hadoop 860 2015-02-27 kafka-mirror-maker.sh -rwxr-xr-x 1 hadoop hadoop 884 2015-02-27 kafka-preferred-replica-election.sh -rwxr-xr-x 1 hadoop hadoop 946 2015-02-27 kafka-producer-perf-test.sh -rwxr-xr-x 1 hadoop hadoop 872 2015-02-27 kafka-reassign-partitions.sh -rwxr-xr-x 1 hadoop hadoop 866 2015-02-27 kafka-replay-log-producer.sh -rwxr-xr-x 1 hadoop hadoop 872 2015-02-27 kafka-replica-verification.sh -rwxr-xr-x 1 hadoop hadoop 4185 2015-02-27 kafka-run-class.sh -rwxr-xr-x 1 hadoop hadoop 1333 2015-02-27 kafka-server-start.sh -rwxr-xr-x 1 hadoop hadoop 891 2015-02-27 kafka-server-stop.sh -rwxr-xr-x 1 hadoop hadoop 868 2015-02-27 kafka-simple-consumer-shell.sh -rwxr-xr-x 1 hadoop hadoop 861 2015-02-27 kafka-topics.sh drwxr-xr-x 2 hadoop hadoop 4096 2015-02-27 windows -rwxr-xr-x 1 hadoop hadoop 1370 2015-02-27 zookeeper-server-start.sh -rwxr-xr-x 1 hadoop hadoop 875 2015-02-27 zookeeper-server-stop.sh -rwxr-xr-x 1 hadoop hadoop 968 2015-02-27 zookeeper-shell.sh [hadoop@nnode kafka0.8.2.1]$
说明:Kafka也提供了在windows下运行的bat脚本,在bin/windows目录下。
ZooKeeper脚本
Kafka各组件均依赖于ZooKeeper环境,因此在使用Kafka之前首先需要具备ZooKeeper环境;可以配置ZooKeeper集群,也可以使用Kafka集成的ZooKeeper脚本来启动一个standalone mode的ZooKeeper节点。
# 启动Zookeeper Server [hadoop@nnode kafka0.8.2.1]$ bin/zookeeper-server-start.sh USAGE: bin/zookeeper-server-start.sh zookeeper.properties # 配置文件路径为config/zookeeper.properties,主要配置zookeeper的本地存储路径(dataDir) # 内部实现为调用 exec $base_dir/kafka-run-class.sh $EXTRA_ARGS org.apache.zookeeper.server.quorum.QuorumPeerMain $@ # 停止ZooKeeper Server [hadoop@nnode kafka0.8.2.1]$ bin/zookeeper-server-stop.sh # 内部实现为调用 ps ax | grep -i ‘zookeeper‘ | grep -v grep | awk ‘{print $1}‘ | xargs kill -SIGINT # 设置服务器参数 [hadoop@nnode kafka0.8.2.1]$ zookeeper-shell.sh USAGE: bin/zookeeper-shell.sh zookeeper_host:port[/path] [args...] # 内部实现为调用 exec $(dirname $0)/kafka-run-class.sh org.apache.zookeeper.ZooKeeperMain -server "$@"
说明:$@ 表示所有参数列表。 $# 添加到Shell的参数个数。
Kafka启动与停止
# 启动Kafka Server [hadoop@nnode kafka0.8.2.1]$ bin/kafka-server-start.sh USAGE: bin/kafka-server-start.sh [-daemon] server.properties # 内部实现为调用 exec $base_dir/kafka-run-class.sh $EXTRA_ARGS kafka.Kafka $@ # 略 [hadoop@nnode kafka0.8.2.1]$ bin/kafka-run-class.sh # 停止Kafka Server [hadoop@nnode kafka0.8.2.1]$ kafka-server-stop.sh # 内部实现为调用 ps ax | grep -i ‘kafka\.Kafka‘ | grep java | grep -v grep | awk ‘{print $1}‘ | xargs kill -SIGTERM
说明:Kafka启动时会从config/server.properties读取配置信息,其中Kafka Server启动的三个核心配置项为:
broker.id : broker的唯一标识符,取值为非负整数(可以取ip的最后一组) port : server监听客户端连接的端口(默认为9092) zookeeper.connect : ZK的连接信息,格式为hostname1:port1[,hostname2:port2,hostname3:port3] # 可选 log.dirs : Kafka数据存储的路径(默认为/tmp/kafka-logs),以逗号分割的一个或多个目录列表。 当有一个新partition被创建时,此时哪个目录中partition数目最少,则新创建的partition会被放 置到该目录。 num.partitions : Topic的partition数目(默认为1),可以在创建Topic时指定 # 其他参考http://kafka.apache.org/documentation.html#configuration
Kafka消息
kafka-console-producer.sh
kafka-console-consumer.sh
kafka-topics.sh
本文出自 “闷葫芦的世界” 博客,请务必保留此出处http://luchunli.blog.51cto.com/2368057/1712530
原文地址:http://luchunli.blog.51cto.com/2368057/1712530