rabbitmq 学习 之下载和安装(1)

参考官网 :  https://www.rabbitmq.com/download.html

1 选择适合自己系统的安装方式,比如centos ,打开连接 https://www.rabbitmq.com/install-rpm.html

2 There are two ways to install the most recent version of RabbitMQ:

如上所述 可以从git 下载 然后rpm 安装 ,并且安装 依赖。

也可以 使用yum 源安装  提供package  Cloud 和 Bintray 两个源。
 

bintray 的包 没有 package cloud 支持的多,好多老版本包找不到

3 具体使用方式参见具体部分。

 

4 erlang 和 rabbitmq server 版本对应关系   https://www.rabbitmq.com/which-erlang.html

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

6 The server is not started as a daemon by default when the RabbitMQ server package is installed. To start the daemon by default when the system boots, as an administrator run

chkconfig rabbitmq-server on

As an administrator, start and stop the server as usual:

/sbin/service rabbitmq-server start

/sbin/service rabbitmq-server stop

7 rabbitmq 使用的端口:

Installing on RPM-based Linux (RHEL, CentOS, Fedora, openSUSE)

Overview

rabbitmq-server is included in standard Fedora and RHEL repositories. However, the versions included are usually outdated.

There are two ways to install the most recent version of RabbitMQ:

 

The following guide focuses on RabbitMQ installation on RPM-based distributions such as Fedora, RHEL and CentOS. It covers a number of topics:

and more.

 

 

Overview

The package is distributed via Yum repositories on PackageCloud and Bintray.

rabbitmq-server is included in Fedora. However, the versions included often lag behind RabbitMQ releases. It is recommended that you use Yum repositories from PackageCloud or Bintray.

Check the Fedora package details for which version of the server is available for which versions of the distribution.

Supported Distributions

Below is a list of supported RPM-based distributions as of RabbitMQ 3.6.3:

  • CentOS 7.x and x.x (note: there are two separate RPM packages for each series)
  • RedHat Enterprise Linux 7.x and x.x (same packages as for CentOS)
  • Fedora 23 through 25 (use the CentOS 7.x package)

The packages may work on other RPM-based distributions if dependencies are satisfied but their testing and support is done on a best effort basis.

 

User Privilege Requirements

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

Install Erlang

Before installing RabbitMQ, you must install a supported version of Erlang/OTP. There are three commonly used sources for Erlang packages on RPM-based distributions.

  • Team RabbitMQ produces a package stripped down to only provide those components needed to run RabbitMQ. It might be easiest to use if installing Erlang's dependencies is proving difficult.
  • Erlang Solutions produces packages that are usually reasonably up to date and involve installation of a potentially excessive list of dependencies.
  • EPEL ("Extra Packages for Enterprise Linux"); part of the Red Hat/Fedora organisation, provides many additional packages, including Erlang. These are the most official packages but tend to be out of date. The packages are split into many small pieces.
  • openSUSE produces Erlang packages for each distribution (openSUSE and SLES)

Zero-dependency Erlang from RabbitMQ

Zero dependency Erlang RPM package for running RabbitMQ can be installed via Yum repositories on Bintray and Package Cloud as well as a direct download.

As the name suggests, the package strips off some Erlang modules and dependencies that are not essential for running RabbitMQ.

Erlang packages from openSUSE

openSUSE package repositories provide Erlang so it can be installed using Zypper:

sudo zypper in erlang

Erlang versions available in the standard repositories will in practice be behind the most recent version. To use the last version with the newest features, add the openSUSE Factory repositories for Erlang:

# add the openSUSE erlang factory, obs:// extracts the http url for the matching distro.
sudo zypper ar -f  obs://devel:languages:erlang:Factory openSUSE-Erlang-Factory

# import the signing key and refresh the repository
sudo zypper --gpg-auto-import-keys refresh

# install a recent Erlang version
sudo zypper in erlang

 

Erlang Yum Repository from Erlang Solutions

Follow the instructions under "Installation using repository" at Erlang Solutions. Note that Erlang Solutions tend to provide cutting edge Erlang versions that may or may not be supported by RabbitMQ. Version locking (see below) is recommended when Erlang installed using this option.

Monolithic Erlang Package from Erlang Solutions

Download and install the appropriate esl-erlang RPM from Erlang Solutions.

Erlang package from the EPEL Repository

Follow the steps in the EPEL FAQ to enable EPEL on the target machine, then run the following command as root:

yum install erlang

 

Package Version Locking in Yum

yum version locking plugin is recommended to prevent unwanted Erlang upgrades. This is highly recommended when Erlang is installed via the Erlang Solutions repository.

Package Dependencies

