- 安装
tar -xzf kafka_2.12-2.5.0.tgz
cd kafka_2.12-2.5.0
- 配置
broker.id=0
listeners=PLAINTEXT://:9092
log.dirs=/app/kafka_2.12-2.5.0/kafka-logs
zookeeper.connect=node-1:2181,node-2:2181,node-3:2181
- 启动
需要首先启动zookeeper服务后,在启动kafka服务,这里需要注意的是:我安装的版本是kafka_2.12-2.5.0,JDK版本是jdk1.8.0_11,一直起不来,后来差了资料说是需要更新jdk版本,然后重新安装了新的版本jdk1.8.0_251,重新启动还是报错,哭唧唧啊,重新查了资料,然后安装了一个库,重新启动,ok了。
sudo yum install glibc.i686
bin/zookeeper-server-start.sh config/zookeeper.properties
- 创建topic
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
- 查看topic是否创建成功
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
- 发送消息
> bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test
This is a message
This is another message
- 接收消息
> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
This is a message
This is another message
- 创建分布式Broker
cp config/server.properties config/server-1.properties
cp config/server.properties config/server-2.properties
分别写入内容
config/server-1.properties:
broker.id=1
listeners=PLAINTEXT://:9093
log.dirs=/tmp/kafka-logs-1
config/server-2.properties:
broker.id=2
listeners=PLAINTEXT://:9094
log.dirs=/tmp/kafka-logs-2
10 启动新创建的两台服务
bin/kafka-server-start.sh config/server-1.properties &
bin/kafka-server-start.sh config/server-2.properties &
- 新创建一个topic
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 3 --partitions 1 --topic my-replicated-topic
- 给新创建topic发送消息
bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic my-replicated-topic
...
my test message 1
my test message 2
- 消费新创建topic消息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic my-replicated-topic
至此kafka就安装完了,接下来需要对kafka内组件深入了解一下,毕竟只知道它强大,并不知道它怎么强大了 。