CentOS 下安装RabbitMQ
一、安装Erlang
二、安装rabbitmq
下载地址:http://www.rabbitmq.com/install-generic-unix.html
tar -xJf rabbitmq-server-generic-unix-3.12.2.tar.xz
mv rabbitmq_server-3.12.2 /usr/local/rabbitmq
/usr/local/rabbitmq/sbin/rabbitmq-server -detached # 启动rabbitmq
如果启动未成功你可以看下是否rabbitmq端口给占用,rabbitmq用到端口为5672、15672
启动web管理插件
/usr/local/rabbitmq/sbin/rabbitmq-plugins enable rabbitmq_management
/usr/local/rabbitmq/sbin/rabbitmqctl add_user admin admin # 添加用户 用户名 密码
/usr/local/rabbitmq/sbin/rabbitmqctl set_user_tags admin administrator # 设置为管理员组
/usr/local/rabbitmq/sbin/rabbitmqctl set_permissions -p / admin ".*" ".*" ".*" # 设置/虚拟主机的管理权限
/usr/local/rabbitmq/sbin/rabbitmqctl stop # 停止rabbitmq
/usr/local/rabbitmq/sbin/rabbitmq-server -detached # 启动rabbitmq
重启之后,在浏览器执行http://192.168.10.8:15672/ 即可访问rabbitmq的管理界面,用户名和密码都是admin
三、RabbitMQ管理
1.Rabbitmq服务器的主要通过rabbitmqctl和rabbimq-plugins两个工具来管理,以下是一些常用功能:
若单机有多个实例,则使用一下命令来启动
/usr/local/rabbitmq/sbin/rabbitmq-server -detached
2.插件管理
开启某个插件:
/usr/local/rabbitmq/sbin/rabbitmq-plugins enable xxx
关闭某个插件:
/usr/local/rabbitmq/sbin/rabbitmq-plugins disable xxx
注意:重启服务器后生效。
3.virtual_host管理
新建virtual_host:
/usr/local/rabbitmq/sbin/rabbitmqctl add_vhost xxx
撤销virtual_host:
/usr/local/rabbitmq/sbin/rabbitmqctl delete_vhost xxx
4.用户管理
新建用户:
/usr/local/rabbitmq/sbin/rabbitmqctl add_user xxx pwd
删除用户:
/usr/local/rabbitmq/sbin/rabbitmqctl delete_user xxx
修改密码:
/usr/local/rabbitmq/sbin/rabbitmqctl change_password {username} {newpassword}
设置用户角色:
/usr/local/rabbitmq/sbin/rabbitmqctl set_user_tags {username} {tag ...}
Tag可以为 administrator,monitoring, management
5.权限管理
权限设置:set_permissions [-p vhostpath] {user} {conf} {write} {read}
vhostpath:vhost路径
user:用户名
conf:一个正则表达式match哪些配置资源能够被该用户访问
write:一个正则表达式match哪些配置资源能够被该用户写
read:一个正则表达式match哪些配置资源能够被该用户读
6.获取服务器状态信息
a.服务器状态:
/usr/local/rabbitmq/sbin/rabbitmqctl status
b.队列信息:
/usr/local/rabbitmq/sbin/rabbitmqctl list_queues [-p vhostpath] [queueinfoitem ...]
Queueinfoitem可以为:name,durable,auto_delete,arguments,messages_ready,messages_unacknowledged,messages,consumers,memory
c.Exchange信息:
/usr/local/rabbitmq/sbin/rabbitmqctl list_exchanges[-p vhostpath] [exchangeinfoitem ...]
Exchangeinfoitem有:name,type,durable,auto_delete,internal,arguments.
d.Binding信息:
/usr/local/rabbitmq/sbin/rabbitmqctl list_bindings[-p vhostpath] [bindinginfoitem ...]
Bindinginfoitem有:source_name,source_kind,destination_name,destination_kind,routing_key,arguments
e.Connection信息:
/usr/local/rabbitmq/sbin/rabbitmqctl list_connections [connectioninfoitem ...]
Connectioninfoitem有:recv_oct,recv_cnt,send_oct,send_cnt,send_pend等
f.Channel信息:
/usr/local/rabbitmq/sbin/rabbitmqctl list_channels[channelinfoitem ...]
Channelinfoitem有consumer_count,messages_unacknowledged,messages_uncommitted,acks_uncommitted,messages_unconfirmed,prefetch_count,client_flow_blocked
四、设置开机启动
编辑/usr/lib/systemd/system/rabbitmq.service
文件
[Unit]
Description=RabbitMQ
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/rabbitmq/sbin/rabbitmq-server -detached
ExecReload=/usr/local/rabbitmq/sbin/rabbitmq-server stop
Restart=on-failure
RestartSec=3
[Install]
WantedBy=multi-user.target
启动RabbitMQ
systemctl start rabbitmq.service
在开机时启用
systemctl enable rabbitmq.service
五、编辑/etc/profile文件
在/etc/profile
文件末尾追加一下内容
# RabbitMQ
export PATH=$PATH:/usr/local/rabbitmq/sbin
6、执行一下命令使配置生效
source /etc/profile