消息隊(duì)列-RabbitMQ 二 安裝和使用

環(huán)境和版本

ubuntu18, 最新的MQ版本

how

  1. 使用apt軟件倉(cāng)庫(kù)窍仰, 可能會(huì)有版本的延遲
  2. 手動(dòng)安裝汉规,使用dpkg -i, 需要手動(dòng)安裝所有依賴

Erlang安裝

Rabbit Mq是使用Erlang編寫,需要安裝合適的版本驹吮,最簡(jiǎn)單的是使用apt安裝针史。
標(biāo)準(zhǔn)的debian和ubuntu倉(cāng)庫(kù)可能會(huì)提供過(guò)期的版本,但是RMQ團(tuán)隊(duì)維持了一個(gè)Erlang/OTP版本供apt安裝碟狞。

安裝步驟如下

  • 導(dǎo)入倉(cāng)庫(kù)簽名key
    為了可以使用這個(gè)倉(cāng)庫(kù)啄枕,我們需要添加apt-key Rmq簽名的key,使得apt信任該軟件包族沃。這部分工作可以使用一個(gè)key server(可能容易過(guò)載)或者直接使用下載的key(推薦)频祝。
  1. 下載key
https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | sudo apt-key add -
原站勘誤
  1. 使用key server
sudo apt-key adv --keyserver "hkps.pool.sks-keyservers.net" --recv-keys "0x6B73A36E6026DFCA"

開(kāi)啟apt https 傳輸

sudo apt-get install apt-transport-https
  • 添加倉(cāng)庫(kù)資源列表
    所有的第三方apt倉(cāng)庫(kù)泌参,都需要有一個(gè)文件來(lái)描述,并且存放在/etc/apt/source.list.d/目錄下常空,建議存放在/etc/apt/source.list.d/bintray.erlang.list
    資源倉(cāng)庫(kù)的定義文件使用下面的模式:
# This repository provides RabbitMQ packages
# See below for supported distribution and component values
deb https://dl.bintray.com/rabbitmq/debian $distribution $component

不得不說(shuō)國(guó)外網(wǎng)站講解的真是細(xì)致及舍,國(guó)內(nèi)快猛操的模式,導(dǎo)致大家干啥都很浮躁窟绷,沒(méi)有這種好的態(tài)度,不得不說(shuō)人家只憑這種態(tài)度還是值得我們學(xué)習(xí)的咐柜。(什么狗屁的崇洋媚外兼蜈,在這點(diǎn)我不得不一吐為快,rabbitMQ你值得擁有拙友,當(dāng)然也不一概而論为狸,我準(zhǔn)備在Linux上放棄Vmare了,ubuntu18搭建centos7的nat(wifi網(wǎng)卡)搞得我圖血遗契,網(wǎng)站上一點(diǎn)都搜不到相關(guān)的知識(shí)辐棒,有了解的同學(xué)可以留言,網(wǎng)上搜出來(lái)的不對(duì)題的麻煩不要留言牍蜂,我玩了一整天漾根,看到一萬(wàn)遍c-p。不然今天應(yīng)該是centos7+rabbitMq了)鲫竞。下面的我就不翻譯了辐怕,大家膜拜一下原汁原味的態(tài)度吧。

The next couple of sections discuss what distribution and component values are supported.

Distribution

In order to set up an apt repository that provides the correct package, a few decisions have to be made. One is determining the distribution name. It comes from the Debian or Ubuntu release used:

  • bionic for Ubuntu 18.04
  • xenial for Ubuntu 16.04
  • buster for Debian Buster
  • stretch for Debian Stretch

Erlang/OTP Version

Another is what Erlang/OTP release version should be provisioned. It is possible to track a specific series (e.g. 21.x) or install the most recent version available. The choice determines what Debian repository component will be configured.

Consider the following repository file at /etc/apt/sources.list.d/bintray.erlang.list:

# Installs the latest 21.x version available in the repository.
deb http://dl.bintray.com/rabbitmq-erlang/debian bionic erlang-21.x

It configures apt to install the most recent Erlang 21.x version available in the repository and use packages for Ubuntu 18.04 (Bionic).

For Debian Stretch the file would look like this:

# Installs the latest 21.x version available in the repository.
deb http://dl.bintray.com/rabbitmq-erlang/debian stretch erlang-21.x

To use the most recent 20.x patch release available, switch the component to erlang-20.x:

# Installs the latest 20.x version available in the repository.
deb http://dl.bintray.com/rabbitmq-erlang/debian bionic erlang-20.x

erlang-21.x, erlang-19.x, and erlang-16.x are the components for Erlang 21.x, 19.x and R16B03, respectively.

The erlang component installs the most recent version available:

# Installs the latest version available in the repository.
# Consider using version pinning.
deb http://dl.bintray.com/rabbitmq-erlang/debian bionic erlang

