系统
[root@kafka ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
安装jdk
yum install java -y
安装zookeeper
下载zookeeper
https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
[root@kafka ~]# ls -l
总用量 22196
-rw-------. 1 root root 1329 4月 8 10:52 anaconda-ks.cfg
-rwxr-xr-x 1 root root 22724574 4月 8 22:43 zookeeper-3.4.9.tar.gz
[root@kafka ~]# tar -zvxf zookeeper-3.4.9.tar.gz
配置zookeeper文件
cat > /usr/local/zookeeper/conf/zoo.cfg <<EOF
> tickTime=2000
> dataDir=/var/lib/zookeeper
> clientPort=2181
> EOF
启动zookeeper
[root@kafka ~]# /usr/local/zookeeper/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
校验zookeeper
[root@kafka ~]# netstat -tlnp
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 1011/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1229/master
tcp6 0 0 :::22 :::* LISTEN 1011/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1229/master
tcp6 0 0 :::46336 :::* LISTEN 1347/java
tcp6 0 0 :::2181 :::* LISTEN 1347/java
[root@kafka ~]# telnet localhost 2181
Trying ::1...
Connected to localhost.
Escape character is '^]'.
^CConnection closed by foreign host.
[root@kafka ~]# srvr
-bash: srvr: 未找到命令
[root@kafka ~]# telnet localhost 2181
Trying ::1...
Connected to localhost.
Escape character is '^]'.
srvr
Zookeeper version: 3.4.9-1757313, built on 08/23/2016 06:50 GMT
Latency min/avg/max: 0/0/0
Received: 1
Sent: 0
Connections: 1
Outstanding: 0
Zxid: 0x0
Mode: standalone
Node count: 4
Connection closed by foreign host.
安装kafka
http://mirrors.shu.edu.cn/apache/kafka/1.1.0/kafka_2.11-1.1.0.tgz
解压kafka
[root@kafka ~]# ls -l
总用量 22196
-rw-------. 1 root root 1329 4月 8 10:52 anaconda-ks.cfg
-rwxr-xr-x 1 root root 22724574 4月 8 22:43 zookeeper-3.4.9.tar.gz
[root@kafka ~]# mkdir -p /tmp/kafka-logs
[root@kafka ~]# tar -zxvf kafka_2.11-1.1.0.tgz
启动kafka
/usr/local/kafka/bin/kafka-server-start.sh -daemon
[root@kafka ~]# /usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties
[root@kafka ~]# netstat -tlnp
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 1011/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1229/master
tcp6 0 0 :::22 :::* LISTEN 1011/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1229/master
tcp6 0 0 :::39198 :::* LISTEN 1916/java
tcp6 0 0 :::46336 :::* LISTEN 1347/java
tcp6 0 0 :::9092 :::* LISTEN 1916/java
tcp6 0 0 :::2181 :::* LISTEN 1347/java
测试kafka
[root@kafka ~]# /usr/local/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Created topic "test".
[root@kafka ~]# /usr/local/kafka/bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic test
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Topic:test PartitionCount:1 ReplicationFactor:1 Configs:
Topic: test Partition: 0 Leader: 0 Replicas: 0 Isr: 0
[root@kafka ~]# /usr/local/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
>Test Message 1
>Test Message 2
>[root@kafka ~]# ^C
[root@kafka ~]# /usr/local/kafka/bin/kafka-con
kafka-configs.sh kafka-console-consumer.sh kafka-console-producer.sh kafka-consumer-groups.sh kafka-consumer-perf-test.sh
[root@kafka ~]# /usr/local/kafka/bin/kafka-con
kafka-configs.sh kafka-console-consumer.sh kafka-console-producer.sh kafka-consumer-groups.sh kafka-consumer-perf-test.sh
[root@kafka ~]# /usr/local/kafka/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
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].
Test Message 1
Test Message 2
^CProcessed a total of 2 messages
end