Linux安装RabbitMQ3.73开启插件shovel并做配置

一、安装RabbitMQ

安装rabbitmq所需的erlang软件包,方法有二(编译和yum安装),这里采用yum安装

vim /etc/yum.repos.d/rabbitmq-erlang.repo
#插入如下代码
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq/rpm/erlang/20/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1
#清除yum缓存并重新生成缓存
yum clean all && yum makecache

安装erlang/socat

yum install erlang socat -y

安装rabbitmq

rpm -Uvh https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.3/rabbitmq-server-3.7.3-1.el7.noarch.rpm
#启动rabbitmq服务
systemctl start rabbitmq-server
#将rabbitmq设置为开机启动
systemctl enable rabbitmq-server
#查看rabbitmq运行状态
systemctl status rabbitmq-server

创建rabbitmq用户

#添加用户
rabbitmqctl add_user 用户名 密码
#设置用户角色
rabbitmq set_user_tags admin administrator
#tag(administrator,monitoring,policymaker,management)
#设置用户权限(接受来自所有Host的所有操作)
sudo rabbitmqctl  set_permissions -p "/" admin '.*' '.*' '.*' 
#查看用户权限
sudo rabbitmqctl list_user_permissions admin

配置远程访问

#修改配置文件,
sudo vi /etc/rabbitmq/rabbitmq.config 

#保存以下内容
[
{rabbit, [{tcp_listeners, [5672]}, 
{loopback_users, ["admin"]}]} ].

模块开放

#开放shovel模块和shovel_management管理模块
rabbitmq-plugins enable rabbitmq_shovel
rabbitmq-plugins enable rabbitmq_shovel_management

查看已开放的模块

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

防火墙开放端口

firewall-cmd --zone=public --add-port=15672/tcp --permanent #permanent为永久生效
#重新加载防火墙
firewall-cmd --reload

附上rabbitmq常用命令

# 添加用户
sudo rabbitmqctl add_user <username> <password>  
# 删除用户
sudo rabbitmqctl delete_user <username>  
# 修改用户密码
sudo rabbitmqctl change_password <username> <newpassword>  
# 清除用户密码(该用户将不能使用密码登陆,但是可以通过SASL登陆如果配置了SASL认证)
sudo rabbitmqctl clear_password <username> 
# 设置用户tags(相当于角色,包含administrator,monitoring,policymaker,management)
sudo rabbitmqctl set_user_tags <username> <tag>
# 列出所有用户
sudo rabbitmqctl list_users  
# 创建一个vhosts
sudo rabbitmqctl add_vhost <vhostpath>  
# 删除一个vhosts
sudo rabbitmqctl delete_vhost <vhostpath>  
# 列出vhosts
sudo rabbitmqctl list_vhosts [<vhostinfoitem> ...]  
# 针对一个vhosts给用户赋予相关权限;
sudo rabbitmqctl set_permissions [-p <vhostpath>] <user> <conf> <write> <read>  
# 清除一个用户对vhosts的权限;
sudo rabbitmqctl clear_permissions [-p <vhostpath>] <username>  
# 列出哪些用户可以访问该vhosts;
sudo rabbitmqctl list_permissions [-p <vhostpath>]   
# 列出用户访问权限;
sudo rabbitmqctl list_user_permissions <username>

二、配置shovel模块

登陆web界面配置shovel

开始配置

将对应的信息填好,这里注意,因为我们建vhost的时候一般喜欢带个“/”,但是,在uri中直接填“/”他会当成路径来处理,所以这个地方要用%2f来转义。其它的就是将你源队列及目录队列信息填好,然后添加即可。

amqp://username:passwd@IP:端口/%2fVhost

配置完成后在shovel status里面查看状态,如果是runing表示配置成功。如果是terminated则表示配置有问题,请根据日志分析错误

URI参照一下示例

amqp://
connect to local server as default user

amqp://user@/my-vhost
connect to local server with alternate user and virtual host (passwords are not required for local connections)

amqp://server-name
connect to server-name, without SSL and default credentials

amqp://user:password@server-name/my-vhost
connect to server-name, with credentials and overridden virtual host

amqps://user:password@server-name?cacertfile=/path/to/cacert.pem&certfile=/path/to/cert.pem&keyfile=/path/to/key.pem&verify=verify_peer
connect to server-name, with credentials and SSL

amqps://server-name?cacertfile=/path/to/cacert.pem&certfile=/path/to/cert.pem&keyfile=/path/to/key.pem&verify=verify_peer&fail_if_no_peer_cert=true&auth_mechanism=external
connect to server-name, with SSL and EXTERNAL authentication

附:RabbitMQ远程不能访问问题的解决

修改rabbitmq.config.example,将以下两项前面的%去掉,保存然后重启服务即可。参考来源

{tcp_listeners, [5672]},
{loopback_users, ["admin"]},

 

本文参考博客1

本文参考博客2

 

posted @ 2019-03-13 12:51  小年青。  阅读(1415)  评论(0编辑  收藏  举报