That version may or may not be supported by RabbitMQ, so version pinning is highly recommended.

  • 更新包metadata
sudo apt-get update -y
  • 安裝合適的Erlang包
# This is recommended. Metapackages such as erlang and erlang-nox must only be used
# with apt version pinning. They do not pin their dependency versions.
sudo apt-get install -y erlang-base \
                        erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \
                        erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \
                        erlang-runtime-tools erlang-snmp erlang-ssl \
                        erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl

包版本和倉(cāng)庫(kù)鎖定(apt pinning)感興趣的同學(xué)可以自行g(shù)oogle
至此我們已經(jīng)安裝完成了Erlang从绘,what寄疏?那MQ呢... heihei,同學(xué)你已經(jīng)一只腳邁向了地球(welcome earth僵井, Allies)陕截,歡迎來(lái)到MQ的地球

使用apt安裝rabbit mq

磨刀不誤砍柴工,既然你看了上面的安裝過(guò)程批什,下面一樣

#!/bin/sh

## Install RabbitMQ signing key
curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | sudo apt-key add -

## Install apt HTTPS transport
sudo apt-get install apt-transport-https

## Add Bintray repositories that provision latest RabbitMQ and Erlang 21.x releases
sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list <<EOF
deb https://dl.bintray.com/rabbitmq-erlang/debian bionic erlang-21.x
deb https://dl.bintray.com/rabbitmq/debian bionic main
EOF

## Update package indices
sudo apt-get update -y

## Install rabbitmq-server and its dependencies
sudo apt-get install rabbitmq-server -y --fix-missing

再次五體投地原汁原味膜拜網(wǎng)站小哥的態(tài)度农曲,顫抖吧 E.T

The next couple of sections discusses what distribution and component values are supported.

Distribution

In order to set up an apt repository that provides the correct package, a few decisions have to be made. One is determining the distribution name. It comes from the Debian or Ubuntu release used:

  • bionic (Ubuntu 18.04)
  • artful
  • trusty
  • sid
  • buster
  • stretch
  • xenial (Ubuntu 16.04)
  • yakkety
  • zesty

To add the apt repository to the source list directory (/etc/apt/sources.list.d), use:

>echo "deb https://dl.bintray.com/rabbitmq/debian {distribution} main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list

where {distribution} is the name of the Debian or Ubuntu distribution used (see above).

So, on Ubuntu 18.04 the above command becomes

>echo "deb https://dl.bintray.com/rabbitmq/debian bionic main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list

and on Ubuntu 16.04 it would be

>echo "deb https://dl.bintray.com/rabbitmq/debian xenial main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list

It is possible to list multiple repositories, for example, one that provides RabbitMQ and one that provides Erlang/OTP packages. On Ubuntu 18.04 that can be done by modifying the command in the above example like so:

>sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list <<EOF
deb https://dl.bintray.com/rabbitmq-erlang/debian bionic erlang-21.x
deb https://dl.bintray.com/rabbitmq/debian bionic main
EOF

and on Ubuntu 16.04 it would be

>sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list <<EOF
deb https://dl.bintray.com/rabbitmq-erlang/debian xenial erlang-21.x
deb https://dl.bintray.com/rabbitmq/debian xenial main
EOF

Install RabbitMQ Package

After updating the list of apt sources it is necessary to run apt-get update:

>sudo apt-get update -y

Then install the package with

>sudo apt-get install -y rabbitmq-server

(手動(dòng)安裝我已不翻譯了)

Manual Installation with Dpkg

In some cases it may easier to download the package directly from GitHub and install it manually using sudo dpkg -i. Below is a download link.

Description Download Signature
.deb for Debian-based Linux (from GitHub) rabbitmq-server_3.7.17-1_all.deb Signature

When installing manually with dpkg, it is necessary to install package dependencies first. dpkg, unlike apt, does not resolve or manage dependencies.

Here's an example that does that, installs wget, downloads the RabbitMQ package and installs it:

# sync package metadata
sudo apt-get update
# install dependencies manually
sudo apt-get -y install socat logrotate init-system-helpers adduser

# download the package
sudo apt-get -y install wget
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.17/rabbitmq-server_3.7.17-1_all.deb

# install the package with dpkg
sudo dpkg -i rabbitmq-server_3.7.17-1_all.deb

rm rabbitmq-server_3.7.17-1_all.deb

Installation via apt repositories on Bintray and Package Cloud is recommended over downloading the package directly and installing via dpkg -i. When the RabbitMQ package is installed manually with dpkg -i the operator is responsible for making sure that all package dependencies are met.

User Privilege Requirements

RabbitMQ Debian package will require sudo privileges to install and manage. In environments where sudo isn't available, consider using the generic binary build instead.

讓MQ run 起來(lái)

