kafka安装
创建用户和组
1
2[root@localhost java]# groupadd kafka
[root@localhost java]# useradd kafka下载安装软件
1
2[root@localhost java]# su - kafak
[kafka@localhost ~]$ wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.4.1/kafka_2.12-2.4.1.tgz解压与配置
- 解压
1
[kafka@localhost ~]$ tar zxvf kafka_2.12-2.4.1.tgz
- 设置环境变量
1
2
3[kafka@localhost ~]$ vim ~/.bash_profile
export KAFKA_HOME=/home/kafka/kafka_2.12-2.4.1
PATH=${KAFKA_HOME}/bin:$PATH- 创建配置文件目录
1
[kafka@localhost kafka_2.12-2.4.1]$ mkdir myconfig
- 复制配置文件
1
2
3[kafka@localhost kafka_2.12-2.4.1]$ cp config/server.properties myconfig/server-1.properties
[kafka@localhost kafka_2.12-2.4.1]$ cp config/server.properties myconfig/server-2.properties
[kafka@localhost kafka_2.12-2.4.1]$ cp config/server.properties myconfig/server-3.properties- 修改配置文件
节点1
1
2
3
4broker.id=1
listeners=PLAINTEXT://xxx.xxx.xxx.xxx:9092
log.dirs=/home/kafka/kafka_2.12-2.4.1/kafka-logs/server-1
zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183节点2
1
2
3
4broker.id=2
listeners=PLAINTEXT://xxx.xxx.xxx.xxx:9093
log.dirs=/home/kafka/kafka_2.12-2.4.1/kafka-logs/server-2
zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183节点3
1
2
3
4broker.id=3
listeners=PLAINTEXT://xxx.xxx.xxx.xxx:9094
log.dirs=/home/kafka/kafka_2.12-2.4.1/kafka-logs/server-3
zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183server启动
1
2
3bin/kafka-server-start.sh -daemon myconfig/server-1.properties
bin/kafka-server-start.sh -daemon myconfig/server-2.properties
bin/kafka-server-start.sh -daemon myconfig/server-3.properties创建topic
1
2
3
4
bin/kafka-topics.sh --create --zookeeper xxx.xxx.xxx.xxx:2181 --replication-factor 3 --partitions 1 --topic test-topic
/usr/local/kafka/bin/kafka-topics.sh --describe --zookeeper xxx.xxx.xxx.xxx:2181 --topic test-topic生产者消费者测试
1
bin/kafka-console-producer.sh --broker-list 192.168.128.139:9092 --topic test-topic
1
bin/kafka-console-consumer.sh --bootstrap-server xxx.xxx.xxx.xxx:9092 --topic test-topic --from-beginning