联系
Knight's Tale » 技术

安装和配置RabbitMq in Generic Unix or Linux (BSD, Mac OS X)

2015-04-23 12:49

Generic Unix or Linux (BSD, Mac OS X)

Install the Server

解压缩的路径 就是 $RABBITMQ_HOME

可以先卸载掉mac版的 brew uninstall rabbitmq

Run RabbitMQ Server

配置

$RABBITMQ_HOME/etc/rabbitmq/rabbitmq-env.conf

需要新建一个

#example rabbitmq-env.conf file entries
#Rename the node
NODENAME=bunny@localhost
#Config file location and new filename bunnies.config
CONFIG_FILE=/Users/knightliao/usr/rabbit/rabbitmq_server-3.5.1/etc/rabbitmq/rabbitmq

这里要注意的是,/Users/knightliao/usr/rabbit/rabbitmq_server-3.5.1/etc/rabbitmq/rabbitmq不要写成 /Users/knightliao/usr/rabbit/rabbitmq_server- 3.5.1/etc/rabbitmq/rabbitmq.config 否则会找不到的!!

然后 /Users/knightliao/usr/rabbit/rabbitmq_server-3.5.1/etc/rabbitmq/rabbitmq.config 此文件将包含程序配置

运行

sbin/rabbitmq-server
或 rabbitmq-server -detached

运行结果:

              RabbitMQ 3.5.1. Copyright (C) 2007-2014 GoPivotal, Inc.
  ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
  ##  ##
  ##########  Logs: sbin/../var/log/rabbitmq/bunny@localhost.log
  ######  ##        sbin/../var/log/rabbitmq/bunny@localhost-sasl.log
  ##########
              Starting broker... completed with 0 plugins.

说明日志文件在:

/Users/knightliao/usr/rabbit/rabbitmq_server-3.5.1/var/log/rabbitmq

补充

rabbit的配置均是以 RABBITMQ_ 开头的,它的寻找规则是:

  • a shell environment variable called RABBITMQ_var_name is used if this is defined;
  • otherwise, a variable called var_name is used if this is set in the rabbitmq-env.conf file;
  • otherwise, a system-specified default value is used.

https://www.rabbitmq.com/configure.html#customise-general-unix-environment

可以看到

rabbit的port是 5672

常用端口

4369 (epmd), 25672 (Erlang distribution)
5672, 5671 (AMQP 0-9-1 without and with TLS)
15672 (if management plugin is enabled)
61613, 61614 (if STOMP is enabled)
1883, 8883 (if MQTT is enabled)

Default user access

https://www.rabbitmq.com/access-control.html

操作

sbin/rabbitmqctl clear_permissions guest

sbin/rabbitmqctl list_permissions

sbin/rabbitmqctl delete_user guest

sbin/rabbitmqctl add_user root MhxzKhl

sbin/rabbitmqctl set_user_tags root administrator

设置pikaq这个帐号对于rabbitmq的权限:

 sbin/rabbitmqctl set_permissions -p / pikaq ".*" ".*" ".*"
 sbin/rabbitmqctl set_permissions -p / root ".*" ".*" ".*"

如果没有设置 set_permissions 那可能会导致程序里连接不上rabbitmq,或者在admin页面无法看到所有的queue和exchanges

其它常用命令

可参考:

  • http://techv5.com/topic/1294/
  • https://www.rabbitmq.com/man/rabbitmqctl.1.man.html#Access%20control

rabbitmq_server-3.5.1 sbin/rabbitmqctl list_vhosts

  • add_vhost
  • delete_vhost
  • list_vhosts
  • set_permissions
  • clear_permissions
  • list_permissions
  • list_user_permissions
  • add_user
  • delete_user
  • change_password
  • set_user_tags
  • list_users

插件

web管理插件

rabbitmq-plugins enable rabbitmq_management

http://ww1.sinaimg.cn/bmiddle/60c9620fjw1erfc4s2rrbj20fc02at90.jpg

参考: http://blog.csdn.net/yasi_xi/article/details/8655348

如何更改端口号

修改 rabbitmq.config 文件中为

{rabbitmq_management,
    [
        {listener, [{port, 8019}]}
     ]},

这样端口号就改成了 8019了

Managing the Broker

Invoke rabbitmqctl stop to stop the server.

Invoke rabbitmqctl status to check whether it is running.

Controlling System Limits

We recommend allowing for at least 65536 file descriptors for user rabbitmq in production environments. 4096 should be sufficient for most development workloads.

ulimit: http://www.cnblogs.com/ibook360/archive/2012/05/11/2495405.html

可以使用这个链接进行更改: http://docs.basho.com/riak/latest/ops/tuning/open-files-limit/#Mac-OS-X

ulimit -n 65536
ulimit -u 2048