安裝時(shí),rabbit mq默認(rèn)以守護(hù)進(jìn)程啟動(dòng)渊季,并且使用沒(méi)有權(quán)限的用戶 rabbitmq
可以使用super user的service命令啟動(dòng)朋蔫。關(guān)閉、和查看rabbitmq-server狀態(tài)

sudo service rabbitmq-server status[start| stop | restart]

端口獲取

rabbitMq節(jié)點(diǎn)綁定有個(gè)開(kāi)放的tcp端口却汉,用來(lái)接受client端和CLI工具的鏈接驯妄。其他的工具或者進(jìn)程可能占用或者阻止端口,竟會(huì)出現(xiàn)錯(cuò)誤合砂。要保證一下的端口可用性青扔,因?yàn)镕irewalls和SeLinux會(huì)屏蔽端口連接。

  • 4369: epmd, a peer discovery service used by RabbitMQ nodes and CLI tools
  • 5672, 5671: used by AMQP 0-9-1 and 1.0 clients without and with TLS
  • 25672: used for inter-node and CLI tools communication (Erlang distribution server port) and is allocated from a dynamic range (limited to a single port by default, computed as AMQP port + 20000). Unless external connections on these ports are really necessary (e.g. the cluster uses federation or CLI tools are used on machines outside the subnet), these ports should not be publicly exposed. See networking guide for details.
  • 35672-35682: used by CLI tools (Erlang distribution client ports) for communication with nodes and is allocated from a dynamic range (computed as server distribution port + 10000 through server distribution port + 10010). See networking guide for details.
  • 15672: HTTP API clients, management UI and rabbitmqadmin (only if the management plugin is enabled)
  • 61613, 61614: STOMP clients without and with TLS (only if the STOMP plugin is enabled)
  • 1883, 8883: (MQTT clients without and with TLS, if the MQTT plugin is enabled
  • 15674: STOMP-over-WebSockets clients (only if the Web STOMP plugin is enabled)
  • 15675: MQTT-over-WebSockets clients (only if the Web MQTT plugin is enabled)

It is possible to configure RabbitMQ to use different ports and specific network interfac

默認(rèn)user access

broker會(huì)創(chuàng)建一個(gè)user為guest,密碼為guest微猖。通常沒(méi)有配置的clients使用這個(gè)憑證谈息。但是默認(rèn)的這些憑證只能從localhost連接broker,所以你需要配置user用于網(wǎng)絡(luò)上的連接凛剥。

See the documentation on access control for information on how to create more users and delete the guest user.

系統(tǒng)限制

生產(chǎn)級(jí)別的rabbitMq可能需要系統(tǒng)limit和內(nèi)核參數(shù)調(diào)優(yōu)到允許處理高并發(fā)連接和緩沖隊(duì)列侠仇,主要是ulimit -n參數(shù),生產(chǎn)環(huán)境可以調(diào)到最大的65535犁珠,開(kāi)發(fā)環(huán)境4096逻炊,下面knee down & suck

With systemd (Recent Linux Distributions)

On distributions that use systemd, the OS limits are controlled via a configuration file at /etc/systemd/system/rabbitmq-server.service.d/limits.conf. For example, to set the max open file handle limit (nofile) to 64000:

[Service]
LimitNOFILE=64000

See systemd documentation to learn about the supported limits and other directives.

With Docker

To configure kernel limits for Docker contains, use the "default-ulimits" key in Docker daemon configuration file. The file has to be installed on Docker hosts at /etc/docker/daemon.json:

{
  "default-ulimits": {
    "nofile": {
      "Name": "nofile",
      "Hard": 64000,
      "Soft": 64000
    }
  }
}

Without systemd (Older Linux Distributions)

The most straightforward way to adjust the per-user limit for RabbitMQ on distributions that do not use systemd is to edit the /etc/default/rabbitmq-server (provided by the RabbitMQ Debian package) or rabbitmq-env.conf to invoke ulimit before the service is started.

>ulimit -S -n 4096

This soft limit cannot go higher than the hard limit (which defaults to 4096 in many distributions). The hard limit can be increased via /etc/security/limits.conf. This also requires enabling the pam_limits.so module and re-login or reboot. Note that limits cannot be changed for running OS processes.

For more information about controlling fs.file-max with sysctl, please refer to the excellent Riak guide on open file limit tuning.

驗(yàn)證系統(tǒng)limit(應(yīng)該只能驗(yàn)證配置參數(shù),系統(tǒng)參數(shù)需要系統(tǒng)里面配置)

rabbitnqctl satus
or 
cat /proc/$rabbitmq_bean_process_pid/limits

See the CLI tools guide to learn more.

Log Files and Management

Server logs can be found under the configurable directory, which usually defaults to /var/log/rabbitmq when RabbitMQ is installed via a Linux package manager.

RABBITMQ_LOG_BASE can be used to override log directory location.

Assuming a systemd-based distribution, system service logs can be inspected using

journalctl --system

which requires superuser privileges. Its output can be filtered to narrow it down to RabbitMQ-specific entries:

sudo journalctl --system | grep rabbitmq

The output will look similar to this:

Dec 26 11:03:04 localhost rabbitmq-server[968]: ##  ##
Dec 26 11:03:04 localhost rabbitmq-server[968]: ##  ##      RabbitMQ 3.7.16\. Copyright (c) 2007-2019 Pivotal Software, Inc.
Dec 26 11:03:04 localhost rabbitmq-server[968]: ##########  Licensed under the MPL.  See http://www.rabbitmq.com/
Dec 26 11:03:04 localhost rabbitmq-server[968]: ######  ##
Dec 26 11:03:04 localhost rabbitmq-server[968]: ##########  Logs: /var/log/rabbitmq/rabbit@localhost.log
Dec 26 11:03:04 localhost rabbitmq-server[968]: /var/log/rabbitmq/rabbit@localhost_upgrade.log
Dec 26 11:03:04 localhost rabbitmq-server[968]: Starting broker...
Dec 26 11:03:05 localhost rabbitmq-server[968]: systemd unit for activation check: "rabbitmq-server.service"
Dec 26 11:03:06 localhost rabbitmq-server[968]: completed with 6 plugins.

Log Rotation

The broker always appends to the log files, so a complete log history is retained.

logrotate is the recommended way of log file rotation and compression. By default, the package will set up logrotate to run weekly on files located in default /var/log/rabbitmq directory. Rotation configuration can be found in /etc/logrotate.d/rabbitmq-server.

rabbitmq 有很多命令行工具

  • rabbitmqctl 服務(wù)管理和通常的操作任務(wù)
  • rabbitmq-diagnostics 診斷額健康檢查
  • rabbitmq-plugins 插件管理
  • rabbitmqadmin http api的操作任務(wù)

感興趣的可以自行查閱doc文檔

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末犁享,一起剝皮案震驚了整個(gè)濱河市余素,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌炊昆,老刑警劉巖桨吊,帶你破解...
    沈念sama閱讀 206,968評(píng)論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異凤巨,居然都是意外死亡视乐,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門磅甩,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)炊林,“玉大人,你說(shuō)我怎么就攤上這事卷要≡郏” “怎么了?”我有些...
    開(kāi)封第一講書人閱讀 153,220評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵僧叉,是天一觀的道長(zhǎng)奕枝。 經(jīng)常有香客問(wèn)我,道長(zhǎng)瓶堕,這世上最難降的妖魔是什么隘道? 我笑而不...
    開(kāi)封第一講書人閱讀 55,416評(píng)論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮郎笆,結(jié)果婚禮上谭梗,老公的妹妹穿的比我還像新娘。我一直安慰自己宛蚓,他們只是感情好激捏,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,425評(píng)論 5 374
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著凄吏,像睡著了一般远舅。 火紅的嫁衣襯著肌膚如雪闰蛔。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書人閱讀 49,144評(píng)論 1 285
  • 那天图柏,我揣著相機(jī)與錄音序六,去河邊找鬼。 笑死蚤吹,一個(gè)胖子當(dāng)著我的面吹牛例诀,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播裁着,決...
    沈念sama閱讀 38,432評(píng)論 3 401
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼余佃,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了跨算?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書人閱讀 37,088評(píng)論 0 261
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤椭懊,失蹤者是張志新(化名)和其女友劉穎诸蚕,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體氧猬,經(jīng)...
    沈念sama閱讀 43,586評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡背犯,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,028評(píng)論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了盅抚。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片漠魏。...
    茶點(diǎn)故事閱讀 38,137評(píng)論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖妄均,靈堂內(nèi)的尸體忽然破棺而出柱锹,到底是詐尸還是另有隱情,我是刑警寧澤丰包,帶...
    沈念sama閱讀 33,783評(píng)論 4 324
  • 正文 年R本政府宣布禁熏,位于F島的核電站,受9級(jí)特大地震影響邑彪,放射性物質(zhì)發(fā)生泄漏瞧毙。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,343評(píng)論 3 307
  • 文/蒙蒙 一寄症、第九天 我趴在偏房一處隱蔽的房頂上張望宙彪。 院中可真熱鬧,春花似錦有巧、人聲如沸释漆。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 30,333評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)灵汪。三九已至檀训,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間享言,已是汗流浹背峻凫。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 31,559評(píng)論 1 262
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留览露,地道東北人荧琼。 一個(gè)月前我還...
    沈念sama閱讀 45,595評(píng)論 2 355
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像差牛,于是被迫代替她去往敵國(guó)和親命锄。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,901評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容