歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

kafka+zookeeper環境配置(Mac 或者 linux環境)


kafka+zookeeper環境配置(Mac 或者 linux環境)

一.zookeeper下載與安裝
1)下載
adeMacBook-Pro:zookeeper_soft apple$ wget' target='_blank'>http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz[/code] 
2)解壓
tar zxvf zookeeper-3.4.6.tar.gz

3)配置
cd zookeeper-3.4.6

cp -rf conf/zoo_sample.cfg conf/zoo.cfg

vim zoo.cfg

zoo.cfg:

# 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


4)啟動zookeeper

adeMacBook-Pro:bin apple$ sh zkServer.sh start
JMX enabled by default
Using config: /Users/apple/Documents/soft/zookeeper_soft/zookeeper-3.4.6/bin/../conf/zoo.cfg
-n Starting zookeeper ... 
STARTED
adeMacBook-Pro:bin apple$ ps ax| grep zookeeper.out 
10311 s003  S+     0:00.01 grep zookeeper.out
adeMacBook-Pro:bin apple$ ps ax| grep zookeeper
10307 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


二 下載並且安裝kafka(預先得安裝配置好scala的環境,Mac環境參照:http://www.cnblogs.com/super-d2/p/4534208.html)
1).下載kafka:
wget' target='_blank'>http://apache.fayea.com/kafka/0.8.2.1/kafka_2.10-0.8.2.1.tgz[/code] 
2) 解壓:
tar -zxf kafka_2.10-0.8.2.1.tgz

3)啟動kafka
adeMacBook-Pro:kafka_2.10-0.8.2.1 apple$ sh bin/kafka-server-start.sh config/server.properties
備注:要掛到後台使用:
sh bin/kafka-server-start.sh config/server.properties &

4)新建一個TOPIC
adeMacBook-Pro:bin apple$ sh kafka-topics.sh --create --topic kafkatopic --replication-factor 1 --partitions 1 --zookeeper localhost:2181

備注:要掛到後台使用:
sh kafka-topics.sh --create --topic kafkatopic --replication-factor 1 --partitions 1 --zookeeper localhost:2181 &

5) 把KAFKA的生產者啟動起來:
adeMacBook-Pro:bin apple$ sh kafka-console-producer.sh --broker-list localhost:9092 --sync --topic kafkatopic

備注:要掛到後台使用:
sh kafka-console-producer.sh --broker-list localhost:9092 --sync --topic kafkatopic &

6)另開一個終端,把消費者啟動起來:
adeMacBook-Pro:bin apple$ sh kafka-console-consumer.sh --zookeeper localhost:2181 --topic kafkatopic --from-beginning

備注:要掛到後台使用:
sh kafka-console-consumer.sh --zookeeper localhost:2181 --topic kafkatopic --from-beginning &

7)使用
在發送消息的終端輸入aaa,則可以在消費消息的終端顯示,如下圖所示:
Copyright © Linux教程網 All Rights Reserved