RabbitMQ是流行的开源消息队列系统,是AMQP(Advanced Message Queuing Protocol高级消息队列协议)的标准实现,用erlang语言开发,所以RabbitMQ依赖Erlang,需要先安装Erlang。
安装过程如下:
[root@vmware rabbitmq]# wget https://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
[root@vmware rabbitmq]# sudo rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
[root@vmware rabbitmq]# sudo yum -y install erlang
等待安装完成。
可以通过wget直接在linux上下载,不过可能没有最新的版本,建议在去官网下载最新版本。因为我的linux是centOS 6.9,我这里选择的是RHEL/CentOs6.x。
[root@vmware rabbitmq]# cat /etc/redhat-release
CentOS release 6.9 (Final)
RabbitMQ对应的版本
然后将rabbitmq-server-3.7.7-1.el6.noarch.rpm文件上传到linux服务器,开始安装。
[root@vmware rabbitmq]# yum install rabbitmq-server-3.7.7-1.el6.noarch.rpm
安装完成后启动rabbitmq,但是不幸的是报错了,错误如下:
[root@vmware rabbitmq]# service rabbitmq-server start
Starting rabbitmq-server: FAILED - check /var/log/rabbitmq/startup_{log, _err}
rabbitmq-server.
我们打开/var/log/rabbitmq/startup_log看看日志情况:
ERROR: node with name "rabbit" already running on "vmware"错误
解决方法:新建/etc/rabbitmq/rabbitmq-env.conf文件,并写入
NODENAME=rabbit@localhost
NODE_IP_ADDRESS=127.0.0.1
然后查看ps -ef | grep rabbit是否还有相关进程,如果有就kill -9 xxxx,然后再次启动
[root@vmware rabbitmq]# service rabbitmq-server start
Starting rabbitmq-server: SUCCESS
rabbitmq-server.
到这里就安装成功。
常用的rabbitmq启动命令
service rabbitmq-server start
service rabbitmq-server stop
service rabbitmq-server status
service rabbitmq-server rotate-logs|
service rabbitmq-server restart
service rabbitmq-server condrestart
service rabbitmq-server try-restart
service rabbitmq-server reload
service rabbitmq-server force-reload
ps -ef | grep rabbitmq 查看rabbitMq进程
netstat -anplt | grep LISTEN rabbitmq默认监听端口15672/5672
[root@vmware copy]# sudo rabbitmq-plugins enable rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@localhost...
The following plugins have been enabled:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
started 3 plugins.
然后我们打开浏览器输入xxx.xxx.xxx.xxx:15672,使用默认用户名guest,密码也是guest,不过提示
User can only log in via localhost
因为rabbitmq从3.3.0开始禁止使用guest/guest权限通过除localhost外的访问,所以我们自己再创建登录用户并授权管理员
[root@vmware rabbitmq]# sudo rabbitmqctl add_user admin 123456
Adding user "admin" ...
[root@vmware rabbitmq]# sudo rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...
现在再在浏览器打开xxx.xxx.xxx.xxx:15672,输入admin,123456登录界面如下:
注意:记得要开放5672和15672端口
iptables -I INPUT -p tcp --dport 5672 -j ACCEPT
iptables -I INPUT -p tcp --dport 15672 -j ACCEPT