CentOS下 RabbitMQ安装配置:
Posted 梦徒
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS下 RabbitMQ安装配置:相关的知识,希望对你有一定的参考价值。
CentOS7.x安装rabbitMQ
1.添加erlang 源至yum存储库
rpm -Uvh https://download.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
2.安装erlang,遇到提示时,输入y命令
yum install erlang
3.导入RabbitMQ源,如果有依赖安装
yum install socat -y
rpm -Uvh https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.8/rabbitmq-server-3.6.8-1.el7.noarch.rpm
4.安装RabbitMQ公共库秘钥
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
5.启动RabbitMQ服务
service rabbitmq-server start
6.查看RabbitMQ服务状态
service rabbitmq-server status
CentOS RabbitMQ rpm 安装方法:
系统环境:CentOS6
IP地址:10.100.62.41
1.erlang安装:
erlang下载地址: http://www.rabbitmq.com/releases/erlang/ [root@v05-apppre-rabbitmq ~]# cd /opt/ytd_src/ [root@v05-apppre-rabbitmq ytd_src]# wget http://www.rabbitmq.com/releases/erlang/erlang-18.2-1.el6.x86_64.rpm --2017-10-30 07:30:33-- http://www.rabbitmq.com/releases/erlang/erlang-18.2-1.el6.x86_64.rpm 正在解析主机 www.rabbitmq.com (www.rabbitmq.com)... 104.20.62.197, 104.20.63.197, 2400:cb00:2048:1::6814:3fc5, ... 正在连接 www.rabbitmq.com (www.rabbitmq.com)|104.20.62.197|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:18354700 (18M) [application/x-redhat-package-manager] 正在保存至: “erlang-18.2-1.el6.x86_64.rpm” 100%[===============================================================================>] 18,354,700 134KB/s 用时 3m 41s 2017-10-30 07:34:16 (81.0 KB/s) - 已保存 “erlang-18.2-1.el6.x86_64.rpm” [18354700/18354700]) [root@v05-apppre-rabbitmq ytd_src]# ll 总用量 17928 -rw-r--r-- 1 root root 18354700 1月 3 2016 erlang-18.2-1.el6.x86_64.rpm [root@v05-apppre-rabbitmq ytd_src]# rpm -ivh erlang-18.2-1.el6.x86_64.rpm 准备中... ################################# [100%] 正在升级/安装... 1:erlang-18.2-1.el6 ################################# [100%] [root@v05-apppre-rabbitmq ytd_src]# erlang版本地址: wget –no-cache http://www.convirture.com/repos/definitions/rhel/6.x/convirt.repo -O /etc/yum.repos.d/convirt.repo yum makecache yum install socat
2.rabbitMQ安装:
下载地址:https://dl.bintray.com/rabbitmq/rabbitmq-server-rpm/ [root@v05-apppre-rabbitmq ytd_src]# wget https://dl.bintray.com/rabbitmq/rabbitmq-server-rpm/rabbitmq-server-3.6.12-1.el6.noarch.rpm --2017-10-30 07:42:07-- https://dl.bintray.com/rabbitmq/rabbitmq-server-rpm/rabbitmq-server-3.6.12-1.el6.noarch.rpm 正在解析主机 dl.bintray.com (dl.bintray.com)... 35.161.20.85, 52.34.155.241 正在连接 dl.bintray.com (dl.bintray.com)|35.161.20.85|:443... 已连接。 ...... 已发出 HTTP 请求,正在等待回应... 200 OK 长度:4964260 (4.7M) [application/x-rpm] 正在保存至: “rabbitmq-server-3.6.12-1.el6.noarch.rpm” 100%[===============================================================================>] 4,964,260 1.54MB/s 用时 3.1s 2017-10-30 07:42:14 (1.54 MB/s) - 已保存 “rabbitmq-server-3.6.12-1.el6.noarch.rpm” [4964260/4964260]) [root@v05-apppre-rabbitmq ytd_src]# ll 总用量 22776 -rw-r--r-- 1 root root 18354700 1月 3 2016 erlang-18.2-1.el6.x86_64.rpm -rw-r--r-- 1 root root 4964260 9月 21 03:34 rabbitmq-server-3.6.12-1.el6.noarch.rpm [root@v05-apppre-rabbitmq ytd_src]# rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc [root@v05-apppre-rabbitmq ytd_src]# rpm -ivh rabbitmq-server-3.6.12-1.el6.noarch.rpm 错误:依赖检测失败: socat 被 rabbitmq-server-3.6.12-1.el6.noarch 需要 解决报错: [root@v05-apppre-rabbitmq ytd_src]# wget –no-cache http://www.convirture.com/repos/definitions/rhel/6.x/convirt.repo -O /etc/yum.repos.d/convirt.repo [root@v05-apppre-rabbitmq ytd_src]# yum makecache -y [root@v05-apppre-rabbitmq ytd_src]# yum install socat -y [root@v05-apppre-rabbitmq ytd_src]# rpm -ivh rabbitmq-server-3.6.12-1.el6.noarch.rpm 准备中... ################################# [100%] 正在升级/安装... 1:rabbitmq-server-3.6.12-1.el6 ################################# [100%]
3.安装管理插件:
[root@v05-apppre-rabbitmq ytd_src]# rabbitmq-plugins enable rabbitmq_management
4.启动服务:
[root@v05-apppre-rabbitmq ytd_src]# service rabbitmq-server start Starting rabbitmq-server (via systemctl): [ 确定 ]
5.浏览器访问:
http://10.100.62.41:15672
用系统默认的guest账号 结果登录失败 可能权限的问题吧,果断创建一个用户.
添加用户: [root@v05-apppre-rabbitmq ytd_src]# rabbitmqctl add_user admin 123456 Creating user "admin" [root@v05-apppre-rabbitmq ytd_src]# rabbitmqctl set_user_tags admin administrator Setting tags for user "admin" to [administrator] [root@v05-apppre-rabbitmq ytd_src]#
6.重启服务:
[root@v05-apppre-rabbitmq ytd_src]# service rabbitmq-server restart
至此MQ单机版就已经安装完成了.
解决/etc/rabbitmq/rabbitmq.config (not found)问题:
Config file /etc/rabbitmq/rabbitmq.config (not found) Database directory /var/lib/rabbitmq/mnesia/rabbit@localhost Log file /var/log/rabbitmq/rabbit@localhost.log SASL log file /var/log/rabbitmq/rabbit@localhost-sasl.log 新建一个文件:/etc/rabbitmq/rabbitmq.config,输入一下配置内容: [{rabbit, [{loopback_users, []}]}].
由于机器有限,就打算在测试环境给搭建个单机集群版的MQ。
单机集群版配置:
查看第一个节点的状态,(就是默认的单机版状态)
[root@v05-apppre-rabbitmq ~]# rabbitmqctl status Status of node \'rabbit@v05-apppre-rabbitmq\' [{pid,1957}, {running_applications, 我们看到默认启动的是rabbit@v05-apppre-rabbitmq
1.启动第一个节点(即是单机MQ)
RABBITMQ_NODE_PORT=5672 RABBITMQ_NODENAME=rabbit@v05-apppre-rabbitmq rabbitmq-server #由于这个MQ前面已经启动,在这里再启动时可能会报已经启动的错误,暂且不理.
2.启动第二个节点:
RABBITMQ_NODE_PORT=5673 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}] -rabbitmq_stomp tcp_listeners [61614] -rabbitmq_mqtt tcp_listeners [1884]" RABBITMQ_NODENAME=rabbit-01@v05-apppre-rabbitmq rabbitmq-server -detached [root@v05-apppre-rabbitmq ~]# rabbitmqctl status -n rabbit-01@v05-apppre-rabbitmq Status of node \'rabbit-01@v05-apppre-rabbitmq\' [{pid,17574}, ......
3.启动第三个节点:
RABBITMQ_NODE_PORT=5674 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15674}] -rabbitmq_stomp tcp_listeners [61615] -rabbitmq_mqtt tcp_listeners [18845]" RABBITMQ_NODENAME=rabbit-02@v05-apppre-rabbitmq rabbitmq-server -detached [root@v05-apppre-rabbitmq ~]# rabbitmqctl status -n rabbit-02@v05-apppre-rabbitmq Status of node \'rabbit-02@v05-apppre-rabbitmq\' [{pid,19076}, ......
集群操作:
节点二(rabbit-01@v05-apppre-rabbitmq)添加到集群:
停止第二个节点的应用程序: [root@v05-apppre-rabbitmq ~]# rabbitmqctl -n rabbit-01@v05-apppre-rabbitmq stop_app Stopping rabbit application on node \'rabbit-01@v05-apppre-rabbitmq\' 重新设置第二个节点的元数据和状态为清空状态 [root@v05-apppre-rabbitmq ~]# rabbitmqctl -n rabbit-01@v05-apppre-rabbitmq reset Resetting node \'rabbit-01@v05-apppre-rabbitmq\' [root@v05-apppre-rabbitmq ~]# 将rabbit-01@v05-apppre-rabbitmq节点加入rabbit@v05-apppre-rabbitmq集群节点中 [root@v05-apppre-rabbitmq ~]# rabbitmqctl -n rabbit-01@v05-apppre-rabbitmq join_cluster rabbit@v05-apppre-rabbitmq Clustering node \'rabbit-01@v05-apppre-rabbitmq\' with \'rabbit@v05-apppre-rabbitmq\' [root@v05-apppre-rabbitmq ~]# 重新启动rabbit-01@v05-apppre-rabbitmq节点 [root@v05-apppre-rabbitmq ~]# rabbitmqctl -n rabbit-01@v05-apppre-rabbitmq start_app Starting node \'rabbit-01@v05-apppre-rabbitmq\'
节点三添加到集群:
[root@v05-apppre-rabbitmq ~]# rabbitmqctl -n rabbit-02@v05-apppre-rabbitmq stop_app Stopping rabbit application on node \'rabbit-02@v05-apppre-rabbitmq\' [root@v05-apppre-rabbitmq ~]# rabbitmqctl -n rabbit-02@v05-apppre-rabbitmq reset Resetting node \'rabbit-02@v05-apppre-rabbitmq\' [root@v05-apppre-rabbitmq ~]# rabbitmqctl -n rabbit-02@v05-apppre-rabbitmq join_cluster rabbit@v05-apppre-rabbitmq Clustering node \'rabbit-02@v05-apppre-rabbitmq\' with \'rabbit@v05-apppre-rabbitmq\' [root@v05-apppre-rabbitmq ~]# [root@v05-apppre-rabbitmq ~]# rabbitmqctl -n rabbit-02@v05-apppre-rabbitmq start_app Starting node \'rabbit-02@v05-apppre-rabbitmq\' [root@v05-apppre-rabbitmq ~]#
查看集群状态:
[root@v05-apppre-rabbitmq ~]# rabbitmqctl cluster_status -n rabbit@v05-apppre-rabbitmq Cluster status of node \'rabbit@v05-apppre-rabbitmq\' [{nodes,[{disc,[\'rabbit-01@v05-apppre-rabbitmq\', \'rabbit-02@v05-apppre-rabbitmq\', \'rabbit@v05-apppre-rabbitmq\']}]}, {running_nodes,[\'rabbit-02@v05-apppre-rabbitmq\', \'rabbit-01@v05-apppre-rabbitmq\', \'rabbit@v05-apppre-rabbitmq\']}, {cluster_name,<<"rabbit@v05-apppre-rabbitmq">>}, {partitions,[]}, {alarms,[{\'rabbit-02@v05-apppre-rabbitmq\',[]}, {\'rabbit-01@v05-apppre-rabbitmq\',[]}, {\'rabbit@v05-apppre-rabbitmq\',[]}]}] [root@v05-apppre-rabbitmq ~]#
参考文档:http://www.cnblogs.com/wanglan/p/7662471.html
http://blog.csdn.net/Java_HuiLong/article/details/73718714
https://github.com/rabbitmq/erlang-rpm
http://www.rabbitmq.com/download.html
以上是关于CentOS下 RabbitMQ安装配置:的主要内容,如果未能解决你的问题,请参考以下文章
CentOS Stream 9下RabbitMQ安装教程(最新RabbitMQ安装教程)