liym 2019-12-29
RabbitMQ是一个开源的消息中间件,采用 Erlang
语言进行编写,因此RabbitMQ的安装需要依赖Erlang,现在我们将在 Linux
下进行安装RabbitMQ。
本人环境:CentOS 6.5 64位
在安装Erlang的时候,有很多种方法,最开始我是想按照官网先下载Erlang安装包,然后再进行安装。但发现下载Erlang官网的安装包实在是太慢了,因此换了一种方式,使用RabbitMQ提供的零依赖的Erlang RPM软件包,它提供了足以运行RabbitMQ的能力。
Github地址:https://github.com/rabbitmq/erlang-rpm
在上面的Github中,提供了相关版本的安装方法,我这里Linux环境是CentOS 6.5,准备安装的Erlang版本如下:
1,首先,新建一个文件,命令如下:vim /etc/yum.repos.d/rabbitmq-erlang.repo,并将以下内容写入文件中,最后保存。
[rabbitmq-erlang] name=rabbitmq-erlang baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/20/el/6 gpgcheck=1 gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc repo_gpgcheck=0 enabled=1
2,接着,通过 yum
命令安装RabbitMQ提供的Erlang版本,命令如下:yum install erlang 。
[ rabbitmq]# yum install erlang Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.cn99.com * elrepo: hkg.mirror.rackspace.com * epel: hkg.mirror.rackspace.com * extras: mirror.bit.edu.cn * updates: mirrors.cn99.com rabbitmq-erlang | 1.3 kB 00:00 rabbitmq-erlang/primary | 20 kB 00:00 rabbitmq-erlang 3/3 Resolving Dependencies --> Running transaction check ---> Package erlang.x86_64 0:20.3.8.24-1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ===================================================================================== Package Arch Version Repository Size ===================================================================================== Installing: erlang x86_64 20.3.8.24-1.el6 rabbitmq-erlang 18 M Transaction Summary ===================================================================================== Install 1 Package(s) Total download size: 18 M Installed size: 31 M Is this ok [y/N]: N Exiting on user Command Your transaction was saved, rerun it with: yum load-transaction /tmp/yum_save_tx-2019-12-28-23-05bDCcch.yumtx [ rabbitmq]# yum install erlang=20.0 Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.cn99.com * elrepo: hkg.mirror.rackspace.com * epel: hkg.mirror.rackspace.com * extras: mirror.bit.edu.cn * updates: mirrors.cn99.com No package erlang=20.0 available. Error: Nothing to do [ rabbitmq]# yum install erlang Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.cn99.com * elrepo: hkg.mirror.rackspace.com * epel: hkg.mirror.rackspace.com * extras: mirror.bit.edu.cn * updates: mirrors.cn99.com Resolving Dependencies --> Running transaction check ---> Package erlang.x86_64 0:20.3.8.24-1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ===================================================================================== Package Arch Version Repository Size ===================================================================================== Installing: erlang x86_64 20.3.8.24-1.el6 rabbitmq-erlang 18 M Transaction Summary ===================================================================================== Install 1 Package(s) Total download size: 18 M Installed size: 31 M Is this ok [y/N]: y Downloading Packages: erlang-20.3.8.24-1.el6.x86_64.rpm | 18 MB 00:18 warning: rpmts_HdrFromFdno: Header V4 RSA/SHA1 Signature, key ID 6026dfca: NOKEY Retrieving key from https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc Importing GPG key 0x6026DFCA: Userid: "RabbitMQ Release Signing Key <>" From : https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc Is this ok [y/N]: y Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : erlang-20.3.8.24-1.el6.x86_64 1/1 Verifying : erlang-20.3.8.24-1.el6.x86_64 1/1 Installed: erlang.x86_64 0:20.3.8.24-1.el6 Complete!
3,最后,验证 Erlang
是否安装成功,在终端输入 erl
。
[ rabbitmq]# erl Erlang/OTP 20 [erts-9.3.3.13] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:10] [hipe] [kernel-poll:false] Eshell V9.3.3.13 (abort with ^G) 1>
出现如上提示,说明Erlang
已经安装成功。
在上面,我们安装的Erlang版本是 20.3.x
,根据RbbitMQ对Erlang版本要求,我选择安装的RabbitMQ版本是 3.7.6
,可以直接从Gtihub中下载已发行版本。
RbbitMQ对Erlang版本要求:https://www.rabbitmq.com/which-erlang.html
Github下载地址:https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.7.6
1,首先,创建一个文件夹,用于存放即将下载的RabbitMQ。
创建文件夹:mkdir /opt/rabbitmq
进入文件夹:cd /opt/rabbitmq
2,接着,通过 wget
命令下载RabbitMQ,也可以在Windows中下载再上传到Linux。
下载RabbitMQ命令:wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.6/rabbitmq-server-generic-unix-3.7.6.tar.xz
3,最后,将下载的RabbitMQ解压。因为这里下载的是后缀为 .tar.xz
的文件,需要通过 tar
和 xz
命令进行解压,如果没有安装 xz
解压工具的话,可以通过 yum -y install xz
命令进行安装。解压命令如下:
xz -d rabbitmq-server-generic-unix-3.7.6.tar.xz
tar -xvf rabbitmq-server-generic-unix-3.7.6.tar
查看 /opt/rabbitmq
下的文件,显示的文件如下:
[ rabbitmq]# ls rabbitmq_server-3.7.6 rabbitmq-server-generic-unix-3.7.6.tar [ rabbitmq]#
进入 /opt/rabbitmq/rabbitmq_server-3.7.6/sbin
目录下,我们这里下载的 RabbitMQ 解压后直接使用即可。
前台启动服务:./rabbitmq-server
后台启动服务:./rabbitmq-server -detached
查看服务状态:./rabbitmqctl status
关闭服务:./rabbitmqctl stop
[ ~]# cd /opt/rabbitmq/rabbitmq_server-3.7.6/sbin [ sbin]# ls cuttlefish rabbitmq-defaults rabbitmq-env rabbitmq-server rabbitmqctl rabbitmq-diagnostics rabbitmq-plugins [ sbin]# ./rabbitmq-server ## ## ## ## RabbitMQ 3.7.6. Copyright (C) 2007-2018 Pivotal Software, Inc. ########## Licensed under the MPL. See http://www.rabbitmq.com/ ###### ## ########## Logs: /opt/rabbitmq/rabbitmq_server-3.7.6/var/log/rabbitmq/ /opt/rabbitmq/rabbitmq_server-3.7.6/var/log/rabbitmq/_upgrade.log Starting broker... completed with 0 plugins.
接下来,我们需要创建一个用户,并给其赋予管理员权限。
新增用户:./rabbitmqctl add_user admin 123456
给用户赋予权限:
./rabbitmqctl set_user_tags admin administrator
./rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
其他的一些命令:
查看用户列表:./rabbitmqctl list_users
修改用户密码:./rabbitmqctl change_password 用户名 新密码
删除用户:./rabbitmqctl delete_user 用户名
[ sbin]# ./rabbitmqctl add_user admin 123456 Adding user "admin" ... [ sbin]# ./rabbitmqctl set_user_tags admin administrator Setting tags for user "admin" to [administrator] ... [ sbin]# ./rabbitmqctl set_permissions -p / admin ".*" ".*" ".*" Setting permissions for user "admin" in vhost "/" ... [ sbin]# ./rabbitmqctl list_users Listing users ... admin [administrator] guest [administrator] [ sbin]#
我们在 /opt/rabbitmq/rabbitmq_server-3.7.6/sbin
目录下 ,可以开启Web控制台管理插件,命令如下:
./rabbitmq-plugins enable rabbitmq_management
[ sbin]# ./rabbitmq-plugins enable rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch Applying plugin configuration to The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch started 3 plugins. [ sbin]#
最后,我们需要再检查一下相关端口是否已开放,比如15672、5672等,其中,15672
是Web管理界面端口,5672
是AMQP通信端口。
在Windows中输入地址进行访问:http://ip地址:15672/,可以看到RabbitMQ的控制台管理界面。