51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Centos7安装部署RabbitMQ3.7.x

文章目录

RabbitMQ是一个开源的消息代理和队列服务器,通过Erlang编写,用来通过普通协议在完全不同的应用之间共享数据。并且RabbitMQ是基于高级消息队列(AMQP)协议的。

当前以Centos7系统为例,部署RabbitMQ3.7.x,由于RabbitMQ需要Erlang支持,所以这里先安装Erlang,你可以通过epel源来安装(epel提供的版本过旧),也可以通过配置yum源来安装,我这里以yum源来安装。

安装Erlang {#title-0}

1、配置Erlang源
cat > /etc/yum.repos.d/rabbitmq-erlang.repo << EOF [rabbitmq-erlang] name=rabbitmq-erlang baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/22/el/7 gpgcheck=1 gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc repo_gpgcheck=0 enabled=1 EOF

|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 | cat > /etc/yum.repos.d/rabbitmq-erlang.repo << EOF [rabbitmq-erlang] name=rabbitmq-erlang baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/22/el/7 gpgcheck=1 gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc repo_gpgcheck=0 enabled=1 EOF |

2、安装erlang和socat
yum install erlang socat -y

|---|-----------------------------| | 1 | yum install erlang socat -y |

3、查看erlang版本
erl -version Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 10.7.2

|-----|-----------------------------------------------------------------------------| | 1 2 | erl -version Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 10.7.2 |

可以直接运行erl命令切换到Erlang shell
erl Erlang/OTP 22 [erts-10.7.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe] Eshell V10.7.2 (abort with ^G) 1> 按ctrl+c两次退出

|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 | erl Erlang/OTP 22 [erts-10.7.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe] Eshell V10.7.2 (abort with ^G) 1> 按ctrl+c两次退出 |


安装RabbitMQ {#title-1}

1、配置rabbitmq源
cat > /etc/yum.repos.d/rabbitmq.repo << EOF [bintray-rabbitmq-server] name=bintray-rabbitmq-rpm baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/el/7/ gpgcheck=0 repo_gpgcheck=0 enabled=1 EOF

|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 | cat > /etc/yum.repos.d/rabbitmq.repo << EOF [bintray-rabbitmq-server] name=bintray-rabbitmq-rpm baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/el/7/ gpgcheck=0 repo_gpgcheck=0 enabled=1 EOF |

2、安装rabbitmq
yum install rabbitmq-server -y

|---|--------------------------------| | 1 | yum install rabbitmq-server -y |

3、启动RabbitMQ

注意:rabbitmq默认以系统用户rabbitmq身份运行,如果更改节点数据或日志的位置,确保文件权限是rabbitmq(并且还要更新环境变量)
systemctl start rabbitmq-server

|---|---------------------------------| | 1 | systemctl start rabbitmq-server |

4、设置开机自启
systemctl enable rabbitmq-server

|---|----------------------------------| | 1 | systemctl enable rabbitmq-server |

5、启用rabbitmq的web控制台
rabbitmq-plugins enable rabbitmq_management Enabling plugins on node rabbit@whsir6: rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch Applying plugin configuration to rabbit@whsir6... The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch started 3 plugins.

|----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | rabbitmq-plugins enable rabbitmq_management Enabling plugins on node rabbit@whsir6: rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch Applying plugin configuration to rabbit@whsir6... The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch started 3 plugins. |

6、刷新文件权限
chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/

|---|-----------------------------------------------| | 1 | chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/ |

注:rabbitmq默认账号密码为guest,但是guest用户只能通过localhost登录使用,所以我这里建议修改guest用户的密码及新建账号来管理rabbitmq

用户标签 {#title-2}

在该版本的rabbitmq中默认有六种标签设置,默认新建的用户标签为none

administrator(超级管理员):无需解释,至高权限
monitoring(监控者):可以查看节点相关信息、内存、集群、统计等情况
policymaker(策略制定者):可以查看,创建和删除策略和参数,无法查看节点信息
management(普通管理者):可以查看队列、交换和绑定,无法查看节点信息,也无法对策略进行管理
impersonator(模拟者):允许应用程序伪造用户ID
none(无):无法访问管理插件

权限控制 {#title-3}

rabbitmqctl set_permissions [-p <vhost>] <user> <conf> <write> <read>

vhost被授予权限的主机
user被授予权限的用户
conf正则匹配用户在哪些资源具有配置权限
write正则匹配用户在哪些资源具有写权限
read正则匹配用户在哪些资源具有读权限

配置用户 {#title-4}

添加rabbitmqWeb控制台管理用户(wuhao是你要添加的用户名,thisispw是该用户的密码)
rabbitmqctl add_user wuhao thisispw

|---|-------------------------------------| | 1 | rabbitmqctl add_user wuhao thisispw |

查看当前用户列表
rabbitmqctl list_users

|---|------------------------| | 1 | rabbitmqctl list_users |

用户标签分配,我这里为了演示,将administrator分配给用户wuhao
rabbitmqctl set_user_tags wuhao administrator

|---|-----------------------------------------------| | 1 | rabbitmqctl set_user_tags wuhao administrator |

设置wuhao用户在主机所有资源上可配置、可写、可读的权限
rabbitmqctl set_permissions -p / wuhao ".*" ".*" ".*"

|---|----------------------------------------------------------| | 1 | rabbitmqctl set_permissions -p / wuhao ".*" ".*" ".*" |

访问http://IP:15672/,用户wuhao,密码thisispw,登录RabbitMQ

登陆后可看到如下页面


赞(0)
未经允许不得转载:工具盒子 » Centos7安装部署RabbitMQ3.7.x