centos/rhel 6.5(更新至centos 7)下rabbitmq安装(最简单方便的方式)

vim /etc/hosts 增加

127.0.0.1 hostname

不然启动的时候可能会报如下错误:

[root@devel2 rabbitmq]# rabbitmq-server
ERROR: epmd error for host devel2: timeout (timed out)

 

wget -c http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
yum install erlang
rpm -Uvh  rabbitmq-server-3.4.3-1.noarch.rpm
在命令敲rabbitmq-server。不会报command not found就OK了。
/etc/init.d/rabbitmq-server start

如果启动报:node with name "rabbit" already running on "mail"
vim /etc/rabbitmq/rabbitmq-env.conf
NODENAME=rabbit@localhost

NODE_IP_ADDRESS=127.0.0.1

 

--这两天新装机器,发现上述链接失效了。下面使用下载版erl安装,亲测,如下:

从https://www.erlang-solutions.com/resources/download.html下载R16B03版本的erlang。(如果已经存在大于等于该版本的erlang,一般也是可以的,比如erlang 18.3,可以rpm -qa | grep erl检查下)

rpm ivh esl-erlang_16.b.3-1~centos~6_amd64.rpm

export ERL_HOME=/usr/local/erlang

PATH=$RABBITMQ_HOME/sbin:$ERL_HOME/bin:$JAVA_HOME/bin:$PATH:$HOME/bin

安装完成后,输入erl看是否跳出交互界面,如下:

[root@dev-server local]# erl
Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.4  (abort with ^G)
1>

 

注:上述安装方式在centos 7下可能会出错(这两天在本地搭个应用环境,缺少很多依赖,整理如下)

根据https://www.vultr.com/docs/how-to-install-rabbitmq-on-centos-7所述安装erlang(2019更新,如果无法使用yum安装成功,推荐移步到https://www.cnblogs.com/zhjh256/p/10469732.html稳定、可靠)。

yum install socat 

为了最方便不易出错,使用unix-generic.tar.gz通用版,不用rpm和源码。

从http://www.rabbitmq.com/releases/rabbitmq-server/v3.5.7/下载rabbitmq-server-generic-unix-3.5.7.tar.gz

tar xzvf rabbitmq-server-generic-unix-3.5.7.tar.gz

PS:如果遇到是tar.xz后缀,可使用xz -d ***.tar.xz 解压缩。

ln -s rabbitmq_server-3.5.7 rabbitmq    # 在3.7中不能使用ln -s rabbitmq_server-3.5.7/ rabbitmq,否则会报下列错误:

escript: exception error: undefined function rabbitmqctl_escript:main/1
  in function  escript:run/2 (escript.erl, line 758)
  in call from escript:start/1 (escript.erl, line 277)
  in call from init:start_em/1 
  in call from init:do_boot/3

 

export RABBITMQ_HOME=/usr/local/rabbitmq

export PATH=$RABBITMQ_HOME/sbin:$PATH

启动rabbitmq。

 [root@dev-server ~]# rabbitmq-server -detached #后台模式

              RabbitMQ 3.5.7. Copyright (C) 2007-2015 Pivotal Software, Inc.
  ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
  ##  ##
  ##########  Logs: /usr/local/rabbitmq/sbin/../var/log/rabbitmq/rabbit@dev-server.log
  ######  ##        /usr/local/rabbitmq/sbin/../var/log/rabbitmq/rabbit@dev-server-sasl.log
  ##########
              Starting broker...

查看rabbitmq状态:

[root@dev-server ~]# rabbitmqctl status
Status of node 'rabbit@dev-server' ...
[{pid,53837},
 {running_applications,[{rabbit,"RabbitMQ","3.5.7"},
                        {os_mon,"CPO  CXC 138 46","2.2.14"},
                        {xmerl,"XML parser","1.3.6"},
                        {mnesia,"MNESIA  CXC 138 12","4.11"},
                        {sasl,"SASL  CXC 138 11","2.3.4"},
                        {stdlib,"ERTS  CXC 138 10","1.19.4"},
                        {kernel,"ERTS  CXC 138 10","2.16.4"}]},
 {os,{unix,linux}},
 {erlang_version,"Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [async-threads:64] [hipe] [kernel-poll:true]\n"},
 {memory,[{total,34723952},
          {connection_readers,0},
          {connection_writers,0},
          {connection_channels,0},
          {connection_other,2728},
          {queue_procs,2728},
          {queue_slave_procs,0},
          {plugins,0},
          {other_proc,13324200},
          {mnesia,57456},
          {mgmt_db,0},
          {msg_index,42504},
          {other_ets,704840},
          {binary,13944},
          {code,16499289},
          {atom,602729},
          {other_system,3473534}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,784151347},
 {disk_free_limit,50000000},
 {disk_free,31549009920},
 {file_descriptors,[{total_limit,924},
                    {total_used,3},
                    {sockets_limit,829},
                    {sockets_used,1}]},
 {processes,[{limit,1048576},{used,123}]},
 {run_queue,0},
 {uptime,86}]

 

启用控制台

[root@dev-server ~]# 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@dev-server... started 6 plugins.

在某些情况下,可能会出现如下错误:


Error: The following plugins could not be found:
  rabbitmq_management

此时是因为rabbitmq查找插件的路径不正确所致。可按照如下方式解决:

mkdir /etc/rabbitmq

 vi /etc/rabbitmq/rabbitmq-env.conf    #这个是rabbitmq环境变量的配置文件,这个文件的位置是确定和不能改变的,位于:/etc/rabbitmq或$RABBITMQ_HOME/etc/rabbitmq目录下(视具体的安装方式而定),具体可参考http://www.rabbitmq.com/configure.html

增加如下配置项:

RABBITMQ_MNESIA_BASE=/usr/local/rabbitmq/data
RABBITMQ_LOG_BASE=/usr/local/rabbitmq/log
RABBITMQ_PLUGINS_DIR=/usr/local/rabbitmq/plugins

或者也可以在sbin/rabbitmq-env中增加。

重启rabbitmq,问题解决。

PS:rabbitmq的标准配置文件是rabbitmq.config(从rabbitmq 3.7开始,调整为了rabbitmq.conf,采用k/v格式,而不是类似json格式),它既有默认的目录,也可以在rabbitmq-env.conf文件中配置。,具体可参考http://www.rabbitmq.com/configure.html

rabbitmq对erlang的版本要求如下:

 参考http://www.rabbitmq.com/which-erlang.html

注:如果windows下报 node with name "rabbit" already running on XXX,则先执行rabbitmqctl.bat stop,再启动即可。

 还需要注意的是,因为rabbitmq依赖于各种环境变量确定相关值和路劲,所以对于二进制安装,一定要在rabbitmq-env中设置RABBITMQ_LOG_BASE确保日志会正常生成,默认情况下它不会自动生成到RABBITMQ_BASE下,也不会到/var/lib/rabbitmq目录下。具体可见http://rabbitmq.docs.pivotal.io/36/rabbit-web-docs/relocate.html。

默认情况下,web控制台guest用户只允许localhost登录,所以因先创建管理员用户,并授权如下:

[root@localhost ~]# rabbitmqctl add_user admin 123456
Adding user "admin" ...
[root@localhost ~]# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...
[root@localhost ~]# rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/" ...

 登录http://IP:15672/访问。如下:

 

rabbitmq其它插件安装

web mqtt,支持websocket,参考:http://www.rabbitmq.com/web-mqtt.html

posted @ 2016-09-30 08:12  zhjh256  阅读(1732)  评论(0编辑  收藏  举报