下載地址:http://kafka.apache.org/downloadsshell
安裝JDK:CentOS安裝JDKapache
安裝ZooKeeper:CentOS安裝ZooKeeperbootstrap
shell> tar -zxvf kafka_2.12-2.2.0.tgz -C /usr/local/
shell> cd /usr/local/kafka_2.12-2.2.0/config shell> vim server.properties
編輯如下內容vim
# 默認爲/tmp/kafka-logs,可能會被刪掉 log.dirs=/usr/local/kafka_2.12-2.2.0/logs # 監聽地址,ifconfig查看到的本機真實地址,單節點不配置也能夠 listeners=PLAINTEXT://192.168.1.10:9092 # 打開註釋,設置爲對外可訪問的地址,能夠是主機名,也能夠是ip地址,但必定是鏈接kafka的其餘機器能夠訪問到的地址,簡單來講就是「容許遠程鏈接」 # 若是是局域網(內網、阿里雲騰訊雲的vpc等),直接設置成局域網ip就行了 # 若是是雲主機而且直接經過外網訪問kafka(通常不這麼作,可是若是這麼作了),須要設置成彈性ip或綁定的域名 # advertised.listeners=PLAINTEXT://tianranll.cn:9092 advertised.listeners=PLAINTEXT://192.168.1.10:9092 # zookeeper地址及端口號 # 若是是集羣,多是這樣:hostname1:port1,hostname2:port2,hostname3:port3 # 若是是帶有chroot:hostname1:port1,hostname2:port2,hostname3:port3/chroot/path zookeeper.connect=192.168.1.10:2181
shell> cd /usr/local/kafka_2.12-2.2.0 shell> bin/kafka-server-start.sh -daemon config/server.properties
若是使用kafka-manager,須要開啓JMX_PORTsegmentfault
shell> JMX_PORT=9999 bin/kafka-server-start.sh -daemon config/server.properties
shell> bin/kafka-server-stop.sh
cd /usr/local/zookeeper-3.5.3-beta/ bin/zkCli.sh [zk: localhost:2181(CONNECTED) 0] ls /brokers/ids [0] [zk: localhost:2181(CONNECTED) 1] get /brokers/ids/0 {"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT"},"endpoints":["PLAINTEXT://VM_2_24_centos:9092"],"jmx_port":-1,"host":"VM_2_24_centos","timestamp":"1585396767598","port":9092,"version":4}
shell> bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
shell> bin/kafka-topics.sh --list --bootstrap-server localhost:9092 test
shell> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test >Hello >World
shell> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning Hello World