【资源】 http://www.cnblogs.com/likehua/p/3999538.html
准备工作:kafka的运行需要依赖java和zookeeper,所以要提前准备java和zookeeper环境,另外就是kafka的tar包了
【1】解压
tar -xzvf kafka-0.9.2.tar.gz
mv kafka-0.9.2 /usr/local/
【2】配置环境变量&修改kafka配置
path配置
export KAFKA_HOME=/usr/local/kafka-0.9.2
export PATH = $KAFKA_HOME/bin:$PATH
kafka配置
############################# Server Basics #############################
# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
############################# Socket Server Settings #############################
listeners=PLAINTEXT://:9092
# 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
# 添加此配置
advertised.host.name=127.0.0.1(或者具体的本机ip)
advertised.port=9092
# 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>
【3】安装启动
#先启动kafka自带的zookeeper(当然这里也可以启动自己安装的zookeeper)
./zookeeper-server-start.sh -daemon ../config/zookeeper.properties
#启动kafka服务
./kafka-server-start.sh -daemon ../config/server.properties
#创建一个主题
./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic ARF
#创建一个消费者
./kafka-console-consumer.sh --zookeeper localhost:2181 --topic ARF --from-beginning
#创建一个新消费者(支持0.9版本+)
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic ARF --new-consumer --from-beginning --consumer.config ../config/consumer.properties
#创建一个生产者
./kafka-console-producer.sh --broker-list localhost:9092 --topic ARF
#创建一个新生产者(支持0.9版本+)
./kafka-console-producer.sh --broker-list localhost:9092 --topic ARF --producer.config ../config/producer.properties
相关命令请浏览:http://orchome.com/454