执行命令brew install kafka,结果报了如下提示:
Updating Homebrew…
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
angular-cli diffoscope ford liquibase pybind11
antibody dnstwist gitfs lsd ripgrep-all
aws-es-proxy dnsviz gitless mame subversion
balena-cli doctl go mockolo terragrunt
bat doitlive [email protected] moco tig
binwalk eralchemy godep monolith tomcat
borgmatic erlang googler netlify-cli vim
bumpversion exploitdb goolabs newrelic-cli weechat
composer eye-d3 gprof2dot node@10 xonsh
contentful-cli faas-cli grip node@12
cryptominisat fabric helmfile ocrmypdf
cxxtest fbi-servefiles homebank perl
deno fobis libdca puzzles
kafka: Java 1.8 is required to install this formula.
Install AdoptOpenJDK 8 with Homebrew Cask:
brew cask install homebrew/cask-versions/adoptopenjdk8
Error: An unsatisfied requirement failed this build.
从提示中,可以看出是缺少java1.8的jdk。于是执行命令brew cask install homebrew/cask-versions/java8,安装Java1.8的jdk,安装过程如下所示
==> Tapping homebrew/cask-versions
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-versions’…
remote: Enumerating objects: 227, done.
remote: Counting objects: 100% (227/227), done.
remote: Compressing objects: 100% (216/216), done.
remote: Total 227 (delta 17), reused 49 (delta 10), pack-reused 0
Receiving objects: 100% (227/227), 91.82 KiB | 79.00 KiB/s, done.
Resolving deltas: 100% (17/17), done.
Tapped 207 casks (246 files, 349.5KB).
==> Caveats
This Cask makes minor modifications to the JRE to prevent issues with
packaged applications, as discussed here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361
If your Java application still asks for JRE installation, you might need
to reboot or logout/login.
Installing java8 means you have AGREED to the license at
https://www.oracle.com/technetwork/java/javase/terms/license/index.html
==> Satisfying dependencies
==> Downloading https://download.oracle.com/otn-pub/java/jdk/8u192-b12/750e1c8617c5452694857ad95c3ee230/jdk-8u192-macosx-x64.dmg
==> Downloading from https://download.oracle.com/otn-pub/java/jdk/8u192-b12/750e1c8617c5452694857ad95c3ee230/jdk-8u192-macosx-x64.dmg?AuthParam=1540643090_5c9af33a69f03fb1455c1720498fa1e5
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask ‘java8’.
==> Installing Cask java8
==> Running installer for java8; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:
installer: Package name is JDK 8 Update 192
installer: Installing at base path /
installer: The install was successful.
java8 was successfully installed!
在安装完1.8版本jdk之后,再次执行命令brew install kafka,安装过程如下所示:
==> Installing dependencies for kafka: zookeeper
==> Installing kafka dependency: zookeeper
==> Downloading https://homebrew.bintray.com/bottles/zookeeper-3.4.13.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring zookeeper-3.4.13.high_sierra.bottle.tar.gz
==> Caveats
To have launchd start zookeeper now and restart at login:
brew services start zookeeper
Or, if you don’t want/need a background service you can just run:
zkServer start
==> Summary
? /usr/local/Cellar/zookeeper/3.4.13: 244 files, 33.4MB
==> Installing kafka
==> Downloading https://homebrew.bintray.com/bottles/kafka-2.0.0.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring kafka-2.0.0.high_sierra.bottle.tar.gz
==> Caveats
To have launchd start kafka now and restart at login:
brew services start kafka
Or, if you don’t want/need a background service you can just run:
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties & kafka-server-start /usr/local/etc/kafka/server.properties
==> Summary
? /usr/local/Cellar/kafka/2.0.0: 160 files, 46.8MB
==> Caveats
==> zookeeper
To have launchd start zookeeper now and restart at login:
brew services start zookeeper
Or, if you don’t want/need a background service you can just run:
zkServer start
==> kafka
To have launchd start kafka now and restart at login:
brew services start kafka
Or, if you don’t want/need a background service you can just run:
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties & kafka-server-start /usr/local/etc/kafka/server.properties
至此,mac上安装kafka的过程结束。
运行kafka是需要依赖于zookeeper的,所以安装kafka的时候也会包含zookeeper。
kafka的安装目录:/usr/local/Cellar/kafka/2.0.0/bin
kafka的配置文件目录:/usr/local/Cellar/kafka/2.0.0/bin
kafka服务的配置文件:/usr/local/etc/kafka/server.properties
zookeeper配置文件: /usr/local/etc/kafka/zookeeper.properties
broker.id=0
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://127.0.0.1:9092
log.dirs=/usr/local/var/lib/kafka-logs
dataDir=/usr/local/var/lib/zookeeper
clientPort=2181
maxClientCnxns=0
使用以下命令,就可以启动zookeeper和Kafka:
1.在执行各命令前,先转到kafka的bin目录,
cd /usr/local/Cellar/kafka/2.0.0/bin
2.首先,启动zookeeper:
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties
3.然后,启动Kafka:
kafka-server-start /usr/local/etc/kafka/server.properties
4.接下来,让我们创建一个“使用单个分区”、“只有一个副本”、名为“test”的主题的topic,
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
5.查看创建的topic,运行list topic命令:
kafka-topics --list --zookeeper localhost:2181
6.生产消息:
在命令行启动一个Kafka生产者,从文件或标准输入接收输入,并将其作为消息发送到Kafka集群。默认情况下,每行都将作为单独的消息发送。
kafka-console-producer --broker-list localhost:9092 --topic test
7.消费消息:
在命令行启动一个Kafka消费者,将消息转储到标准输出。
kafka-console-consumer --bootstrap-server localhost:9092 --topic test --from-beginning
8.如果想删除topic,可以使用如下命令:
kafka-topics --delete --zookeeper localhost:2181 --topic