環(huán)境和版本
ubuntu18, 最新的MQ版本
how
- 使用apt軟件倉(cāng)庫(kù)窍仰, 可能會(huì)有版本的延遲
- 手動(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(推薦)频祝。
- 下載key
https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | sudo apt-key add -
原站勘誤
- 使用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文檔