➜ sudo add-apt-repository ppa:webupd8team/java ➜ sudo apt-get update
安装oracle-java8-installer
➜ sudo apt-get install oracle-java8-installer
设置系统默认JDK
➜ sudo update-java-alternatives -s java-8-oracle
下载解压Kafka
➜ mkdir ~/Downloads & cd ~/Downloads ➜ wget http://mirrors.hust.edu.cn/apache/kafka/2.0.0/kafka_2.11-2.0.0.tgz ➜ mkdir ~/kafka && cd ~/kafka ➜ kafka tar -xvzf ~/Downloads/kafka_2.11-2.0.0.tgz --strip 1
允许Kafka删除主题
➜ vim ~/kafka/config/server.properties # 添加 delete.topic.enable=true
定义systemd
Zookeeper
➜ sudo vim /etc/systemd/system/zookeeper.service
[Unit] Requires=network.target remote-fs.target After=network.target remote-fs.target [Service] Type=simple User=zhongmingmao ExecStart=/home/zhongmingmao/kafka/bin/zookeeper-server-start.sh /home/zhongmingmao/kafka/config/zookeeper.properties ExecStop=/home/zhongmingmao/kafka/bin/zookeeper-server-stop.sh Restart=on-abnormal [Install] WantedBy=multi-user.target
Kafka
➜ sudo vim /etc/systemd/system/kafka.service
[Unit] Requires=zookeeper.service After=zookeeper.service [Service] Type=simple User=zhongmingmao ExecStart=/bin/sh -c '/home/zhongmingmao/kafka/bin/kafka-server-start.sh /home/zhongmingmao/kafka/config/server.properties > /home/zhongmingmao/kafka/kafka.log 2>&1' ExecStop=/home/zhongmingmao/kafka/bin/kafka-server-stop.sh Restart=on-abnormal [Install] WantedBy=multi-user.target
启动
➜ sudo systemctl start kafka ➜ sudo systemctl status kafka ● kafka.service Loaded: loaded (/etc/systemd/system/kafka.service; disabled; vendor preset: enabled) Active: active (running) since Mon 2018-10-08 01:52:40 UTC; 6s ago ➜ sudo systemctl status zookeeper ● zookeeper.service Loaded: loaded (/etc/systemd/system/zookeeper.service; disabled; vendor preset: enabled) Active: active (running) since Mon 2018-10-08 01:52:40 UTC; 1min 33s ago
查看日志
➜ journalctl -u kafka ➜ journalctl -u zookeeper
开机自启动
➜ sudo systemctl enable kafka Created symlink /etc/systemd/system/multi-user.target.wants/kafka.service → /etc/systemd/system/kafka.service.
添加环境变量
➜ vim ~/.zshrc # 添加 KAFKA_HOME="/home/zhongmingmao/kafka/" export PATH=$KAFKA_HOME/bin:$PATH ➜ source ~/.zshrc
测试功能
创建主题
➜ kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 1 --topic zhongmingmao Created topic "zhongmingmao". ➜ kafka-topics.sh --zookeeper localhost:2181 --list zhongmingmao
发送消息
➜ echo "hello, zhongmingmao" | kafka-console-producer.sh --broker-list localhost:9092 --topic zhongmingmao > /dev/null
读取消息
➜ kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic zhongmingmao --from-beginning hello, zhongmingmao
KafkaT
安装
➜ sudo apt install ruby ruby-dev build-essential ➜ sudo gem install kafkat
配置
➜ vim ~/.kafkatcfg
{ "kafka_path": "~/kafka", "log_path": "/tmp/kafka-logs", "zk_path": "localhost:2181" }
➜ kafkat partitions Topic Partition Leader Replicas ISRs zhongmingmao 0 0 [0] [0] __consumer_offsets 0 0 [0] [0]
集群
机器IP
- 172.16.143.133
- 172.16.143.134
- 172.16.143.135
创建数据目录
➜ mkdir -p ~/data/zookeeper && mkdir -p ~/data/kafka
配置Zookeeper
zookeeper.properties
➜ vim ~/kafka/config/zookeeper.properties
dataDir=/home/zhongmingmao/data/zookeeper clientPort=2181 maxClientCnxns=100 tickTime=2000 initLimit=10 syncLimit=5 server.1=172.16.143.133:2888:3888 server.2=172.16.143.134:2888:3888 server.3=172.16.143.135:2888:3888
新增myid
➜ echo 1 > ~/data/zookeeper/myid # 不同机器,数值为1、2、3
配置Kafka
➜ vim ~/kafka/config/server.properties # 修改下面配置 broker.id=0 # 不同机器,数值为0、1、2 listeners=PLAINTEXT://172.16.143.133:9092 # 机器IP zookeeper.connect=172.16.143.133:2181,172.16.143.134:2181,172.16.143.135:2181 # Zookeeper集群 log.dirs=/home/zhongmingmao/data/kafka
启动Kafka
➜ sudo systemctl start kafka ➜ jps 4997 Jps 4331 Kafka 4317 QuorumPeerMain
测试功能
创建主题
# Mac OS ➜ kafka-topics --zookeeper 172.16.143.133:2181,172.16.143.134:2181,172.16.143.135:2181 --create --replication-factor 1 --partitions 1 --topic zhongmingmao Created topic "zhongmingmao". ➜ kafka-topics --zookeeper 172.16.143.133:2181,172.16.143.134:2181,172.16.143.135:2181 --list zhongmingmao # --zookeeper 可以只列一个
发送消息
# Mac OS ➜ echo "hello, zhongmingmao" | kafka-console-producer --broker-list 172.16.143.133:9092,172.16.143.134:9092,172.16.143.135:9092, --topic zhongmingmao > /dev/null
读取消息
# Mac OS ➜ kafka-console-consumer --bootstrap-server 172.16.143.133:9092,172.16.143.134:9092,172.16.143.135:9092 --topic zhongmingmao --from-beginning hello, zhongmingmao
修改KafkaT
➜ vim ~/.kafkatcfg
{ "kafka_path": "/home/zhongmingmao/kafka", "log_path": "/home/zhongmingmao/data/kafka", "zk_path": "172.16.143.133:2181,172.16.143.134:2181,172.16.143.135:2181" }
➜ kafkat partitions Topic Partition Leader Replicas ISRs zhongmingmao 0 2 [2] [2] __consumer_offsets 0 1 [1] [1]
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 配置Hadoop集群JobHistoryServer
- Apache配置——支持JBoss集群
- 配置Hadoop集群客户端
- Consul 集群部署 + ACL 配置
- SLife 1.0 加入集群的配置和 Docker 化部署配置
- Mariadb之半同步复制集群配置
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
JAVASCRIPT语言精髓与编程实践
周爱民 / 电子工业出版社 / 2008-3 / 68.00元
《JAVASCRIPT语言精髓与编程实践》讲述了JavaScript的语言实现与扩展,主要包括以下三个方面的内容:(1)动态、函数式语言,以及其它语言特性在JavaScript的表现与应用;(2)如何用动态函数式语言的特性来扩展JavaScript的语言特性与框架;(3)如何将JavaScript引擎整合到其它高级语言的开发过程中。一起来看看 《JAVASCRIPT语言精髓与编程实践》 这本书的介绍吧!