记录一下在centos7.x下面安装RabbitMQ消息中间件
RabbitMQ是一个开源而且遵循 AMQP协议实现的基于 Erlang语言编写,因此安装RabbitMQ之前是需要部署安装Erlang环境的
先安装Erlang
https://packagecloud.io/rabbitmq/
点进去可以看到
因为使用的centos是7.x版本的,所以搜寻el7 (el8表示centos8.x下面安装的) 严格遵循版本
访问进去
https://packagecloud.io/rabbitmq/erlang/packages/el/7/erlang-23.3.4.10-1.el7.x86_64.rpm?distro_version_id=140
特别爽安装步骤都给出来了,还有wget方式的
[root@myw ~]# curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
Detected operating system as centos/7.
Checking for curl...
Detected curl...
Downloading repository file: https://packagecloud.io/install/repositories/rabbitmq/erlang/config_file.repo?os=centos&dist=7&source=script
done.
Installing pygpgme to verify GPG signatures...
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: 100.125.0.40
* extras: 100.125.0.40
* updates: 100.125.0.40
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
rabbitmq_erlang-source/signature | 819 B 00:00:00
Retrieving key from https://packagecloud.io/rabbitmq/erlang/gpgkey
Importing GPG key 0xDF309A0B:
Userid : "https://packagecloud.io/rabbitmq/erlang (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>"
Fingerprint: 2ebd e413 d3ce 5d35 bcd1 5b7c 71c6 3471 df30 9a0b
From : https://packagecloud.io/rabbitmq/erlang/gpgkey
rabbitmq_erlang-source/signature | 951 B 00:00:00 !!!
updates | 2.9 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 249 kB 00:00:00
(2/2): updates/7/x86_64/primary_db | 19 MB 00:00:00
rabbitmq_erlang-source/primary | 175 B 00:00:01
Package pygpgme-0.3-9.el7.x86_64 already installed and latest version
Nothing to do
Installing yum-utils...
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: 100.125.0.40
* extras: 100.125.0.40
* updates: 100.125.0.40
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be installed
--> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-54.el7_8.noarch
--> Processing Dependency: libxml2-python for package: yum-utils-1.1.31-54.el7_8.noarch
--> Running transaction check
---> Package libxml2-python.x86_64 0:2.9.1-6.el7_9.6 will be installed
--> Processing Dependency: libxml2 = 2.9.1-6.el7_9.6 for package: libxml2-python-2.9.1-6.el7_9.6.x86_64
---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed
--> Running transaction check
---> Package libxml2.x86_64 0:2.9.1-6.el7.5 will be updated
---> Package libxml2.x86_64 0:2.9.1-6.el7_9.6 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================================================================================
Installing:
yum-utils noarch 1.1.31-54.el7_8 base 122 k
Installing for dependencies:
libxml2-python x86_64 2.9.1-6.el7_9.6 updates 247 k
python-kitchen noarch 1.1.1-5.el7 base 267 k
Updating for dependencies:
libxml2 x86_64 2.9.1-6.el7_9.6 updates 668 k
Transaction Summary
====================================================================================================================================================================================================================
Install 1 Package (+2 Dependent packages)
Upgrade ( 1 Dependent package)
Total download size: 1.3 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/4): libxml2-python-2.9.1-6.el7_9.6.x86_64.rpm | 247 kB 00:00:00
(2/4): libxml2-2.9.1-6.el7_9.6.x86_64.rpm | 668 kB 00:00:00
(3/4): yum-utils-1.1.31-54.el7_8.noarch.rpm | 122 kB 00:00:00
(4/4): python-kitchen-1.1.1-5.el7.noarch.rpm | 267 kB 00:00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 9.8 MB/s | 1.3 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python-kitchen-1.1.1-5.el7.noarch 1/5
Updating : libxml2-2.9.1-6.el7_9.6.x86_64 2/5
Installing : libxml2-python-2.9.1-6.el7_9.6.x86_64 3/5
Installing : yum-utils-1.1.31-54.el7_8.noarch 4/5
Cleanup : libxml2-2.9.1-6.el7.5.x86_64 5/5
Verifying : libxml2-2.9.1-6.el7_9.6.x86_64 1/5
Verifying : python-kitchen-1.1.1-5.el7.noarch 2/5
Verifying : yum-utils-1.1.31-54.el7_8.noarch 3/5
Verifying : libxml2-python-2.9.1-6.el7_9.6.x86_64 4/5
Verifying : libxml2-2.9.1-6.el7.5.x86_64 5/5
Installed:
yum-utils.noarch 0:1.1.31-54.el7_8
Dependency Installed:
libxml2-python.x86_64 0:2.9.1-6.el7_9.6 python-kitchen.noarch 0:1.1.1-5.el7
Dependency Updated:
libxml2.x86_64 0:2.9.1-6.el7_9.6
Complete!
Generating yum cache for rabbitmq_erlang...
Importing GPG key 0xDF309A0B:
Userid : "https://packagecloud.io/rabbitmq/erlang (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>"
Fingerprint: 2ebd e413 d3ce 5d35 bcd1 5b7c 71c6 3471 df30 9a0b
From : https://packagecloud.io/rabbitmq/erlang/gpgkey
Generating yum cache for rabbitmq_erlang-source...
The repository is setup! You can now install packages.
[root@myw ~]#
[root@myw ~]# sudo yum install erlang-23.3.4.10-1.el7.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: 100.125.0.40
* extras: 100.125.0.40
* updates: 100.125.0.40
Resolving Dependencies
--> Running transaction check
---> Package erlang.x86_64 0:23.3.4.10-1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================================================================================
Installing:
erlang x86_64 23.3.4.10-1.el7 rabbitmq_erlang 19 M
Transaction Summary
====================================================================================================================================================================================================================
Install 1 Package
Total download size: 19 M
Installed size: 34 M
Is this ok [y/d/N]: y
Downloading packages:
erlang-23.3.4.10-1.el7.x86_64.rpm | 19 MB 00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : erlang-23.3.4.10-1.el7.x86_64 1/1
Verifying : erlang-23.3.4.10-1.el7.x86_64 1/1
Installed:
erlang.x86_64 0:23.3.4.10-1.el7
Complete!
[root@myw ~]#
查看是否安装成功
[root@myw ~]# erl -version
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 11.2.2.9
[root@myw ~]#
记录一下这2条
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
sudo yum install erlang-23.3.4.10-1.el7.x86_64
安装RabbitMq
回到起初页面,选择rabbitmq-server点进去搜索el7
这里确认下版本要和安装的erlang对应,相对特别重要,这里选择的是没问题的,依旧2个步骤
[root@myw ~]# curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
Detected operating system as centos/7.
Checking for curl...
Detected curl...
Downloading repository file: https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/config_file.repo?os=centos&dist=7&source=script
done.
Installing pygpgme to verify GPG signatures...
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: 100.125.0.40
* extras: 100.125.0.40
* updates: 100.125.0.40
rabbitmq_erlang/x86_64/signature | 833 B 00:00:00
rabbitmq_erlang/x86_64/signature | 1.8 kB 00:00:00 !!!
rabbitmq_erlang-source/signature | 819 B 00:00:00
rabbitmq_erlang-source/signature | 951 B 00:00:00 !!!
rabbitmq_rabbitmq-server-source/signature | 836 B 00:00:00
Retrieving key from https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
Importing GPG key 0x4D206F89:
Userid : "https://packagecloud.io/rabbitmq/rabbitmq-server (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>"
Fingerprint: 8c69 5b02 19af deb0 4a05 8ed8 f4e7 8920 4d20 6f89
From : https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
rabbitmq_rabbitmq-server-source/signature | 1.0 kB 00:00:00 !!!
rabbitmq_rabbitmq-server-source/primary | 175 B 00:00:01
Package pygpgme-0.3-9.el7.x86_64 already installed and latest version
Nothing to do
Installing yum-utils...
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: 100.125.0.40
* extras: 100.125.0.40
* updates: 100.125.0.40
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do
Generating yum cache for rabbitmq_rabbitmq-server...
Importing GPG key 0x4D206F89:
Userid : "https://packagecloud.io/rabbitmq/rabbitmq-server (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>"
Fingerprint: 8c69 5b02 19af deb0 4a05 8ed8 f4e7 8920 4d20 6f89
From : https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
Generating yum cache for rabbitmq_rabbitmq-server-source...
The repository is setup! You can now install packages.
[root@myw ~]#
[root@myw ~]# sudo yum install rabbitmq-server-3.10.0-1.el7.noarch
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: 100.125.0.40
* extras: 100.125.0.40
* updates: 100.125.0.40
Resolving Dependencies
--> Running transaction check
---> Package rabbitmq-server.noarch 0:3.10.0-1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================================================================================
Installing:
rabbitmq-server noarch 3.10.0-1.el7 rabbitmq_rabbitmq-server 14 M
Transaction Summary
====================================================================================================================================================================================================================
Install 1 Package
Total download size: 14 M
Installed size: 19 M
Is this ok [y/d/N]: y
Downloading packages:
rabbitmq-server-3.10.0-1.el7.noarch.rpm | 14 MB 00:00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : rabbitmq-server-3.10.0-1.el7.noarch 1/1
Verifying : rabbitmq-server-3.10.0-1.el7.noarch 1/1
Installed:
rabbitmq-server.noarch 0:3.10.0-1.el7
Complete!
[root@myw ~]#
记录下2条安装
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
sudo yum install rabbitmq-server-3.10.0-1.el7.noarch
把RabbitMQ的web管理界面插件加上(web管理界面比起用指令操作更方便)
rabbitmq-plugins enable rabbitmq_management
[root@myw ~]# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@myw:
rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@myw...
The following plugins have been enabled:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
set 3 plugins.
Offline change; changes will take effect at broker restart.
[root@myw ~]#
启动指令
systemctl start rabbitmq-server
[root@myw ~]# systemctl start rabbitmq-server
[root@myw ~]# netstat -lnp|grep 5672
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 22993/beam.smp
tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 22993/beam.smp
tcp6 0 0 :::5672 :::* LISTEN 22993/beam.smp
[root@myw ~]#
开机自启动
systemctl enable rabbitmq-server
重启指令
systemctl restart rabbitmq-server
停止指令
systemctl stop rabbitmq-server
取消开机自启指令
systemctl disable rabbitmq-server
启动后访问web界面
127.0.0.1:15672
默认账号密码是guest guest 因为仅仅支持本地登录,所以放在云端安装,可以单独创建用户,guest用户不用理会它。
RabbitMQ常见操作
用户管理
1.查询RabbitMQ的用户
rabbitmqctl list_users
[root@myw ~]# rabbitmqctl list_users
Listing users ...
user tags
mywroot [administrator]
guest [administrator]
[root@myw ~]#
2.添加新用户(授权和加角色)
rabbitmqctl add_user mywadmin 123456
跟着的是账号mywadmin 后面是密码123456
[root@myw ~]# rabbitmqctl add_user mywadmin 123456
Adding user "mywadmin" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
[root@myw ~]#
分配管理员的角色
rabbitmqctl set_user_tags mywadmin administrator
[root@myw ~]# rabbitmqctl set_user_tags mywadmin administrator
Setting tags for user "mywadmin" to [administrator] ...
[root@myw ~]# rabbitmqctl list_users
Listing users ...
user tags
mywroot [administrator]
mywadmin [administrator]
guest [administrator]
[root@myw ~]#
分配所有权限
rabbitmqctl set_permissions -p / mywadmin ".*" ".*" ".*"
[root@myw ~]# rabbitmqctl set_permissions -p / mywadmin ".*" ".*" ".*"
Setting permissions for user "mywadmin" in vhost "/" ...
[root@myw ~]#
3.指引RabbitMQ的broker认证用户和密码
rabbitmqctl authenticate_user mywadmin 123456
[root@myw ~]# rabbitmqctl authenticate_user mywadmin 123456
Authenticating user "mywadmin" ...
Success
[root@myw ~]#
4.修改指定用户的密码(很少操作)
rabbitmqctl change_password mywadmin 12345678
[root@myw ~]# rabbitmqctl change_password mywadmin 12345678
Changing password for user "mywadmin" ...
[root@myw ~]#
5.清除指定用户密码(很少操作)
rabbitmqctl clear_password mywadmin
[root@myw ~]# rabbitmqctl clear_password mywadmin
Clearing password for user "mywadmin" ...
[root@myw ~]# rabbitmqctl list_users
Listing users ...
user tags
mywroot [administrator]
mywadmin [administrator]
guest [administrator]
[root@myw ~]#
6.删除指定用户
rabbitmqctl delete_user mywadmin
[root@myw ~]# rabbitmqctl delete_user mywadmin
Deleting user "mywadmin" ...
[root@myw ~]# rabbitmqctl list_users
Listing users ...
user tags
mywroot [administrator]
guest [administrator]
[root@myw ~]#
权限管理
1.给用户授权
rabbitmqctl set_permissions -p / mywadmin ".*" ".*" ".*"
rabbitmqctl set_permissions -p sthvhost mywadmin "^mywqueue.*" ".*" ".*"
授权指令的格式
rabbitmqctl set_permissions [-p vhost] {user} {conf} {write} {read}
[-p vhost] 表示给待授权用户的vhost(虚拟主机)名称 默认是"/"
{user}表示待授权的用户 mywadmin
{conf}表示待授权用户的配置权限 正则表达式 一般都是给的 “.*”
{write}表示待授权用户的写权限 正则表达式 一般都是给的 “.*”
{read}表示待授权用户的读权限 正则表达式 一般都是给的 “.*”
2.查询指定vhost(虚拟主机)的所有用户的权限 默认的写法是"/"
rabbitmqctl list_permissions [-p vhost]
rabbitmqctl list_permissions -p /
[root@myw ~]# rabbitmqctl list_permissions -p /
Listing permissions for vhost "/" ...
user configure write read
mywadmin .* .* .*
mywroot .* .* .*
guest .* .* .*
[root@myw ~]#
3.查询指定用户的权限
rabbitmqctl list_user_permissions {username}
rabbitmqctl list_user_permissions mywadmin
[root@myw ~]# rabbitmqctl list_user_permissions mywadmin
Listing permissions for user "mywadmin" ...
vhost configure write read
/ .* .* .*
[root@myw ~]#
4.清除指定vhost的权限
rabbitmqctl clear_permissions [-p vhost] {username}
rabbitmqctl clear_permissions -p / mywadmin
[root@myw ~]# rabbitmqctl clear_permissions -p / mywadmin
Clearing permissions for user "mywadmin" in vhost "/" ...
[root@myw ~]# rabbitmqctl list_user_permissions mywadmin
Listing permissions for user "mywadmin" ...
[root@myw ~]#
vhost虚拟主机管理
1.创建虚拟主机
rabbitmqctl add_vhost vhost_myw
[root@myw ~]# rabbitmqctl add_vhost vhost_myw
Adding vhost "vhost_myw" ...
[root@myw ~]#
2.查看虚拟主机
rabbitmqctl list_vhosts
rabbitmqctl list_vhosts name tracing
主要显示虚拟主机的名称
[root@myw ~]# rabbitmqctl list_vhosts
Listing vhosts ...
name
vhost_myw
/
[root@myw ~]#
[root@myw ~]# rabbitmqctl list_vhosts name tracing
Listing vhosts ...
name tracing
vhost_myw false
/ false
[root@myw ~]#
3.删除虚拟主机(慎重)
rabbitmqctl delete_vhost vhost_myw
[root@myw ~]# rabbitmqctl delete_vhost vhost_myw
Deleting vhost "vhost_myw" ...
[root@myw ~]#
插件管理(主要是web管理)
1.查看当前的插件使用状态
rabbitmq-plugins list
[root@myw ~]# rabbitmq-plugins list
Listing plugins with pattern ".*" ...
Configured: E = explicitly enabled; e = implicitly enabled
| Status: * = running on rabbit@myw
|/
[ ] rabbitmq_amqp1_0 3.10.0
[ ] rabbitmq_auth_backend_cache 3.10.0
[ ] rabbitmq_auth_backend_http 3.10.0
[ ] rabbitmq_auth_backend_ldap 3.10.0
[ ] rabbitmq_auth_backend_oauth2 3.10.0
[ ] rabbitmq_auth_mechanism_ssl 3.10.0
[ ] rabbitmq_consistent_hash_exchange 3.10.0
[ ] rabbitmq_event_exchange 3.10.0
[ ] rabbitmq_federation 3.10.0
[ ] rabbitmq_federation_management 3.10.0
[ ] rabbitmq_jms_topic_exchange 3.10.0
[E*] rabbitmq_management 3.10.0
[e*] rabbitmq_management_agent 3.10.0
[ ] rabbitmq_mqtt 3.10.0
[ ] rabbitmq_peer_discovery_aws 3.10.0
[ ] rabbitmq_peer_discovery_common 3.10.0
[ ] rabbitmq_peer_discovery_consul 3.10.0
[ ] rabbitmq_peer_discovery_etcd 3.10.0
[ ] rabbitmq_peer_discovery_k8s 3.10.0
[ ] rabbitmq_prometheus 3.10.0
[ ] rabbitmq_random_exchange 3.10.0
[ ] rabbitmq_recent_history_exchange 3.10.0
[ ] rabbitmq_sharding 3.10.0
[ ] rabbitmq_shovel 3.10.0
[ ] rabbitmq_shovel_management 3.10.0
[ ] rabbitmq_stomp 3.10.0
[ ] rabbitmq_stream 3.10.0
[ ] rabbitmq_stream_management 3.10.0
[ ] rabbitmq_top 3.10.0
[ ] rabbitmq_tracing 3.10.0
[ ] rabbitmq_trust_store 3.10.0
[e*] rabbitmq_web_dispatch 3.10.0
[ ] rabbitmq_web_mqtt 3.10.0
[ ] rabbitmq_web_mqtt_examples 3.10.0
[ ] rabbitmq_web_stomp 3.10.0
[ ] rabbitmq_web_stomp_examples 3.10.0
[root@myw ~]#
E = explicitly enabled; e = implicitly enabled
2.启动web页面插件
rabbitmq-plugins enable rabbitmq_management
3.关闭web页面插件
rabbitmq-plugins disable rabbitmq_management
[root@myw ~]# rabbitmq-plugins disable rabbitmq_management
Disabling plugins on node rabbit@myw:
rabbitmq_management
All plugins have been disabled.
Applying plugin configuration to rabbit@myw...
The following plugins have been disabled:
rabbitmq_management_agent
rabbitmq_web_dispatch
rabbitmq_management
stopped 3 plugins.
[root@myw ~]#