一、RedHat 7.2中安装与启动RabbitMQ
点击或复制链接下载:
http://www.rabbitmq.com/releases/erlang/erlang-18.3-1.el7.centos.x86_64.rpm
http://repo.iotti.biz/CentOS/7/x86_64/socat-1.7.3.2-5.el7.lux.x86_64.rpm
http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.5/rabbitmq-server-3.6.5-1.noarch.rpm
上传到 /usr/local/software文件夹中
使用XShell链接Linux,文件上传使用SmarTTy,SmarTTy也可以链接Linux,但对中文支持不好,好处是SmarTTy可以无需安装任何软件就可将windows文件上传到虚拟机中的Linux系统中
[root@bogon software]# ll
总用量 23588
-rw-r--r--. 1 root root 18345424 12月 16 00:46 erlang-18.3-1.el7.centos.x86_64.rpm
-rw-r--r--. 1 root root 5520417 12月 16 00:45 rabbitmq-server-3.6.5-1.noarch.rpm
-rw-r--r--. 1 root root 284676 12月 16 00:45 socat-1.7.3.2-5.el7.lux.x86_64.rpm
[root@bogon software]#
使用rpm命令安装,rpm命令会对软件环境、配置文件等进行自动配置,不会有rabbitmq.config配置文件
安装erlang-18.3-1.el7
[root@bogon software]# rpm -ivh erlang-18.3-1.el7.centos.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:erlang-18.3-1.el7.centos ################################# [100%]
[root@bogon software]#
如果直接安装rabbitmq-server-3.6.5-1,会提示"错误:依赖检测失败:socat 被 rabbitmq-server-3.6.5-1.noarch 需要",所以要先安装socat
[root@bogon software]# rpm -ivh rabbitmq-server-3.6.5-1.noarch.rpm
警告:rabbitmq-server-3.6.5-1.noarch.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID 6026dfca: NOKEY
错误:依赖检测失败:
socat 被 rabbitmq-server-3.6.5-1.noarch 需要
[root@bogon software]#
安装socat-1.7.3.2-5
[root@bogon software]# rpm -ivh socat-1.7.3.2-5.el7.lux.x86_64.rpm
警告:socat-1.7.3.2-5.el7.lux.x86_64.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID 53e4e7a9: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:socat-1.7.3.2-5.el7.lux ################################# [100%]
[root@bogon software]#
安装rabbitmq-server-3.6.5
[root@bogon software]# rpm -ivh rabbitmq-server-3.6.5-1.noarch.rpm
警告:rabbitmq-server-3.6.5-1.noarch.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID 6026dfca: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:rabbitmq-server-3.6.5-1 ################################# [100%]
[root@bogon software]#
打开rabbit.app文件按i键进行编辑
[root@bogon software]# vi /usr/lib/rabbitmq/lib/rabbitmq_server-3.6.5/ebin/rabbit.app
找到{loopback_users, [<<"guest">>]},改为{loopback_users, [guest]},修改loopback_users值的作用是修改RabbitMQ管控台的登录账号,默认是被注释的,修改完成后按i键,输入wq保存退出
输入rabbitmq后按tab自动补全,会出现三个命令
[root@bogon software]# rabbitmq
rabbitmqctl rabbitmq-plugins rabbitmq-server
rabbitmqctl对rabbitmq对rabbitmq进行操作
rabbitmq-plugins安装rabbitmq插件
rabbitmq-server开启、关闭rabbitmq服务
执行"rabbitmq-server start &"启动rabbitmq
[root@bogon software]# rabbitmq-server start &
[2] 10662
[root@bogon software]# ERROR: node with name "rabbit" already running on "bogon"
如果执行报错"node with name "rabbit" already running",则说明已经启动,我们执行ps -ef |grep rabbitmq命令查看正在执行的rabbitmq服务
[root@bogon software]# ps -ef |grep rabbitmq
root 9632 2002 0 02:43 pts/1 00:00:00 /bin/sh /usr/sbin/rabbitmq-server start
root 9642 9632 0 02:43 pts/1 00:00:00 su rabbitmq -s /bin/sh -c /usr/lib/rabbitm/bin/rabbitmq-server 'start'
rabbitmq 9643 9642 0 02:43 ? 00:00:00 /bin/sh -e /usr/lib/rabbitmq/bin/rabbitmq-server start
rabbitmq 9718 1 0 02:43 ? 00:00:00 /usr/lib64/erlang/erts-7.3/bin/epmd -daemon
rabbitmq 9731 9643 0 02:43 ? 00:00:06 /usr/lib64/erlang/erts-7.3/bin/beam -W w -A
我们可以看到有三个rabbitmq相关的进程rabbitmq 9643、rabbitmq 9718、rabbitmq 9731,终止这三个进程
[root@bogon software]# kill 9643
[root@bogon software]# kill 9718
[1]+ 完成 rabbitmq-server start
[root@bogon software]# kill 9731
再次查看rabbitmq服务,已经没有rabbitmq的服务了
[root@bogon software]# ps -ef | grep rabbitmq
root 11684 2002 0 03:48 pts/1 00:00:00 grep --color=auto rabbitmq
重新执行rabbitmq-server start &,启动rabbitmq服务
[root@bogon software]# rabbitmq-server start &
[1] 11686
[root@bogon software]#
RabbitMQ 3.6.5. Copyright (C) 2007-2016 Pivotal Software, Inc.
## ## Licensed under the MPL. See http://www.rabbitmq.com/
## ##
########## Logs: /var/log/rabbitmq/rabbit@bogon.log
###### ## /var/log/rabbitmq/rabbit@bogon-sasl.log
##########
Starting broker...
completed with 0 plugins.
[root@bogon software]#
我们看到打印信息Logs: /var/log/rabbitmq/rabbit@bogon.log, /var/log/rabbitmq/是日志存放的路径,bogon是主机名,通过以下命令修改主机名
[root@bogon software]# vi /etc/hostname
安装RabbitMQ插件,查看rabbitmq默认提供的插件
[root@bogon software]# rabbitmq-plugins list
Configured: E = explicitly enabled; e = implicitly enabled
| Status: [failed to contact rabbit@bogon - status not shown]
|/
[ ] amqp_client 3.6.5
[ ] cowboy 1.0.3
[ ] cowlib 1.0.1
[ ] mochiweb 2.13.1
[ ] rabbitmq_amqp1_0 3.6.5
[ ] rabbitmq_auth_backend_ldap 3.6.5
[ ] rabbitmq_auth_mechanism_ssl 3.6.5
[ ] rabbitmq_consistent_hash_exchange 3.6.5
[ ] rabbitmq_event_exchange 3.6.5
[ ] rabbitmq_federation 3.6.5
[ ] rabbitmq_federation_management 3.6.5
[ ] rabbitmq_jms_topic_exchange 3.6.5
[ ] rabbitmq_management 3.6.5
[ ] rabbitmq_management_agent 3.6.5
[ ] rabbitmq_management_visualiser 3.6.5
[ ] rabbitmq_mqtt 3.6.5
[ ] rabbitmq_recent_history_exchange 1.2.1
[ ] rabbitmq_sharding 0.1.0
[ ] rabbitmq_shovel 3.6.5
[ ] rabbitmq_shovel_management 3.6.5
[ ] rabbitmq_stomp 3.6.5
[ ] rabbitmq_top 3.6.5
[ ] rabbitmq_tracing 3.6.5
[ ] rabbitmq_trust_store 3.6.5
[ ] rabbitmq_web_dispatch 3.6.5
[ ] rabbitmq_web_stomp 3.6.5
[ ] rabbitmq_web_stomp_examples 3.6.5
[ ] sockjs 0.3.4
[ ] webmachine 1.10.3
使用rabbitmq-plugins enable + "插件名"命令开启RabbitMQ默认插件
[root@bogon ~]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
mochiweb
webmachine
rabbitmq_web_dispatch
amqp_client
rabbitmq_management_agent
rabbitmq_management
Applying plugin configuration to rabbit@bogon... started 6 plugins.
[root@bogon ~]#
rabbitmq默认启动rabbitmq_management 插件,该插件用来启动管控台,管控台默认端口号是15672,端口号5671用来与java端进行通信的端口号,25672是rabbitmq集群进行通信的端口号,打开浏览器输入虚拟机IP+:15672,账号密码为我们之前修改/usr/lib/rabbitmq/lib/rabbitmq_server-3.6.5/ebin/rabbit.app文件中{loopback_users, [guest]}的guset
可以看到管控台页面
二、rabbitmq的rabbitmqctl命令说明
基础操作:
rabbitmqctl start_app 启动rabbitmq服务
rabbitmqctl stop_app 关闭rabbitmq服务
rabbitmqctl status 节点状态
rabbitmqctl add_user username password 添加用户
rabbitmqctl list_users 查看所有用户
rabbitmqctl delete_users username 删除用户
rabbitmqctl clear_permissions -p vhostpath username 清除用户权限
rabbitmqctl list_user_permissions username 查询用户权限
rabbitmqctl change_password username newpassword 修改密码
rabbitmqctl set_permissions -p vhostpath username "." "." ".*" 设置用户权限
rabbitmqctl add_vhost vhostpath 创建虚拟主机
rabbitmqctl list_vhosts 查看所有虚拟主机,默认虚拟主机名为"/"
rabbitmqctl list_psermissions -p vhostpath 查询虚拟主机上所有权限
rabbitmqctl delete_vhost vhostpath 删除虚拟主机
rbbitmqctl list_queues 查询所有队列信息
rabbitmqctl -p vhostpath purge_queue blue 清除队列里的消息
高级操作:
rabbitmqctl reset 移除所有数据,要在rabbitmqctl stop_app之后使用
rabbitmqctl join_cluster <clusternode> [--ram] 组成集群命令,默认硬盘级别存储将消息落入磁盘,--ram内存级别存储将消息保存在内存中
rabbitmqctl change_culster_node_type disc | ram 修改集群节点的存储模式,磁盘存储,内存存储
rabbitmqctl forget_cluster_node [--offline] 忘记节点(摘除节点,当有节点坏掉,可以通过该命令摘除坏掉节点,这种方式是最简单的失败转移,--offine如果有主节点坏掉,这样整个rabbitmq服务无法启动,这时使用--offine命令可以在rabbitmq服务没有启动的时候摘除主节点)
rabbitmqctl rename_cluster_node oldnode1 newnode1 [newnode1] [newnode2...] 修改节点名称