RabbitMQ和Kafka:Mac安装教程

本文将简单介绍如何在mac上安装RabbitMQ和Kafka,没有任何理论知识的介绍,完全是安装步骤分享。

如果要看如何在windows上安装,请移步另一篇文章

RabbitMQ和Kafka:Win10安装教程

1. 安装brew

brew 全称Homebrew 是Mac OSX上的软件包管理工具,通过brew的简单的命令,我们可以简单的安装和卸载软件

1.1 安装brew

打开终端,输入以下命令,然后一步步按照提示输入开机密码即可。

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

安装过程如下

renaissance$ /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

              开始执行Brew自动安装程序
             [cunkai.wang@foxmail.com]
           [2020-06-13 09:26:49][10.14]
       https://zhuanlan.zhihu.com/p/111014448


请选择一个下载镜像,例如中科大,输入1回车。
源有时候不稳定,如果git克隆报错重新运行脚本选择源。cask非必须,有部分人需要。
1、中科大下载源 2、清华大学下载源 3、腾讯下载源(不稳定) 4、阿里巴巴下载源(缺少cask源)
请输入序号: 1

  你选择了中国科学技术大学下载源

此脚本将要删除之前的brew(包括它下载的软件),请自行备份。
->是否现在开始执行脚本(N/Y)Y

--> 脚本开始执行
==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹
(设置开机密码:在左上角苹果图标->系统偏好设置->"用户与群组"->更改密码)
(如果提示This incident will be reported. 在"用户与群组"中查看是否管理员)
请输入开机密码,输入过程不显示,输入完后回车
Password:
-> 创建文件夹 /usr/local/Homebrew
此步骤成功
-> 创建文件夹 /usr/local/Caskroom
此步骤成功
-> 创建文件夹 /usr/local/Cellar
此步骤成功
-> 创建文件夹 /usr/local/var/homebrew
此步骤成功
-> 创建文件夹 /usr/local/etc
此步骤成功
-> 创建文件夹 /usr/local/sbin
此步骤成功
-> 创建文件夹 /usr/local/opt
此步骤成功
-> 创建文件夹 /usr/local/share/zsh
此步骤成功
-> 创建文件夹 /usr/local/share/zsh/site-functions
此步骤成功
-> 创建文件夹 /usr/local/var/homebrew/linked
此步骤成功
-> 创建文件夹 /usr/local/Frameworks
此步骤成功
git version 2.18.0

下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源
==> 克隆Homebrew基本文件(32M+)

未发现Git代理(属于正常状态)
Cloning into '/usr/local/Homebrew'...
remote: Enumerating objects: 138610, done.
remote: Total 138610 (delta 0), reused 0 (delta 0) | 1.02 MiB/s      
Receiving objects: 100% (138610/138610), 33.81 MiB | 988.00 KiB/s, done.
Resolving deltas: 100% (102221/102221), done.
此步骤成功
==> 创建brew的替身
此步骤成功
==> 克隆Homebrew Core(224M+) 
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 732718, done.
remote: Total 732718 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (732718/732718), 237.22 MiB | 575.00 KiB/s, done.
Resolving deltas: 100% (488152/488152), done.
Checking out files: 100% (5290/5290), done.
此步骤成功
==> 克隆Homebrew Cask(248M+) 类似AppStore 
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Password:
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 445241, done.
remote: Total 445241 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (445241/445241), 269.21 MiB | 562.00 KiB/s, done.
Resolving deltas: 100% (318337/318337), done.
此步骤成功
==> 配置国内镜像源HOMEBREW BOTTLE
Password:
此步骤成功

==> 安装完成,brew版本

检测到你不是最新系统,会有一些报错,请稍等Ruby下载安装;
    
brew -v

==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles-portable-ruby/portable-ruby-2.6.3_1.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring portable-ruby-2.6.3_1.yosemite.bottle.tar.gz
Homebrew 2.4.0-37-g797507f-dirty
Homebrew/homebrew-core (git revision d2e3d; last commit 2020-06-13)
Homebrew/homebrew-cask (git revision c01ed; last commit 2020-06-13)
Brew前期配置成功

==> brew update

Already up-to-date.

        上一句如果提示Already up-to-date表示成功
            Brew自动安装程序运行完成
              国内地址已经配置完成

                初步介绍几个brew命令

        本地软件库列表:brew ls
        查找软件:brew search google(其中google替换为要查找的软件关键字)
        查看brew版本:brew -v  更新brew版本:brew update

