一.zookeeper下载与安装
1)下载
1
2 1adeMacBook-Pro:zookeeper_soft apple$ wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
2
2)解压
1
2 1tar zxvf zookeeper-3.4.6.tar.gz
2
3)配置
1
2
3 1cd zookeeper-3.4.6
2cp -rf conf/zoo_sample.cfg conf/zoo.cfg
3
1
2 1vim zoo.cfg
2
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
29 1# The number of milliseconds of each tick
2tickTime=2000
3# The number of ticks that the initial
4# synchronization phase can take
5initLimit=10
6# The number of ticks that can pass between
7# sending a request and getting an acknowledgement
8syncLimit=5
9# the directory where the snapshot is stored.
10# do not use /tmp for storage, /tmp here is just
11# example sakes.
12dataDir=/Users/apple/Documents/soft/zookeeper_soft/zkdata #这个目录是预先创建的
13# the port at which the clients will connect
14clientPort=2181
15# the maximum number of client connections.
16# increase this if you need to handle more clients
17#maxClientCnxns=60
18#
19# Be sure to read the maintenance section of the
20# administrator guide before turning on autopurge.
21#
22# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
23#
24# The number of snapshots to retain in dataDir
25#autopurge.snapRetainCount=3
26# Purge task interval in hours
27# Set to "0" to disable auto purge feature
28#autopurge.purgeInterval=1
29
4)启动zookeeper
1
2
3
4
5
6
7
8
9
10 1adeMacBook-Pro:bin apple$ sh zkServer.sh start
2JMX enabled by default
3Using config: /Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../conf/zoo.cfg
4-n Starting zookeeper ...
5STARTED
6adeMacBook-Pro:bin apple$ ps ax| grep zookeeper.out
710311 s003 S+ 0:00.01 grep zookeeper.out
8adeMacBook-Pro:bin apple$ ps ax| grep zookeeper
910307 s003 S 0:00.63 /usr/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../build/classes:/Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../build/lib/*.jar:/Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../conf/zoo.cfg
10
二 下载并且
安装kafka
1).下载kafka:
1
2 1wget http://apache.fayea.com/kafka/0.8.2.1/kafka_2.10-0.8.2.1.tgz
2
1
2
3
4
5
6
7 1http://apache.dataguru.cn/kafka/0.9.0.0/kafka_2.10-0.9.0.0.tgz
2http://apache.fayea.com/kafka/0.9.0.0/kafka_2.10-0.9.0.0.tgz
3http://mirror.bit.edu.cn/apache/kafka/0.9.0.0/kafka_2.10-0.9.0.0.tgz
4http://mirrors.cnnic.cn/apache/kafka/0.9.0.0/kafka_2.10-0.9.0.0.tgz
5http://mirrors.hust.edu.cn/apache/kafka/0.9.0.0/kafka_2.10-0.9.0.0.tgz
6
7
-
解压:
1
2 1tar -zxf kafka_2.10-0.8.2.1.tgz
2
3)启动kafka
adeMacBook-Pro:kafka_2.10-0.8.2.1 apple$ sh bin/kafka-server-start.sh config/server.properties
备注:要挂到后台使用:
1
2 1sh bin/kafka-server-start.sh config/server.properties &
2
4)新建一个TOPIC
1
2 1adeMacBook-Pro:bin apple$ sh kafka-topics.sh --create --topic kafkatopic --replication-factor 1 --partitions 1 --zookeeper localhost:2181
2
备注:要挂到后台使用:
1
2 1sh kafka-topics.sh --create --topic kafkatopic --replication-factor 1 --partitions 1 --zookeeper localhost:2181 &
2
-
把KAFKA的生产者启动起来:
1
2 1adeMacBook-Pro:bin apple$ sh kafka-console-producer.sh --broker-list localhost:9092 --sync --topic kafkatopic
2
备注:要挂到后台使用:
1
2 1sh kafka-console-producer.sh --broker-list localhost:9092 --sync --topic kafkatopic &
2
6)另开一个终端,把消费者启动起来:
1
2 1adeMacBook-Pro:bin apple$ sh kafka-console-consumer.sh --zookeeper localhost:2181 --topic kafkatopic --from-beginning
2
备注:要挂到后台使用:
1
2 1sh kafka-console-consumer.sh --zookeeper localhost:2181 --topic kafkatopic --from-beginning &
2
7)使用
- 在发送消息的终端输入aaa,则可以在消费消息的终端显示,如下图所示:
kafka+zookeeper环境配置(Mac 或者 linux环境)