一、 安装zookeeper:
Zookeeper安装
1. 安装wget http://www.apache.org/dist//zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz
2 tar zxvf zookeeper-3.3.6.tar.gz
3 cd zookeeper-3.3.6
4 cp conf/zoo_sample.cfg conf/zoo.cfg
启动:
5 ./bin/zkServer.sh start
停止:
6 ./bin/zkServer.sh stop
简单操作:
./bin/zkCli.sh -server 127.0.0.1:2181
[zk: 127.0.0.1:2181(CONNECTED) 2] create /test "hello"
Created /test
[zk: 127.0.0.1:2181(CONNECTED) 3] get /test
"hello"
cZxid = 0x8
ctime = Wed Dec 28 10:03:24 CST 2016
mZxid = 0x8
mtime = Wed Dec 28 10:03:24 CST 2016
pZxid = 0x8
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0
|
二、安装kafka
2 tar zxvf kafka_2.11-0.10.1.0.tgz
3 cd kafka_2.11-0.10.1.0
4 bin/kafka-server-start.sh config/server.properties
5 Create a topic:
# bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
Created topic "test".
# bin/kafka-topics.sh --list --zookeeper localhost:2181
test
Step 4: Send some messages
Kafka comes with a command line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. By default, each line will be sent as a separate message.
Run the producer and then type a few messages into the console to send to the server.
> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
This is a message
This is another message
Step 5: Start a consumer
Kafka also has a command line consumer that will dump out messages to standard output.
> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
This is a message
This is another message
If you have each of the above commands running in a different terminal then you should now be able to type messages into the producer terminal and see them appear in the consumer terminal.
All of the command line tools have additional options; running the command with no arguments will display usage information documenting them in more detail.
|