现在可以输入命令open ~/.zshrc -e 或者 open ~/.bash_profile -e 整理一下重复的语句(运行 echo $SHELL 可以查看应该打开那一个文件修改)

        https://zhuanlan.zhihu.com/p/111014448  欢迎来给点个赞

1.2 设置国内镜像

由于从github下载软件网速又慢又卡所以我们可以设置成国内的镜像,依次输入以下命令

# 中国科学技术大学的 brew.git 仓库地址
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

# 替换中国科学技术大学的 homebrew-core.git 仓库地址:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

# 中国科学技术大学的 homebrew-cask 仓库地址:
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

# 替换中国科学技术大学的 homebrew-bottles 访问 URL:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

1.3 设置github的ip

由于下载软件的时候经常会去github上下载东西,有时候很慢会导致出现连接超时等问题,所以我们要保证ping github.com可以正常。

sudo vi /etc/hosts # 修改hosts文件

# 复制如下
151.101.185.194 github.global.ssl.fastly.net
192.30.253.112 github.com
151.101.184.133 assets-cdn.github.com
151.101.184.133 avatars0.githubusercontent.com
151.101.112.133 avatars1.githubusercontent.com

再次打开终端,发现ping github.com还是超时

renaissance$ ping github.com
PING github.com (192.30.253.112): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4
Request timeout for icmp_seq 5
Request timeout for icmp_seq 6

此时前往https://github.com.ipaddress.com/
网站查看最新的github网址为140.82.113.3,所以修改将
192.30.253.112 github.com 修改成
140.82.113.3 github.com

140.82.113.3

再次ping github.com发现可以ping通

renaissance$ ping github.com
PING github.com (140.82.113.3): 56 data bytes
64 bytes from 140.82.113.3: icmp_seq=0 ttl=44 time=364.074 ms
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
64 bytes from 140.82.113.3: icmp_seq=3 ttl=44 time=320.332 ms
Request timeout for icmp_seq 4
Request timeout for icmp_seq 5
64 bytes from 140.82.113.3: icmp_seq=6 ttl=44 time=395.800 ms
Request timeout for icmp_seq 7
64 bytes from 140.82.113.3: icmp_seq=8 ttl=44 time=331.844 ms
Request timeout for icmp_seq 9
64 bytes from 140.82.113.3: icmp_seq=10 ttl=44 time=370.847 ms
64 bytes from 140.82.113.3: icmp_seq=11 ttl=44 time=495.214 ms
Request timeout for icmp_seq 12
64 bytes from 140.82.113.3: icmp_seq=13 ttl=44 time=432.208 ms
64 bytes from 140.82.113.3: icmp_seq=14 ttl=44 time=349.181 ms

1.4 brew命令介绍

常用的命令如下

  brew [info | home | options ] [FORMULA...]  
  brew install FORMULA...    # 安装某个软件
  brew uninstall FORMULA...  # 卸载某个软件
  brew search [foo]          # 查找某个软件
  brew list [FORMULA...]     # 列出所有软件
  brew update  
  brew upgrade [FORMULA...]  # 更新某个软件
  brew pin/unpin [FORMULA...]  

2. 安装rabbitMQ

打开终端输入以下命令

brew install rabbitmq

如果下载的过程中一直是1%的加载,那说明是网太慢了,我就断掉wifi换热点,十分钟就下完了。

Downloading https://github.com/rabbitmq/rabbitmq-server/releases/download/v3
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws
######################################################################## 100.0%k
==> Installing dependencies for rabbitmq: openssl@1.1, jpeg, libpng, libtiff, wxmac and erlang
==> Installing rabbitmq dependency: openssl@1.1
==> Pouring openssl@1.1-1.1.1g.mojave.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> /Users/renaissance/.bash_profile

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> Summary
🍺  /usr/local/Cellar/openssl@1.1/1.1.1g: 8,059 files, 18MB
==> Installing rabbitmq dependency: jpeg
==> Pouring jpeg-9d.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/jpeg/9d: 21 files, 751KB
==> Installing rabbitmq dependency: libpng
==> Pouring libpng-1.6.37.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/libpng/1.6.37: 27 files, 1.2MB
==> Installing rabbitmq dependency: libtiff
==> Pouring libtiff-4.1.0.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/libtiff/4.1.0: 247 files, 3.6MB
==> Installing rabbitmq dependency: wxmac
==> Pouring wxmac-3.0.5.1_1.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/wxmac/3.0.5.1_1: 813 files, 23.1MB
==> Installing rabbitmq dependency: erlang
==> Pouring erlang-23.0.2.mojave.bottle.tar.gz
==> Caveats
Man pages can be found in:
  /usr/local/opt/erlang/lib/erlang/man

