Kafka Mac下配置运行

安装zookeeper

  • 安装kafka前需要先安装zookeeper
  • 安装步骤
    • 下载wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
    • 解压 tar -zxvf zookeeper-3.4.6.tar.gz
    • 配置
      1
      2
      3
      4
      cd zookeeper-3.4.6
      cp -rf conf/zoo_sample.cfg conf/zoo.cfg
      vim zoo.cfg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/Users/apple/Documents/soft/zookeeper_soft/zkdata #这个目录是预先创建的
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
  • 启动zookeeper
    1
    sh zkServer.sh start

安装kafka

  • 下载kafka

    1
    wget http://apache.fayea.com/kafka/0.8.2.1/kafka_2.10-0.8.2.1.tgz
  • 解压

    1
    tar -zxf kafka_2.10-0.8.2.1.tgz
  • 启动

    1
    sh bin/kafka-server-start.sh config/server.properties
  • 新建一个TOPIC

    1
    sh kafka-topics.sh --create --topic kafkatopic --replication-factor 1 --partitions 1 --zookeeper localhost:2181
  • 把KAFKA的生产者启动起来

    1
    sh kafka-console-producer.sh --broker-list localhost:9092 --sync --topic kafkatopic
  • 另开一个终端,把消费者启动起来

    1
    bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
  • 在发送消息的终端输(生产者)入aaa,则可以在消费消息的终端显示

  • 发送消息

    1
    bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
  • 查看消息

    1
    bin/kafka-topics.sh --list --zookeeper localhost:2181