参考资料:http://blog.csdn.net/yunfeng482/article/details/72853983
一、rabbitmq简介
MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法。应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们。消息传递指的是程序之间通过在消息中发送数据进行通信,而不是通过直接调用彼此来通信,直接调用通常是用于诸如远程过程调用的技术。排队指的是应用程序通过 队列来通信。队列的使用除去了接收和发送应用程序同时执行的要求。其中较为成熟的MQ产品有IBM WEBSPHERE MQ等等。
RabbitMQ是一个在AMQP基础上完成的,可复用的企业消息系统。他遵循Mozilla Public License开源协议。
二、安装
1. 依赖环境的安装。
[[email protected] ~]# yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel unixODBC unixODBC-devel httpd python-simplejson
2. erlang语言环境的安装(rabbitMq是用erlang分布式语言开发的)
三种方法安装:编译安装,rpm安装,yum安装。我这里下载的rpm包安装的。
wget http://www.rabbitmq.com/releases/erlang/erlang-18.1-1.el6.x86_64.rpm rpm -ivh erlang-18.1-1.el6.x86_64.rpm
erlang语言编译配置选项:
–prefix 指定安装目录
–enable-smp-support启用对称多处理支持(Symmetric Multi-Processing对称多处理结构的简称)
–enable-threads启用异步线程支持
–enable-sctp启用流控制协议支持(Stream Control Transmission Protocol,流控制传输协议)
–enable-kernel-poll启用Linux内核poll
–enable-hipe启用高性能Erlang –with-ssl 启用ssl包 –without-javac
不用java编译
配置erlang环境变量:
vim /etc/profile export PATH=$PATH:/usr/lib64/erlang/bin/ #erlang安装路径 source /etc/profil
测试erlang安装是否成功:
[[email protected] ~]# erl Erlang/OTP 17 [erts-6.2] [source] [smp:2:2] [async-threads:10] [kernel-poll:false] Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] Eshell V7.1 (abort with ^G) #erlang版本号
3. 安装socat包
安装socat依赖包,否则在安装rabbitmq时会出现报错信息如下:
[[email protected] ~]# rpm -ivh rabbitmq-server-3.6.6-1.el6.noarch.rpm warning: rabbitmq-server-3.6.6-1.el6.noarch.rpm: Header V4 RSA/SHA1 Signature, key ID 6026dfca: NOKEY error: Failed dependencies: erlang >= R16B-03 is needed by rabbitmq-server-3.6.6-1.el6.noarch socat is needed by rabbitmq-server-3.6.6-1.el6.noarch
yum安装socat:
[[email protected] ~]# yum -y install socat Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.163.com * extras: mirrors.163.com * updates: mirrors.zju.edu.cn No package socat available. Error: Nothing to do
此时会报错没有socat包或是找不到socat包,解决方法安装centos的epel的扩展源
[[email protected] ~]# yum -y install epel-release [[email protected] ~]# yum -y install socat #重新安装socat
4. 安装rabbitmq
[[email protected] ~]# wget https://github.com/rabbitmq/rabbitmq-server/releases/download/rabbitmq_v3_6_11/rabbitmq-server-3.6.11-1.el6.noarch.rpm [[email protected] ~]# rpm -i –nodeps rabbitmq-server-3.6.6-1.el6.noarch.rpm #不做依赖检查
生成配置文件
[[email protected] ~]# cp /usr/share/doc/rabbitmq-server-3.6.6/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config
启动rabbitmq
[[email protected] ~]# service rabbitmq-server start #报出错误信息 Starting rabbitmq-server: rmdir: failed to remove `/var/run/rabbitmq’: Directory not empty FAILED - check /var/log/rabbitmq/startup_{log, _err} rabbitmq-server.
解决方法:
[[email protected] ~]# ln -s /usr/lib64/erlang/bin/erl /usr/bin/erl #并在/etc/hosts中加入一行:127.0.0.1 主机名
再次启动rabbitmq:
[[email protected] ~]# 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
开启管理页面插件:
[[email protected] ~]# rabbitmq-plugins enable rabbitmq_management
添加管理员账号 :
[[email protected] ~]# rabbitmqctl add_user rabbitadmin 123456 Creating user "rabbitadmin" [[email protected] ~]# rabbitmqctl set_user_tags rabbitadmin administrator #分配用户标签 Setting tags for user "rabbitadmin" to [administrator] [[email protected] ~]# rabbitmqctl list_users #创建和赋角色完成后查看并确认 Listing users rabbitadmin [administrator] guest [administrator]
登录rabbitmq管理界面:
浏览器输入地址:http://服务器IP地址:15672/
用户名密码:rabbitadmin/123456
自此,整个rabbitmq-server消息中间件就搭建完成了。