Access them with `erl -man`, or add this directory to MANPATH.
==> Summary
🍺  /usr/local/Cellar/erlang/23.0.2: 6,275 files, 287.9MB
==> Installing rabbitmq
==> /usr/bin/unzip -qq -j /usr/local/Cellar/rabbitmq/3.8.3/plugins/rabbitmq_mana
==> Caveats
Management Plugin enabled by default at http://localhost:15672

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

To have launchd start rabbitmq now and restart at login:
  brew services start rabbitmq
Or, if you don't want/need a background service you can just run:
  rabbitmq-server
==> Summary
🍺  /usr/local/Cellar/rabbitmq/3.8.3: 281 files, 20.4MB, built in 4 seconds
==> Caveats
==> openssl@1.1
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> /Users/renaissance/.bash_profile

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> erlang
Man pages can be found in:
  /usr/local/opt/erlang/lib/erlang/man

Access them with `erl -man`, or add this directory to MANPATH.
==> rabbitmq
Management Plugin enabled by default at http://localhost:15672

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

To have launchd start rabbitmq now and restart at login:
  brew services start rabbitmq
Or, if you don't want/need a background service you can just run:
  rabbitmq-server

按照提示输入启动命令rabbitmq-server

renaissance$ rabbitmq-server

  ##  ##      RabbitMQ 3.8.3
  ##  ##
  ##########  Copyright (c) 2007-2020 Pivotal Software, Inc.
  ######  ##
  ##########  Licensed under the MPL 1.1. Website: https://rabbitmq.com

  Doc guides: https://rabbitmq.com/documentation.html
  Support:    https://rabbitmq.com/contact.html
  Tutorials:  https://rabbitmq.com/getstarted.html
  Monitoring: https://rabbitmq.com/monitoring.html

  Logs: /usr/local/var/log/rabbitmq/rabbit@localhost.log
        /usr/local/var/log/rabbitmq/rabbit@localhost_upgrade.log

  Config file(s): (none)

  Starting broker... completed with 6 plugins.


然后在浏览器输入 http://localhost:15672/,账号和密码都是guest

登录界面
主界面

安装成功!!!终于安装成功!!

3. 安装kafka

3.1 安装kafka

在终端输入安装命令

brew install kafka

下载过程如下

renaissance$ brew install kafka
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/zookeeper-3
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/kafka-2.5.0
######################################################################## 100.0%
==> Installing dependencies for kafka: zookeeper
==> Installing kafka dependency: zookeeper
==> Pouring zookeeper-3.5.8.mojave.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.5.8: 394 files, 11.4MB
==> Installing kafka
==> Pouring kafka-2.5.0.mojave.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.5.0: 186 files, 58.6MB
==> 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

3.2 启动zookeeper和kafka

然后按照提示输入启动命令,新建两个窗口分别启动zookeeper和kafka。

# 启动zookeeper
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties & 

# 启动kafka
kafka-server-start /usr/local/etc/kafka/server.properties &
zookeeper启动成功如下
kafka启动成功如下

3.3 测试kafka

  • 新建topic
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic  topictest
  • 查看topic
kafka-topics --list --zookeeper localhost:2181
  • 新建窗口,生产者输入消息
kafka-console-producer --broker-list localhost:9092 --topic topictest
生产者
  • 新建窗口,消费者输出消息
kafka-console-consumer --bootstrap-server localhost:9092 --topic topictest --from-beginning
消费者

kafka也安装完成!!!

4. 总结

通过此次安装第一了解brew安装管理包,简单的命令就可以安装卸载软件,因此是mac下安装卸载软件一个比较好的选择了。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,657评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,889评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,057评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,509评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,562评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,443评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,251评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,129评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,561评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,779评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,902评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,621评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,220评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,838评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,971评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,025评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,843评论 2 354