欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

rabbitmq安装及异常处理

程序员文章站 2022-03-05 20:25:16
...

        官网:

        https://www.rabbitmq.com/install-standalone-mac.html

 

       

安装erlang语言环境

安装依赖文件

yum install ncurses-devel
yum -y install openssl
yum -y install ssl

yum -y install xmlto
yum -y install python-simplejson
yum -y install python

进入 http://www.erlang.org/download.html 选择源文件下载

wget http://www.erlang.org/download/otp_src_17.5.tar.gz
tar zxvf otp_src_17.5.tar.gz
cd otp_src_17.5

阅读HOTO/INSTALL.md文件

./configure
make && make install

安装完成以后,执行erl看是否能打开eshell,用’halt().’退出,注意后面的点号,那是erlang的结束符。

[[email protected] ~]# erl
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V6.4 (abort with ^G)
1> 9+1.
10
2> halt().

安装RabbitMQ

安装依赖

yum install xmlto

创建主文件夹

mkdir rabbitmq
cd rabbitmq

直接使用RPM

wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.0/rabbitmq-server-3.6.0-1.noarch.rpm
rpm -ivh rabbitmq-server-3.6.0-1.noarch.rpm

编译安装包
进入http://www.rabbitmq.com/download.html选择最新的源码包

wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.0/rabbitmq-server-3.6.0.tar.xz
xz -d rabbitmq-server-3.6.0.tar.xz
tar xvf rabbitmq-server-3.6.0.tar
cd rabbitmq-server-3.6.0
make
make install TARGET_DIR=/opt/rabbitmq SBIN_DIR=/opt/rabbitmq/sbin MAN_DIR=/opt/rabbitmq/man DOC_INSTALL_DIR=/opt/rabbitmq/doc

使用

启动MQ

rabbitmq-server -detached

查看状态

rabbitmqctl status

启用管理插件

mkdir /etc/rabbitmq/
rabbitmq-plugins enable rabbitmq_management

停止服务

rabbitmqctl stop

添加账号
PS:默认账号guest只能在localhost访问

rabbitmqctl add_user admin admin

设置管理员

rabbitmqctl set_user_tags admin administrator

设置读写权限
命令使用户admin具有/vhost1这个virtual host中所有资源的配置、写、读权限以便管理其中的资源

rabbitmqctl set_permissions -p /vhost1 admin ‘.‘ ‘.‘ ‘.*’

查看账号

rabbitmqctl list_users

加入账号到配置

vi /etc/rabbitmq/rabbitmq.config
[
{rabbit, [{loopback_users, [“admin”]}]}
].

重启后 http://ip:15672 登录管理界面了

 

 

        异常处理:

        

64位CentOS6.2安装erlang及rabbitmqServer

CentOS 6.2 64bit 安装erlang及RabbitMQ Server

1、操作系统环境(CentOS 6.2 64bit)

[[email protected] ~]# cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m
[[email protected] ~]# cat /proc/cpuinfo grep "clflush size"
clflush size    : 64
clflush size    : 64
clflush size    : 64
clflush size    : 64
clflush size    : 64
clflush size    : 64
clflush size    : 64
clflush size    : 64
2、安装erlang依赖的基本环境
[[email protected] ~]# yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel
3、导入erlang源,并安装erlang
[[email protected] ~]# rpm --import http://binaries.erlang-solutions.com/debian/erlang_solutions.asc
[[email protected] ~]# wget -O /etc/yum.repos.d/erlang_solutions.repo  http://binaries.erlang-solutions.com/rpm/centos/erlang_solutions.repo
--2014-04-09 22:29:49--  http://binaries.erlang-solutions.com/rpm/centos/erlang_solutions.repo
Resolving binaries.erlang-solutions.com... 46.235.224.136
Connecting to binaries.erlang-solutions.com46.235.224.136:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://packages.erlang-solutions.com//rpm/centos/erlang_solutions.repo [following]
--2014-04-09 22:29:56--  http://packages.erlang-solutions.com//rpm/centos/erlang_solutions.repo
Resolving packages.erlang-solutions.com... 31.172.186.53
Connecting to packages.erlang-solutions.com31.172.186.53:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 245
Saving to: /etc/yum.repos.d/erlang_solutions.repo

100%[=================================================================================>] 245         --.-K/s   in 0s

