kafka_2.9.2-0.8.1.1伪分布式集群安装

 

Kafka版本:kafka_2.9.2-0.8.1.1


官网:http://kafka.apache.org/
官方文档:http://kafka.apache.org/documentation.html#quickstart


下载解压

[root@rs229 ~]# wget -c -P /root http://mirrors.cnnic.cn/apache/kafka/0.8.1.1/kafka_2.9.2-0.8.1.1.tgz

# tar xzf kafka_2.9.2-0.8.1.1.tgz
# cd kafka_2.9.2-0.8.1.1


设置环境变量:

KAFKA_HOME=/usr/local/adsit/yting/apache/kafka/kafka_2.9.2-0.8.1.1

 


PATH=.:$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HBASE_HOME/bin:$ZOOKEEPER_HOME/bin:$HIVE_HOME/bin:$MAVEN_HOME/bin:$MAHOUT_HOME/bin:$SCALA_HOME/bin:$STORM_HOME/bin:$REDIS_HOME/bin:$FLUME_HOME/bin:$KAFKA_HOME/bin

 

 

启动自带的zookeeper,也可以不用

[root@rs229 kafka_2.9.2-0.8.1.1]#bin/zookeeper-server-start.sh config/zookeeper.properties &

启动kafka server,不使用自带的要注意修改zookeeper地址

[root@rs229 kafka_2.9.2-0.8.1.1]#bin/kafka-server-start.sh config/server.properties &

注意后台启动服务

 

使用介绍:
创建topic

[root@rs229 kafka_2.9.2-0.8.1.1]# bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test &

列出topic
[root@rs229 kafka_2.9.2-0.8.1.1]# bin/kafka-topics.sh --list --zookeeper localhost:2181

test

producer
# Send some messages (发送一些消息)
输入一条信息(Thisis a message: The you smile until forever),并且Ctrl+z退出shell
[root@rs229 kafka_2.9.2-0.8.1.1]# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
This is a message: The you smile until forever

comsumer
# Start a consumer(开启一个消费者)
输入命令之后打印出一些信息,最后面显示了刚刚输入的信息:Thisis a message: The you smile until forever
[root@rs229 kafka_2.9.2-0.8.1.1]# bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
This is a message: The you smile until forever


集群:多个brocker 整目录拷贝多份就可以了

cp config/server.properties config/server-1.properties
cp config/server.properties config/server-1.properties

新的配置

config/server-1.properties:
    broker.id=1
    port=9093
    log.dir=/tmp/kafka-logs-1

config/server-2.properties:
    broker.id=2
    port=9094
    log.dir=/tmp/kafka-logs-2

 

注意:真正集群要设置host.name和advertised.host.name这两个属性


启动

JMX_PORT=9997 bin/kafka-server-start.sh config/server-1.properties &
JMX_PORT=9998 bin/kafka-server-start.sh config/server-2.properties &
集群启动要加:JMX_PORT=


详细java api使用见:

https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+SimpleConsumer+Example

https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+Producer+Example

https://cwiki.apache.org/confluence/display/KAFKA/Consumer+Group+Example

 

 

你可能感兴趣的:(kafka)