Kafka -- 集群安装与配置(Ubuntu)
单节点
安装Java
添加ppa
1 | $ sudo add-apt-repository ppa:webupd8team/java |
安装oracle-java8-installer
1 | $ sudo apt-get install oracle-java8-installer |
设置系统默认JDK
1 | $ sudo update-java-alternatives -s java-8-oracle |
下载解压Kafka
1 | $ mkdir ~/Downloads & cd ~/Downloads |
允许Kafka删除主题
1 | $ vim ~/kafka/config/server.properties |
定义systemd
Zookeeper
1 | $ sudo vim /etc/systemd/system/zookeeper.service |
1 | [Unit] |
Kafka
1 | $ sudo vim /etc/systemd/system/kafka.service |
1 | [Unit] |
启动
1 | $ sudo systemctl start kafka |
查看日志
1 | $ journalctl -u kafka |
开机自启动
1 | $ sudo systemctl enable kafka |
添加环境变量
1 | $ vim ~/.zshrc |
测试功能
创建主题
1 | $ kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 1 --topic zhongmingmao |
发送消息
1 | $ echo "hello, zhongmingmao" | kafka-console-producer.sh --broker-list localhost:9092 --topic zhongmingmao > /dev/null |
读取消息
1 | $ kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic zhongmingmao --from-beginning |
KafkaT
安装
1 | $ sudo apt install ruby ruby-dev build-essential |
配置
1 | $ vim ~/.kafkatcfg |
1 | { |
1 | $ kafkat partitions |
集群
机器IP
- 172.16.143.133
- 172.16.143.134
- 172.16.143.135
创建数据目录
1 | $ mkdir -p ~/data/zookeeper && mkdir -p ~/data/kafka |
配置Zookeeper
zookeeper.properties
1 | $ vim ~/kafka/config/zookeeper.properties |
1 | dataDir=/home/zhongmingmao/data/zookeeper |
新增myid
1 | $ echo 1 > ~/data/zookeeper/myid # 不同机器,数值为1、2、3 |
配置Kafka
1 | $ vim ~/kafka/config/server.properties |
启动Kafka
1 | $ sudo systemctl start kafka |
测试功能
创建主题
1 | # Mac OS |
发送消息
1 | # Mac OS |
读取消息
1 | # Mac OS |
修改KafkaT
1 | $ vim ~/.kafkatcfg |
1 | { |
1 | $ kafkat partitions |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.