2014-04-09 22:30:09 (34.0 MB/s) - /etc/yum.repos.d/erlang_solutions.repo
[[email protected] ~]# wget http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
Resolving tree.repoforge.org... 78.46.17.228
Connecting to tree.repoforge.org78.46.17.228:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm [following]
--2014-04-09 22:30:54--  http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
Resolving apt.sw.be... 193.1.193.67
Connecting to apt.sw.be193.1.193.67:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12700 (12K) [application/x-redhat-package-manager]
Saving to: rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

100%[=================================================================================>] 12,700      4.80K/s   in 2.6s

2014-04-09 22:31:07 (4.80 KB/s) - rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

[[email protected] ~]# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
[[email protected] ~]# rpm -i rpmforge-release-0.5.2-2.el6.rf.*.rpm
[[email protected] ~]# yum update
[[email protected] ~]# yum update --skip-broken
[[email protected] ~]# yum install erlang
4、测试erlang环境
[[email protected] ~]# erl
Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:false]

Eshell V5.10.4  (abort with ^G)
1> A=12.
12
2> A.
12
3>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution
^C[[email protected] ~]#
5、下载并安装rabbitmq-server  
[[email protected] ~]# wget -c http://www.rabbitmq.com/releases/rabbitmq-server/v3.3.0/rabbitmq-server-3.3.0-1.noarch.rpm
--2014-04-10 16:44:24--  
http://www.rabbitmq.com/releases/rabbitmq-server/v3.3.0/rabbitmq-server-3.3.0-1.noarch.rpm
Resolving www.rabbitmq.com... 192.240.153.117
Connecting to www.rabbitmq.com192.240.153.117:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3869384 (3.7M) [application/x-redhat-package-manager]
Saving to: “rabbitmq-server-3.3.0-1.noarch.rpm”

100%[======================================>] 3,869,384   11.9K/s   in 5m 37s

2014-04-10 16:50:10 (11.2 KB/s) - “rabbitmq-server-3.3.0-1.noarch.rpm” saved [3869384/3869384]

[[email protected] ~]#  yum install rabbitmq-server-3.3.0-1.noarch.rpm
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * rpmforge: ftp.riken.jp
 * updates: centos.ustc.edu.cn
Setting up Install Process
Examining rabbitmq-server-3.3.0-1.noarch.rpm: rabbitmq-server-3.3.0-1.noarch
Marking rabbitmq-server-3.3.0-1.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
> Package rabbitmq-server.noarch 0:3.3.0-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch     Version     Repository                         Size
================================================================================
Installing:
 rabbitmq-server   noarch   3.3.0-1     /rabbitmq-server-3.3.0-1.noarch   4.3 M

Transaction Summary
================================================================================
Install       1 Package(s)

Total size: 4.3 M
Installed size: 4.3 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : rabbitmq-server-3.3.0-1.noarch                               1/1

Installed:
  rabbitmq-server.noarch 0:3.3.0-1

