1.先配置好zookeeper集羣(能夠看zookeeper集羣搭建)vim
2.三個kafka機器bash
10.1.44.186 kafka(9092) zookeeper(2181)socket
10.1.44.187 kafka(9092) zookeeper(2181)ide
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.安裝建立日誌目錄spa
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.修改配置文件(修改標準說明項).net
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.建立topicserver
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