When installing with Yum, all dependencies other than Erlang/OTP should be resolved and installed automatically as long as compatible versions are available. When that's not the case, dependency packages must be installed manually. However, when installing a local RPM file via yum dependencies must be installed manually. Below is the list of dependencies of RabbitMQ server as of 3.7.0:

 

Install RabbitMQ Server

Using PackageCloud Yum Repository

A Yum repository with RabbitMQ packages is available from PackageCloud. A quick way to install is to use a Package Cloud-provided script. Package Cloud also can be used to install a recent Erlang version via yum.

There are more installation options available:

  • Using PackageCloud Chef cookbook
  • Using PackageCloud Puppet module
  • Manually

See PackageCloud RabbitMQ repository instructions.

 

Package Cloud signs distributed packages using their own GPG keys. As of late 2018 Package Cloud is undergoing a signing key migration. Instead of relying on a "master key", projects will migrate to use repository-specific signing keys. Before the migration is completed, both old and new key must be imported for forward compatibility:

# import the new PackageCloud key that will be used starting December 1st, 2018 (GMT)
rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey

# import the old PackageCloud key that will be discontinued on December 1st, 2018 (GMT)
rpm --import https://packagecloud.io/gpg.key

 

After importing both keys please follow the Package Cloud repository setup instructions.

Using Bintray Yum Repository

A Yum repository with RabbitMQ packages is available from Bintray. The package page provides a repository setup help section. Bintray also can be used to install a recent Erlang version via yum.

Before the Yum repository can be used, RabbitMQ signing key must be imported first. This makes RPM tools trust the signature on the packages provided in the repository. To do so, run rpm --import as a superuser:

rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc

 

In order to use the Yum repository, a .repo file (e.g. rabbitmq.repo) has to be added under the /etc/yum.repos.d/ directory. The contents of the file will vary slightly between distributions (e.g. CentOS 7 vs. CentOS 6 vs. OpenSUSE). The following example targets CentOS 7:

[bintray-rabbitmq-server]
name=bintray-rabbitmq-rpm
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/el/7/
gpgcheck=0
repo_gpgcheck=0
enabled=1

 

On CentOS 6 the baseurl line would be slightly different:

[bintray-rabbitmq-server]
name=bintray-rabbitmq-rpm
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/el/6/
gpgcheck=0
repo_gpgcheck=0
enabled=1

 

The following example targets OpenSUSE:

[bintray-rabbitmq-server]
name=bintray-rabbitmq-rpm
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/opensuse/42.1/
gpgcheck=0
repo_gpgcheck=0
enabled=1

 

The following example targets SLES 11.x:

[bintray-rabbitmq-server]
name=bintray-rabbitmq-rpm
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/sles/11
gpgcheck=0
repo_gpgcheck=0
enabled=1

 

With rpm and Downloaded RPM

After downloading the server package, issue the following command as 'root':

rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
# this example assumes the CentOS 7 version of the package
yum install rabbitmq-server-3.7.15-1.el7.noarch.rpm

RabbitMQ public signing key is also available from rabbitmq.com:

rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
# this example assumes the CentOS 7 version of the package
yum install rabbitmq-server-3.7.15-1.el7.noarch.rpm

 

Download the Server

In some cases it may easier to download the package and install it manually. The package can be downloaded from GitHub.

DescriptionDownload 
RPM for RHEL Linux 7.x, CentOS 7.x, Fedora 19+ (supports systemd)rabbitmq-server-3.7.15-1.el7.noarch.rpm(Signature)
RPM for RHEL Linux 6.x, CentOS 6.x, Fedora prior to 19rabbitmq-server-3.7.15-1.el6.noarch.rpm(Signature)
RPM for openSUSE Linuxrabbitmq-server-3.7.15-1.suse.noarch.rpm(Signature)
RPM for SLES 11.xrabbitmq-server-3.7.15-1.sles11.noarch.rpm(Signature)

Run RabbitMQ Server

Start the Server

The server is not started as a daemon by default when the RabbitMQ server package is installed. To start the daemon by default when the system boots, as an administrator run

chkconfig rabbitmq-server on

 

As an administrator, start and stop the server as usual:

/sbin/service rabbitmq-server start

/sbin/service rabbitmq-server stop
sudo service rabbitmq-server status

Port Access

RabbitMQ nodes bind to ports (open server TCP sockets) in order to accept client and CLI tool connections. Other processes and tools such as SELinux may prevent RabbitMQ from binding to a port. When that happens, the node will fail to start. CLI tools, client libraries and RabbitMQ nodes also open connections (client TCP sockets). Firewalls can prevent nodes and CLI tools from communicating with each other. Make sure the following ports are accessible:

  • 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 interfaces.

 

8 控制打开的文件句柄个数