Complete!
6、启动rabbitmq-server
[[email protected] ~]# /etc/init.d/rabbitmq-server start
Starting rabbitmq-server:
FAILED - check /var/log/rabbitmq/startup_{log, _err}
rabbitmq-server.
[[email protected] ~]# cat /var/log/rabbitmq/startup_err
[[email protected] ~]# cat /var/log/rabbitmq/startup_log
ERROR: epmd error for host leekwen: address (cannot connect to host/port)
[[email protected] ~]# hostname
leekwen
[[email protected] ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=leekwen
[[email protected] ~]# cat /etc/hosts
127.0.0.1       localhost
127.0.0.1       leekwen
::1             localhost
7、以上操作排除了因为主机名不同导致RabbitMQ-Server启动报错的问题,请修改主机名(参见上述步骤),再次启动RabbitMQ-Server
[[email protected] ~]# /etc/init.d/rabbitmq-server restart
Restarting rabbitmq-server: RabbitMQ is not running
FAILED - check /var/log/rabbitmq/startup_{log, _err}
rabbitmq-server.
8、结果同样报错,查看错误的日志:
[[email protected] ~]# cat /var/log/rabbitmq/startup_log
              RabbitMQ 3.3.0. Copyright (C) 2007-2013 GoPivotal, Inc.
  ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
  ##  ##
  ##########  Logs: /var/log/rabbitmq/[email protected]
  ######  ##        /var/log/rabbitmq/[email protected]
  ##########
              Starting broker...

BOOT FAILED
===========

Error description:
   {case_clause,
       {error,
           {{shutdown,
                {failed_to_start_child,tcp_listener,
                    {cannot_listen,{0,0,0,0,0,0,0,0},5672,eaddrinuse}}},
            {child,undefined,'rabbit_tcp_listener_sup_:::5672',
                {tcp_listener_sup,start_link,
                    [{0,0,0,0,0,0,0,0},
                     5672,
                     [inet6,binary,
                      {packet,raw},
                      {reuseaddr,true},
                      {backlog,128},
                      {nodelay,true},
                      {linger,{true,0}},
                      {exit_on_close,false}],
                     {rabbit_networking,tcp_listener_started,[amqp]},
                     {rabbit_networking,tcp_listener_stopped,[amqp]},
                     {rabbit_networking,start_client,[]},
                     "TCP Listener"]},
                transient,infinity,supervisor,
                [tcp_listener_sup]}}}}

Log files (may contain more information):
   /var/log/rabbitmq/[email protected]
   /var/log/rabbitmq/[email protected]

Stack trace:
   [{rabbit_networking,start_listener0,4,[]},
    {rabbit_networking,'-start_listener/4-lc$^0/1-0-',4,[]},
    {rabbit_networking,start_listener,4,[]},
    {rabbit_networking,'-boot_tcp/0-lc$^0/1-0-',1,[]},
    {rabbit_networking,boot_tcp,0,[]},
    {rabbit_networking,boot,0,[]},
    {rabbit,'-run_boot_step/1-lc$^1/1-1-',1,[]},
    {rabbit,run_boot_step,1,[]}]

BOOT FAILED
===========

Error description:
   {could_not_start,rabbit,
    {bad_return,
     {{rabbit,start,[normal,[]]},
      {'EXIT',
       {rabbit,failure_during_boot,
        {case_clause,
         {error,
          {{shutdown,
            {failed_to_start_child,tcp_listener,
             {cannot_listen,{0,0,0,0,0,0,0,0},5672,eaddrinuse}}},
           {child,undefined,'rabbit_tcp_listener_sup_:::5672',
            {tcp_listener_sup,start_link,
             [{0,0,0,0,0,0,0,0},
              5672,
              [inet6,binary,
               {packet,raw},
               {reuseaddr,true},
               {backlog,128},
               {nodelay,true},
               {linger,{true,0}},
               {exit_on_close,false}],
              {rabbit_networking,tcp_listener_started,[amqp]},
              {rabbit_networking,tcp_listener_stopped,[amqp]},
              {rabbit_networking,start_client,[]},
              "TCP Listener"]},
            transient,infinity,supervisor,
            [tcp_listener_sup]}}}}}}}}}

Log files (may contain more information):
   /var/log/rabbitmq/[email protected]
   /var/log/rabbitmq/[email protected]

{"init terminating in do_boot",{rabbit,failure_during_boot,{could_not_start,rabb                                                                                        use,{error,{{shutdown,{failed_to_start_child,tcp_listener,{cannot_listen,{0,0,0,                                                                                        stener_sup,start_link,[{0,0,0,0,0,0,0,0},5672,[inet6,binary,{packet,raw},{reusea                                                                                        networking,tcp_listener_started,[amqp]},{rabbit_networking,tcp_listener_stopped,                                                                                        or,[tcp_listener_sup]}}}}}}}}}}}
tail: /var/log/rabbitmq/startup_log: file truncated        [FAILED]

[[email protected] ~]# cat /var/log/rabbitmq/startup_err

Crash dump was written to: erl_crash.dump
init terminating in do_boot ()
9、出现如上的错误,可能是因为5672端口已经被占用的原因。
查看5672端口的情况,如果有进程占用此端口,请将它关闭后,重新启动RabbitMQ-Server;
[[email protected] ~]# netstat -atn grep 5672
tcp        0      0 0.0.0.0:5672                0.0.0.0:*                   LISTEN
[[email protected] ~]# lsof -i:5672
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
qpidd   1901 qpidd   10u  IPv4  13941      0t0  TCP *:amqp (LISTEN)
[[email protected] ~]# chkconfig qpidd off
[[email protected] ~]# netstat -atn grep 5672
tcp        0      0 0.0.0.0:5672                0.0.0.0:*                   LISTEN
[[email protected] ~]# chkconfig qpidd --list
qpidd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
[[email protected] ~]# /etc/init.d/qpidd stop
Stopping Qpid AMQP daemon:                                 [  OK  ]
[[email protected] ~]# netstat -atn grep 5672
tcp        0      0 127.0.0.1:25672             127.0.0.1:60925             TIME_WAIT
[[email protected] ~]# lsof -i:5672
[[email protected] ~]# /etc/init.d/rabbitmq-server start
Starting rabbitmq-server: SUCCESS
rabbitmq-server.
10、查看RabbitMQ服务启动的状态,并开启RabbitMQ的相应管理插件:
[[email protected] ~]# rabbitmqctl status
Status of node [email protected] ...
[{pid,716},
 {running_applications,[{rabbit,"RabbitMQ","3.3.0"},
                        {os_mon,"CPO  CXC 138 46","2.2.14"},
                        {mnesia,"MNESIA  CXC 138 12","4.11"},
                        {xmerl,"XML parser","1.3.5"},
                        {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 (erts-5.10.4) [source] [64-bit] [smp:8:8] [async-threads:30] [kernel-poll:true]\n"},
 {memory,[{total,36436456},
          {connection_procs,2704},
          {queue_procs,5408},
          {plugins,0},
          {other_proc,13704576},
          {mnesia,60240},
          {mgmt_db,0},
          {msg_index,24368},
          {other_ets,789624},
          {binary,13672},
          {code,16399491},
          {atom,594537},
          {other_system,4841836}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,6690450636},
 {disk_free_limit,50000000},
 {disk_free,47402364928},
 {file_descriptors,[{total_limit,924},
                    {total_used,3},
                    {sockets_limit,829},
                    {sockets_used,1}]},
 {processes,[{limit,1048576},{used,131}]},
 {run_queue,0},
 {uptime,83}]
...done.

[[email protected] ~]# netstat -atn grep 5672
tcp        0      0 0.0.0.0:25672               0.0.0.0:*                   LISTEN
tcp        0      0 :::5672                     :::*                        LISTEN
[[email protected] ~]# lsof -i:5672
COMMAND  PID     USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
beam.smp 716 rabbitmq   15u  IPv6 1948888      0t0  TCP *:amqp (LISTEN)
[[email protected] ~]# rabbitmq-plugins list
[ ] amqp_client                       3.3.0
[ ] cowboy                            0.5.0-rmq3.3.0-git4b93c2d
[ ] eldap                             3.3.0-gite309de4
[ ] mochiweb                          2.7.0-rmq3.3.0-git680dba8
[ ] rabbitmq_amqp1_0                  3.3.0
[ ] rabbitmq_auth_backend_ldap        3.3.0
[ ] rabbitmq_auth_mechanism_ssl       3.3.0
[ ] rabbitmq_consistent_hash_exchange 3.3.0
[ ] rabbitmq_federation               3.3.0
[ ] rabbitmq_federation_management    3.3.0
[ ] rabbitmq_management               3.3.0
[ ] rabbitmq_management_agent         3.3.0
[ ] rabbitmq_management_visualiser    3.3.0
[ ] rabbitmq_mqtt                     3.3.0
[ ] rabbitmq_shovel                   3.3.0
[ ] rabbitmq_shovel_management        3.3.0
[ ] rabbitmq_stomp                    3.3.0
[ ] rabbitmq_tracing                  3.3.0
[ ] rabbitmq_web_dispatch             3.3.0
[ ] rabbitmq_web_stomp                3.3.0
[ ] rabbitmq_web_stomp_examples       3.3.0
[ ] sockjs                            0.3.4-rmq3.3.0-git3132eb9
[ ] webmachine                        1.10.3-rmq3.3.0-gite9359c7
[[email protected] ~]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  mochiweb
  webmachine
  rabbitmq_web_dispatch
  amqp_client
  rabbitmq_management_agent
  rabbitmq_management
Plugin configuration has changed. Restart RabbitMQ for changes to take effect.
[[email protected] ~]# rabbitmq-plugins enable mochiweb webmachine rabbitmq_web_dispatch amqp_client rabbitmq_m                                                             anagement_agent rabbitmq_management
Plugin configuration unchanged.
[[email protected] ~]# rabbitmq-plugins list
[E] amqp_client                       3.3.0
[ ] cowboy                            0.5.0-rmq3.3.0-git4b93c2d
[ ] eldap                             3.3.0-gite309de4
[E] mochiweb                          2.7.0-rmq3.3.0-git680dba8
[ ] rabbitmq_amqp1_0                  3.3.0
[ ] rabbitmq_auth_backend_ldap        3.3.0
[ ] rabbitmq_auth_mechanism_ssl       3.3.0
[ ] rabbitmq_consistent_hash_exchange 3.3.0
[ ] rabbitmq_federation               3.3.0
[ ] rabbitmq_federation_management    3.3.0
[E] rabbitmq_management               3.3.0
[E] rabbitmq_management_agent         3.3.0
[ ] rabbitmq_management_visualiser    3.3.0
[ ] rabbitmq_mqtt                     3.3.0
[ ] rabbitmq_shovel                   3.3.0
[ ] rabbitmq_shovel_management        3.3.0
[ ] rabbitmq_stomp                    3.3.0
[ ] rabbitmq_tracing                  3.3.0
[E] rabbitmq_web_dispatch             3.3.0
[ ] rabbitmq_web_stomp                3.3.0
[ ] rabbitmq_web_stomp_examples       3.3.0
[ ] sockjs                            0.3.4-rmq3.3.0-git3132eb9
[E] webmachine                        1.10.3-rmq3.3.0-gite9359c7
[[email protected] ~]# rabbitmq-plugins list
[E] amqp_client                       3.3.0
[ ] cowboy                            0.5.0-rmq3.3.0-git4b93c2d
[ ] eldap                             3.3.0-gite309de4
[E] mochiweb                          2.7.0-rmq3.3.0-git680dba8
[ ] rabbitmq_amqp1_0                  3.3.0
[ ] rabbitmq_auth_backend_ldap        3.3.0
[ ] rabbitmq_auth_mechanism_ssl       3.3.0
[ ] rabbitmq_consistent_hash_exchange 3.3.0
[ ] rabbitmq_federation               3.3.0
[ ] rabbitmq_federation_management    3.3.0
[E] rabbitmq_management               3.3.0
[E] rabbitmq_management_agent         3.3.0
[ ] rabbitmq_management_visualiser    3.3.0
[ ] rabbitmq_mqtt                     3.3.0
[ ] rabbitmq_shovel                   3.3.0
[ ] rabbitmq_shovel_management        3.3.0
[ ] rabbitmq_stomp                    3.3.0
[ ] rabbitmq_tracing                  3.3.0
[E] rabbitmq_web_dispatch             3.3.0
[ ] rabbitmq_web_stomp                3.3.0
[ ] rabbitmq_web_stomp_examples       3.3.0
[ ] sockjs                            0.3.4-rmq3.3.0-git3132eb9
[E] webmachine                        1.10.3-rmq3.3.0-gite9359c7
[[email protected] ~]# netstat -atn grep 5672
tcp        0      0 0.0.0.0:25672               0.0.0.0:*                   LISTEN
tcp        0      0 :::5672                     :::*                        LISTEN
[[email protected] ~]# netstat -atn grep 15672
[[email protected] ~]# netstat -atn grep 55672
[[email protected] ~]# /etc/init.d/rabbitmq-server restart
Restarting rabbitmq-server: SUCCESS
rabbitmq-server.
[[email protected] ~]# netstat -atn grep 55672
[[email protected] ~]# netstat -atn grep 5672
tcp        0      0 0.0.0.0:15672               0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:25672               0.0.0.0:*                   LISTEN
tcp        0      0 127.0.0.1:54463             127.0.0.1:25672             TIME_WAIT
tcp        0      0 127.0.0.1:60321             127.0.0.1:25672             TIME_WAIT
tcp        0      0 127.0.0.1:25672             127.0.0.1:56750             TIME_WAIT
tcp        0      0 :::5672                     :::*                        LISTEN

就可以用guest,guest登陆http://192.168.1.101:15672端口了。

注意:如果此时你从端口15672或55672登陆不了,请关闭CentOS6.2的防火墙,再次登陆,

如果仍然出现无法登陆的想象,查看日志后,显示:

=ERROR REPORT==== 20-Apr-2014::00:55:15 ===
webmachine error: path="api/whoami"
"Unauthorized"
那么请运行如下的命令,增加用户admin,密码admin即可。  
[[email protected] ~]# rabbitmqctl add_user admin admin
Creating user "admin" ...
...done.
[[email protected] ~]# rabbitmqctl list_users
Listing users ...
admin   []
guest   [administrator]
...done.
[[email protected] ~]# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...
...done.
[[email protected] ~]# rabbitmqctl list_users
Listing users ...
admin   [administrator]
guest   [administrator]
...done.
到此,配置完成。 
相关标签: rabbitmq