[root@localhost kafka_2.11-1.0.0]# wget http://mirrors.shuosc.org/apache/kafka/1.0.0/kafka_2.11-1.0.0.tgz
[root@localhost kafka_2.11-1.0.0]# cd kafka_2.11-1.0.0/
#启动zookeeper
[root@localhost kafka_2.11-1.0.0]# bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
#启动kafka
[root@localhost kafka_2.11-1.0.0]# bin/kafka-server-start.sh -daemon config/server.properties
root@localhost kafka_2.11-1.0.0]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 989/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1095/master
tcp6 0 0 :::38544 :::* LISTEN 1692/java
tcp6 0 0 :::22 :::* LISTEN 989/sshd
tcp6 0 0 :::38489 :::* LISTEN 2278/java
tcp6 0 0 ::1:25 :::* LISTEN 1095/master
tcp6 0 0 :::9092 :::* LISTEN 2278/java
tcp6 0 0 :::2181 :::* LISTEN 1692/java
[root@localhost kafka_2.11-1.0.0]# bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic mytopic
Created topic "mytopic".
[root@localhost kafka_2.11-1.0.0]# bin/kafka-topics.sh --list --zookeeper localhost:2181
mytopic
[root@localhost kafka_2.11-1.0.0]# bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic mytopic
Topic:mytopic PartitionCount:1 ReplicationFactor:1 Configs:
Topic: mytopic Partition: 0 Leader: 0 Replicas: 0 Isr: 0
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic mytopic
[root@localhost kafka_2.11-1.0.0]# bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic mytopic --from-beginning
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
hello
#首先运行一个脚本每隔一段时间追加一个数字
[root@localhost kafka_2.11-1.0.0]# for i in {1..300};do echo $i >> test.txt; sleep 1; done
#根据配置文件connect-file-source.properties
里面的源文件填写file=test.txt,connect-file-sink.propertiest为file=test.sink.txt
#从一个文件中读取输入到另一个文件
[root@localhost kafka_2.11-1.0.0]# bin/connect-standalone.sh -daemon config/connect-standalone.properties config/connect-file-source.properties config/connect-file-sink.properties
#查看另一个文件
[root@localhost kafka_2.11-1.0.0]# tail -f test.sink.txt
1
2
3
4
5
6
7
8
9
[root@localhost kafka_2.11-1.0.0]# bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic connect-test
Topic:connect-test PartitionCount:1 ReplicationFactor:1 Configs:
Topic: connect-test Partition: 0 Leader: 0 Replicas: 0 Isr: 0