1.先配置好zookeeper集群(可以看zookeeper集群搭建)
2.三个kafka机器
10.1.44.186 kafka(9092) zookeeper(2181)
10.1.44.187 kafka(9092) zookeeper(2181)
10.1.44.188 kafka(9092) zookeeper(2181)
vim /etc/hosts -------------- 10.1.44.186 server186 10.1.44.187 server187 10.1.44.188 server188
3.安装创建日志目录
rz tar zxf kafka_2.11-0.9.0.0.tgz mv kafka_2.11-0.9.0.0 /usr/local/kafka cd /usr/local/kafka/ mkdir log ll 总用量 36 drwxr-xr-x 3 root root 4096 11月 21 2015 bin drwxr-xr-x 2 root root 4096 11月 21 2015 config drwxr-xr-x 2 root root 4096 3月 19 15:06 libs -rw-r--r-- 1 root root 11358 11月 21 2015 LICENSE drwxr-xr-x 2 root root 4096 3月 19 15:06 log # 新创建的日志目录 -rw-r--r-- 1 root root 162 11月 21 2015 NOTICE drwxr-xr-x 2 root root 4096 11月 21 2015 site-docs
4.修改配置文件(修改标准说明项)
cd /usr/local/kafka vim config/server.properties ---------------------------- broker.id=0 # 唯一的,每个server配置独立不重复的值 listeners=PLAINTEXT://:9092 port=9092 # 开启端口 advertised.host.name=10.1.44.188 # 开启主机地址,每个server填写自己的ip num.network.threads=3 num.io.threads=8 socket.send.buffer.bytes=102400 socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 log.dirs=/usr/local/kafka/log # 日志目录,要先创建 num.partitions=1 num.recovery.threads.per.data.dir=1 log.retention.hours=168 log.segment.bytes=1073741824 log.retention.check.interval.ms=300000 log.cleaner.enable=false zookeeper.connect=10.1.44.186:2181,10.1.44.187:2181,10.1.44.188:2181 # 配置zookeeper集群地址 zookeeper.connection.timeout.ms=6000
5.启动
cd /usr/local/kafka bin/kafka-server-start.sh config/server.properties & cd /usr/local/kafka bin/kafka-server-start.sh -daemon config/server.properties & jps(三个机器应该是一样的进程) --------- 20744 Jps 20651 Kafka 31150 QuorumPeerMain
6.创建topic
cd /usr/local/kafka bin/kafka-topics.sh --create --zookeeper 10.1.44.186:2181,10.1.44.187:2181,10.1.44.188:2181 --partitions 3 --replication-factor 2 --topic test0320
7.查看Topic的状态
cd /usr/local/kafka bin/kafka-topics.sh --describe --zookeeper 10.1.44.186:2181,10.1.44.187:2181,10.1.44.188:2181 --topic test0320 Topic: test0320 PartitionCount:3 ReplicationFactor:2 Configs: Topic: test0320 Partition: 0 Leader: 1 Replicas: 1,0 Isr: 1,0 Topic: test0320 Partition: 1 Leader: 2 Replicas: 2,1 Isr: 2,1 Topic: test0320 Partition: 2 Leader: 0 Replicas: 0,2 Isr: 0,2
8.简单客户端测试
# 生产者 cd /usr/local/kafka bin/kafka-console-producer.sh --broker-list 10.1.44.186:9092 --topic test0320 cd /usr/local/kafka bin/kafka-console-producer.sh --broker-list 10.1.44.187:9092 --topic test0320 cd /usr/local/kafka bin/kafka-console-producer.sh --broker-list 10.1.44.188:9092 --topic test0320 cd /usr/local/kafka bin/kafka-console-producer.sh --broker-list 10.1.44.186:9092,10.1.44.187:9092,10.1.44.188:9092 --topic test0320 # 消费者 cd /usr/local/kafka bin/kafka-console-consumer.sh --zookeeper 10.1.44.186:2181,10.1.44.187:2181,10.1.44.188:2181 --topic test0320 --from-beginning