RabbitMQ installations running production workloads may need system limits and kernel parameters tuning in order to handle a decent number of concurrent connections and queues. The main setting that needs adjustment is the max number of open files, also known as ulimit -n. The default value on many operating systems is too low for a messaging broker (eg. 1024 on several Linux distributions). We recommend allowing for at least 65536 file descriptors for user rabbitmq in production environments. 4096 should be sufficient for most development workloads.

There are two limits in play: the maximum number of open files the OS kernel allows (fs.file-max) and the per-user limit (ulimit -n). The former must be higher than the latter.

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:

[Service]
LimitNOFILE=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 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 excellentRiak guide on open file limit tuning.

 

9 日志

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.14. 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/rabbitmqdirectory. Rotation configuration can be found in /etc/logrotate.d/rabbitmq-server.

 

10 RabbitMQ Changelog

https://www.rabbitmq.com/changelog.html

 

11 github 地址

https://github.com/rabbitmq?q=rabbitmq

 

 

以下是一个安装示例

一 rabbitmq 简介

RabbitMQ 是当今最主流的消息中间件之一。它是一个开源的AMQP实现,服务器端用Erlang语言编写,支持多种客户端,如:Python、Ruby、.NET、Java、JMS、C、PHP、ActionScript、XMPP、STOMP等,支持AJAX。用于在分布式系统中存储转发消息,在易用性、扩展性、高可用性等方面表现优异。

在安装rabbitmq的时候需要注意rabbitmq 和erlang版本的关系,如果两者关系不一一对应的话,那么会导致出错的。
rabbitmq 版本和 erlang 的关系

 

我们接下来的安装的版本和环境是:

  • 系统平台:CentOS 7
  • erlang版本:21.2
  • rabbit-server版本:3.7.12

rabbit-server 默认使用的端口 :
5672(AMQP端口) 和15672(web),还有其他不常用端口未列出,见官网。
如在公网上访问,需要开放这两个端口。

二 erlang 安装

  • 2.1 安装依赖包
yum -y install make gcc gcc-c++ m4 ncurses-devel openssl-devel unixODBC-devel
  • 2.2 下载erlang依赖包
cd  /tmp && wget http://erlang.org/download/otp_src_21.2.tar.gz
  • 2.3 解压
tar xzf otp_src_21.2.tar.gz
  • 2.4 创建文件夹
mkdir /usr/local/erlang
  • 2.5 编译并安装erlang
cd otp_src_21.2
./configure --prefix=/usr/local/erlang --without-javac
make && make install
  • 2.6 添加环境变量
vi + /etc/profile
# 添加以下内容
export PATH=$PATH:/usr/local/erlang/bin
  • 2.7 让环境变量生效
source /etc/profile
  • 2.8 检验安装
erl -version
# 能够正确输出下面的内容表示安装完成
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 10.2

三 rabbitmq rpm安装 (二进制安装和rpm安装二选一)

安装rabbitmq前必须先安装符合要求的erlang

  • 3.1 下载RabbitMQ安装包。
cd /tmp &&  wget  https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.12/rabbitmq-server-3.7.12-1.el7.noarch.rpm
  • 3.2 导入签名密钥。
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
  • 3.3 安装 socat
yum install socat -y
  • 3.3 安装RabbitMQ Server。
yum install  rabbitmq-server-3.7.12-1.el7.noarch.rpm  

如果在此遇到的错误见文章第七点显示的错误收录

  • 3.4 允许RabbitMQ开机自启动。
systemctl enable rabbitmq-server
  • 3.5 启动RabbitMQ。
systemctl start rabbitmq-server
  • 3.6 暂停RabbitMQ。
systemctl stop rabbitmq-server

四 rabbitmq 二进制安装(rpm 安装和二进制安装二选一)

安装rabbitmq前必须先安装符合要求的erlang

  • 4.1 下载rabbitmq 二进制安装
cd /tmp && wget   https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.12/rabbitmq-server-generic-unix-3.7.12.tar.xz
  • 4.2 解压
tar -xf  rabbitmq-server*.tar.xz
  • 4.3 移动到指定路径
mv  /tmp/rabbitmq_server-3.7.12  /usr/local/rabbitmq_server
  • 4.4 添加环境变量
vi + /etc/profile
# 添加以下内容
export PATH=$PATH:/usr/local/rabbitmq_server/sbin
  • 4.5 环境变量生效
source /etc/profile
  • 4.6 启动rabbitmq server
rabbitmq-server 
  • 4.7 后台启动
rabbitmq-server -detached
  • 4.8 关闭rabbitmq
rabbitmqctl shutdown
  • 4.9 创建配置文件

在 $ RABBITMQ_HOME 的目录下创建

#rabbitmq 配置文件 
touch  ./etc/rabbitmq/rabbitmq.conf
#rabbitmq 环境变量文件
touch ./etc/rabbitmq/rabbitmq-env.conf
  • 4.10 设定 rabbitmq的家目录路径
