Linux下安裝RabbitMQ

前言

RabbitMQ是一個開源的消息中間件,採用 Erlang 語言進行編寫,所以RabbitMQ的安裝須要依賴Erlang,如今咱們將在 Linux 下進行安裝RabbitMQ。html

本人環境:CentOS 6.5 64位git

安裝Erlang

在安裝Erlang的時候,有不少種方法,最開始我是想按照官網先下載Erlang安裝包,而後再進行安裝。但發現下載Erlang官網的安裝包實在是太慢了,所以換了一種方式,使用RabbitMQ提供的零依賴的Erlang RPM軟件包,它提供了足以運行RabbitMQ的能力。github

Github地址:https://github.com/rabbitmq/erlang-rpmweb

在上面的Github中,提供了相關版本的安裝方法,我這裏Linux環境是CentOS 6.5,準備安裝的Erlang版本以下:shell

安裝Erlang

1,首先,新建一個文件,命令以下:vim /etc/yum.repos.d/rabbitmq-erlang.repo,並將如下內容寫入文件中,最後保存。vim

[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 erlangasync

[root@bogon 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
[root@bogon 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
[root@bogon 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 <info@rabbitmq.com>"
 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工具

[root@bogon 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已經安裝成功。this

下載RabbitMQ

在上面,咱們安裝的Erlang版本是 20.3.x ,根據RbbitMQ對Erlang版本要求,我選擇安裝的RabbitMQ版本是 3.7.6 ,能夠直接從Gtihub中下載已發行版本。url

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 的文件,須要經過 tarxz 命令進行解壓,若是沒有安裝 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 下的文件,顯示的文件以下:

[root@bogon rabbitmq]# ls
rabbitmq_server-3.7.6  rabbitmq-server-generic-unix-3.7.6.tar
[root@bogon rabbitmq]#

啓動RabbitMQ

進入 /opt/rabbitmq/rabbitmq_server-3.7.6/sbin 目錄下,咱們這裏下載的 RabbitMQ 解壓後直接使用便可。

前臺啓動服務:./rabbitmq-server
後臺啓動服務:./rabbitmq-server -detached
查看服務狀態:./rabbitmqctl status
關閉服務:./rabbitmqctl stop

[root@bogon ~]# cd /opt/rabbitmq/rabbitmq_server-3.7.6/sbin
[root@bogon sbin]# ls
cuttlefish   rabbitmq-defaults     rabbitmq-env      rabbitmq-server
rabbitmqctl  rabbitmq-diagnostics  rabbitmq-plugins
[root@bogon 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/rabbit@bogon.log
                    /opt/rabbitmq/rabbitmq_server-3.7.6/var/log/rabbitmq/rabbit@bogon_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 用戶名

[root@bogon sbin]# ./rabbitmqctl add_user admin 123456
Adding user "admin" ...
[root@bogon sbin]# ./rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...
[root@bogon sbin]# ./rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/" ...
[root@bogon sbin]# ./rabbitmqctl list_users
Listing users ...
admin   [administrator]
guest   [administrator]
[root@bogon sbin]#

開啓Web界面管理工具

咱們在 /opt/rabbitmq/rabbitmq_server-3.7.6/sbin 目錄下 ,能夠開啓Web控制檯管理插件,命令以下:

./rabbitmq-plugins enable rabbitmq_management

[root@bogon sbin]# ./rabbitmq-plugins enable rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@bogon...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

started 3 plugins.
[root@bogon sbin]#

最後,咱們須要再檢查一下相關端口是否已開放,好比1567二、5672等,其中,15672是Web管理界面端口,5672是AMQP通訊端口。

在Windows中輸入地址進行訪問:http://ip地址:15672/,能夠看到RabbitMQ的控制檯管理界面。

登陸RabbitMQ

RabbitMQ主界面

相關文章
相關標籤/搜索