一、基础条件
二、kafka单节点安装
[root@xiangys0134-docker-01 tmp]# tar -zxvf kafka_2.11-2.3.1.tgz -C /usr/local/
[root@xiangys0134-docker-01 tmp]# cd /usr/local/kafka_2.11-2.3.1/config/
[root@xiangys0134-docker-01 config]# cp server.properties server.propertiesbak
[root@xiangys0134-docker-01 config]# vim server.properties
broker.id=0
listeners=PLAINTEXT://192.168.10.45:9092
zookeeper.connect=localhost:2181
三、配置用户
[root@xiangys0134-docker-01 ~]# useradd kafka
[root@xiangys0134-docker-01 ~]# passwd kafka
[root@xiangys0134-docker-01 ~]# chown -R kafka. /usr/local/kafka_2.11-2.3.1
四、 配置环境变量
[root@xiangys0134-docker-01 ~]# vim /etc/profile
export KAFKA_HOME=/usr/local/kafka_2.11-2.3.1
export PATH=PATH:KAFKA_HOME/bin
[root@xiangys0134-docker-01 ~]# vim /home/kafka/.bashrc
export KAFKA_HOME=/usr/local/kafka_2.11-2.3.1
export PATH=PATH:KAFKA_HOME/bin
[root@xiangys0134-docker-01 ~]# source /etc/profile
五、启动kafka服务
[root@xiangys0134-docker-01 tmp]# su - kafka -c 'nohup /usr/local/kafka_2.11-2.3.1/bin/kafka-server-start.sh /usr/local/kafka_2.11-2.3.1/config/server.properties &'
[root@xiangys0134-docker-01 tmp]# ss -tunlp|grep 9092
tcp LISTEN 0 50 192.168.10.45:9092 *:* users:(("java",pid=20169,fd=113))
六、创建一个topic
[root@xiangys0134-docker-01 tmp]# kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
Created topic test.
[root@xiangys0134-docker-01 tmp]# kafka-topics.sh --list --zookeeper localhost:2181 //查看
test
七、发送消息
[root@xiangys0134-docker-01 tmp]# kafka-console-producer.sh --broker-list 192.168.10.45:9092 --topic test
>This is a message
>This is another message
八、启动消费者
[kafka@xiangys0134-docker-01 ~]$ kafka-console-consumer.sh --bootstrap-server 192.168.10.45:9092 --topic test --from-beginning
留言