vim ./sbin/rabbitmq-defaults
# 修改 SYS_PREFIX =
SYS_PREFIX =rabbitmq 家目录路径。

五 初始化并配置用户和启用web界面

  • 5.1 删除默认用户

对于生产环境,请删除默认用户(guest),默认用户只能从localhost 连接。

 rabbitmqctl delete_user guest
  • 5.2 创建新用户并设置为管理员

建议每个应用程序都使用单独的用户。

 rabbitmqctl add_user 用户名 密码
 rabbitmqctl set_user_tags 用户名 administrator
  • 5.3 设置用户权限

设置用户djx 具有 /这个virtual host的所有的资源的配置、写、读权限

rabbitmqctl  set_permissions -p / djx  '.*' '.*' '.*'
  • 5.4 启用web 界面
 rabbitmq-plugins enable rabbitmq_management
  • 5.5 访问

访问路径: http://ip:15672
出现以下界面就意味着搭建成功了

RabbitMQ二进制和RPM安装部署与常用命令
RabbitMQ二进制和RPM安装部署与常用命令

六 常用命令

6.1 查看rabbitmq server 状态

rabbitmqctl status
  • 6.2 查看已用的组件,内存使用情况,警报
rabbitmq-diagnostics status
  • 6.3 查看有效的节点配置
rabbitmq-diagnostics environment
  • 6.4 对本地节点执行更广泛的运行状况检查
rabbitmq-diagnostics node_health_check
  • 6.5 virtual host操作
每个VirtualHost相当于一个相对独立的RabbitMQ服务器,每个virtual host相互隔离
#  添加virtual host
rabbitmqctl add_vhost ${hostname}

# 删除virtual host
rabbitmqctl delete_vhost ${hostname}

# 列出所有的virtual host
rabbitmqctl list_vhosts name tracing
# 设置某个用户对于某个host 的权限
set_permissions [-p vhost] user conf write read

示例1:
rabbitmqctl set_permissions -p my-vhost janeway “^janeway-.*” “.*” “.*”
表示设置用户 janeway 对于host名为 my-vhost的以janeway-为开头的资源具有读写权限
示例2:
rabbitmqctl set_permissions -p my-vhost djx “.*” “.*” “.*”
表示设置用户 djx 对于host名为 my-vhost的所有的资源具有读写权限

# 删除用户权限
clear_permissions [-p vhost] username
示例:
rabbitmqctl clear_permissions -p my-vhost janeway
删除用户 janeway 对host my-vhost 的权限

# 查看virtual host已有的用户和权限
rabbitmqctl  list_permissions -p ${主机名}
  • 6.6 用户操作
# 添加用户
rabbitmqctl add_user {用户名} {密码}

# 设置用户角色,除了管理员用户,还有监控者(monitoring),普通管理者(management),策略制定者(policymaker)
    management 
    User can access the management plugin 
    policymaker 
    User can access the management plugin and manage policies and parameters for the vhosts they have access to. 
    monitoring 
    User can access the management plugin and see all connections and channels as well as node-related information. 
    administrator 
    User can do everything monitoring can do, manage users, vhosts and permissions, close other user’s connections, and manage policies and parameters for all vhosts.
示例
rabbitmqctl set_user_tags {用户名} administrator/monitoring/management

# 查看用户列表
rabbitmqctl list_users 

# 给用户赋予权限
rabbitmqctl  set_permissions -p {virtual host名称} 用户名 配置权限 写权限 读权限
示例
rabbitmqctl  set_permissions -p / djx  '.*' '.*' '.*'

# 查看用户权限
 rabbitmqctl  list_user_permissions {用户名}
 
# 查看已有的用户和权限
rabbitmqctl  list_permissions -p '{virtual host名}'

# 删除用户 
rabbitmqctl delete_user {用户名}

# 修改用户的密码
rabbitmqctl change_password {用户名} {新密码} 

七 错误解决方法

  • 问题1

如果在 yum install rabbitmq-server-3.7.12-1.el7.noarch.rpm 遇到了erlang依赖错误的话,

RabbitMQ二进制和RPM安装部署与常用命令

实际我们是已经安装erlang,但是rabbitmq-server 还是检测不到,我重载了环境变量还是不行。

解决办法

先忽略依赖问题安装

rpm -i --nodeps rabbitmq-server-3.7.12-1.el7.noarch.rpm

然后更改rabbitmq的启动加载的环境配置文件 /usr/lib/rabbitmq/bin/rabbitmq-env。在里面开头添加

source  /etc/profile

或者尝试方法:添加一个软连接

ln -s /usr/local/erlang/bin/erl      /usr/bin/erl

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值