CentOS 7.5 下安装RabbitMQ

1. 安装Erlang

vim /etc/yum.repos.d/rabbitmq-erlang.repo
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/21/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1

yum -y install erlang

2. 下载安装 RabbitMQ

wget http://mirror.centos.org/centos/7/os/x86_64/Packages/socat-1.7.3.2-2.el7.x86_64.rpm
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.1/rabbitmq-server-3.8.1-1.el7.noarch.rpm

# rpm -ivh socat-1.7.3.2-2.el7.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:socat-1.7.3.2-2.el7              ################################# [100%]

# rpm -ivh rabbitmq-server-3.8.1-1.el7.noarch.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:rabbitmq-server-3.8.1-1.el7      ################################# [100%]

3. 启动Server与Web管理界面

# vim /usr/lib/rabbitmq/lib/rabbitmq_server-3.8.1/ebin/rabbit.app
{loopback_users, [<<"guest">>]}
修改为:
{loopback_users, ["guest"]},


# systemctl start rabbitmq-server

# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@zabbix:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@zabbix...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

started 3 plugins.

# firewall-cmd --zone=public --add-port=15672/tcp --permanent
# firewall-cmd --reload

浏览器:http://IP:15672 (用户名:guest,密码:guest)

4. 插件列表:

# rabbitmq-plugins list
Listing plugins with pattern ".*" ...
 Configured: E = explicitly enabled; e = implicitly enabled
 | Status: * = running on rabbit@zabbix
 |/
[  ] rabbitmq_amqp1_0                  3.8.1
[  ] rabbitmq_auth_backend_cache       3.8.1
[  ] rabbitmq_auth_backend_http        3.8.1
[  ] rabbitmq_auth_backend_ldap        3.8.1
[  ] rabbitmq_auth_backend_oauth2      3.8.1
[  ] rabbitmq_auth_mechanism_ssl       3.8.1
[  ] rabbitmq_consistent_hash_exchange 3.8.1
[  ] rabbitmq_event_exchange           3.8.1
[  ] rabbitmq_federation               3.8.1
[  ] rabbitmq_federation_management    3.8.1
[  ] rabbitmq_jms_topic_exchange       3.8.1
[E*] rabbitmq_management               3.8.1
[e*] rabbitmq_management_agent         3.8.1
[  ] rabbitmq_mqtt                     3.8.1
[  ] rabbitmq_peer_discovery_aws       3.8.1
[  ] rabbitmq_peer_discovery_common    3.8.1
[  ] rabbitmq_peer_discovery_consul    3.8.1
[  ] rabbitmq_peer_discovery_etcd      3.8.1
[  ] rabbitmq_peer_discovery_k8s       3.8.1
[  ] rabbitmq_prometheus               3.8.1
[  ] rabbitmq_random_exchange          3.8.1
[  ] rabbitmq_recent_history_exchange  3.8.1
[  ] rabbitmq_sharding                 3.8.1
[  ] rabbitmq_shovel                   3.8.1
[  ] rabbitmq_shovel_management        3.8.1
[  ] rabbitmq_stomp                    3.8.1
[  ] rabbitmq_top                      3.8.1
[  ] rabbitmq_tracing                  3.8.1
[  ] rabbitmq_trust_store              3.8.1
[e*] rabbitmq_web_dispatch             3.8.1
[  ] rabbitmq_web_mqtt                 3.8.1
[  ] rabbitmq_web_mqtt_examples        3.8.1
[  ] rabbitmq_web_stomp                3.8.1
[  ] rabbitmq_web_stomp_examples       3.8.1

4.1 WebSocket

rabbitmq-plugins enable rabbitmq_web_mqtt
# URL:https://www.rabbitmq.com/web-mqtt.html

# netstat -an|grep 15674
tcp        0      0 0.0.0.0:15674           0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:48713         127.0.0.1:15674         TIME_WAIT

# wget http://127.0.0.1:15674/ws
--2019-12-31 17:36:54--  http://127.0.0.1:15674/ws
正在连接 127.0.0.1:15674... 已连接。
已发出 HTTP 请求,正在等待回应... 426 Upgrade Required
2019-12-31 17:36:54 错误 426:Upgrade Required。

5. 其他操作

5.1 添加用户并授权

# 添加用户
# rabbitmqctl add_user admin rabbit@2019
Adding user "admin" ...

# 设置用户角色
# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...

# 设置用户权限(j接收来自所有Host的所有操作)
# rabbitmqctl set_permissions -p "/" admin '.*' '.*' '.*'
Setting permissions for user "admin" in vhost "/" ...

# 查看用户权限
# rabbitmqctl list_user_permissions admin
Listing permissions for user "admin" ...
vhost   configure   write   read
/   .*  .*  .*

5.2、配置用户远程访问

# vim /usr/lib/rabbitmq/lib/rabbitmq_server-3.8.1/ebin/rabbit.app
{loopback_users, ["guest", "admin"]},
修改为:
{loopback_users, ["guest"},

# systemctl restart rabbitmq-server
# firewall-cmd --zone=public --add-port=5672/tcp --permanent
# firewall-cmd --reload
点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注