下载地址:
http://kafka.apache.org/downloads
wget https://archive.apache.org/dist/kafka/2.1.0/kafka_2.11-2.1.0.tgz
cd /data1/soft/kafka_2.11-2.1.0
mkdir -p logs
[root@datanode4 config]# pwd
/data1/soft/kafka_2.11-2.1.0/config
修改配置文件server.properties:
broker.id=0
port=9092
log.dirs=/data1/soft/kafka_2.11-2.1.0/logs
zookeeper.connect=datanode4:2181,datanode5:2181,datanode6:2181
分发:
[root@datanode4 soft]# scp -r kafka_2.11-2.1.0/ root@datanode5:/data1/soft/
[root@datanode4 soft]# scp -r kafka_2.11-2.1.0/ root@datanode6:/data1/soft/
在datanode5上修改server.properties
broker.id=1
在datanode6上修改server.properties
broker.id=2
在每台机器上启动:
[root@datanode4 kafka_2.11-2.1.0]# ./bin/kafka-server-start.sh -daemon ./config/server.properties
[root@datanode5 kafka_2.11-2.1.0]# ./bin/kafka-server-start.sh -daemon ./config/server.properties
[root@datanode6 kafka_2.11-2.1.0]# ./bin/kafka-server-start.sh -daemon ./config/server.properties
创建topic
[root@datanode4 bin]# ./kafka-topics.sh --create --zookeeper datanode4:2181,datanode5:2181,datanode6:2181 --replication-factor 3 --partitions 3 --topic mytopic
Created topic "mytopic".
[root@datanode4 bin]# ./kafka-topics.sh --describe --zookeeper localhost:2181 --topic mytopic
Topic:mytopic PartitionCount:3 ReplicationFactor:3 Configs:
Topic: mytopic Partition: 0 Leader: 1 Replicas: 1,2,0 Isr: 1,2,0
Topic: mytopic Partition: 1 Leader: 2 Replicas: 2,0,1 Isr: 2,0,1
Topic: mytopic Partition: 2 Leader: 0 Replicas: 0,1,2 Isr: 0,1,2
[root@datanode4 bin]# ./kafka-topics.sh --list --zookeeper datanode4:2181
kafka的bin目录下启动生产者和消费者
./kafka-console-producer.sh --broker-list localhost:9092 --topic mytopic
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic mytopic