rabbitmq的坑

刚接触rabbitmq,今天早上发现一个发布消息的进程僵死了,最后发现是rabbitmq默认的磁盘占用是80%,超过就僵死了。

搜了一下,可以删除vhost,再重新建立vhost,这样才能释放空间。反正要停止服务几分钟,还不如添加一个硬盘大点的节点,平衡之后将现在这个节点成为成为内存节点。废话不多说,看代码。

 在新节点上设置env,如下

echo >  /etc/rabbitmq/rabbitmq-env.conf <<EOF

RABBITMQ_MNESIA_BASE=/pool/rabbitmq/data
RABBITMQ_LOG_BASE=/pool/rabbitmq/log

EOF

 

 

RabbitMQ会提供一些机制比如把exchange queue设置为durable,persistent mode设置为2,等等来尽可能保证消息不丢失,但是这种保证是有限的.即使你该做的都做了,RabbitMQ节点当掉还是有可能出现消息丢失的情况.这是因为RabbitMQ并没有在节点之间做数据复制(Data Replicate).没有特殊的配置(后面会提到Mirrored Queue),一个队列的数据只会出现在Queue所属的节点.

 

而且数据量大时继续插入数据很容易出现如下警告信息
Mnesia(nonode@nohost): ** WARNING ** Mnesia is overloaded: {dump_log,
time_threshold}

 

消息是分发到多个队列的?AMQP协议里面定义了几种不同类型的exchange:direct, fanout, topic, and headers. 每一种都实现了一种 routing 算法. header的路由消息并不依赖routing key而是去匹配AMQP消息的header部分,这和下面提到的direct exchange如出一辙,但是性能要差很多,在实际场景中几乎不会被用到.

 

创建queue和exchange默认情况下都是没有持久化的,节点重启之后queue和exchange就会消失,这里需要特别指定queue和exchange的durable属性.

 

transient is for msgs sent to transient queues. This directory is blown away on startup because no transient queues survive broker restart. 
persistent is fro msgs sent to durable queues.

Repeat your test but declare the queue as exclusive. You should find that the shutdown of the broker is then much much faster. 

 

新坑:rabbitmq server宕掉后重启报错,检查了一下,因为有节点在发消息,把这些节点都关掉以后,重启成功 

新坑:程序里有一处地方试图在connect之前disconnect,报Detail: "Access refused for user 'guest'\n",这是因为disconnect也会试图连接,因为没有connect,默认会用guest连接,而我已经把guest用户删除掉了,所以才会报这个错误

 新坑:一个节点触发memory resource limit alarm,堵塞消息大发送和接受,将limit从默认的0.4设为0.8,某个消息接受脚本仍然堵塞在那里,需要重启,要好好z研究研究

  新坑: {error,{inconsistent_cluster,"Node rabbit@zw_81_80 thinks it's clustered with node rabbit@zw_81_86, but rabbit@zw_81_86 disagrees"}} 修改  /pool/rabbitmq/data/rabbit\@zw_81_80/cluster_nodes.config 把改节点删除掉。

 

 

Permissions

The management plugin extends the existing permissions model somewhat. Users can be given arbitrary tags within RabbitMQ. The management plugin makes use of tags called "management", "monitoring" and "administrator". The following table shows what the different types of user can do:

TagCapabilities
(None)No access to the management plugin
managementAnything the user could do via AMQP plus:
  • List virtual hosts to which they can log in via AMQP
  • View all queues, exchanges and bindings in "their" virtual hosts
  • View and close their own channels and connections
  • View "global" statistics covering all their virtual hosts, including activity by other users within them
monitoringEverything "management" can plus:
  • List all virtual hosts, including ones they could not log in to via AMQP
  • View other users's connections and channels
  • View node-level data such as memory use and clustering
  • View truly global statistics for all virtual hosts
administratorEverything "monitoring" can plus:
  • Create and delete virtual hosts
  • View, create and delete users
  • View, create and delete permissions
  • Close other users's connections

Note that since "administrator" does everything "monitoring" does, and "monitoring" does everything "management" does, you only need to give each user a maximum of one tag.

Normal RabbitMQ permissions still apply to monitors and administrators; just because a user is a monitor or administrator does not give them full access to exchanges, queues and bindings through either AMQP or the management plugin.

All users can only list objects within a particular virtual host if they have any permissions for that virtual host.

If you get locked out due to only having non-administrator users, or no users at all, you can userabbitmqctl add_user to create a non-administrator user and rabbitmqctl set_user_tags to promote a user to administrator.

 

 

部署完之后头一件就是添加监控,我们这用的是nagios

 

git clone https://github.com/jamesc/nagios-plugins-rabbitmq.git
cd /root/nagios-plugins-rabbitmq/scripts
cp * /usr/local/nagios/libexec/
chmod -R 775 /usr/local/nagios/libexec/
chown -R nagios.nagios /usr/local/nagios/libexec/

 

commands.cfg配置


# 'check_rabbitmq_server' command definition
define command{
command_name check_rabbitmq_server
command_line $USER1$/check_rabbitmq_server -p $ARG1$ -H $ARG2$
}

# 'check_rabbitmq_broker' command definition
define command{
command_name check_rabbitmq_broker
command_line $USER1$/check_rabbitmq_server -p $ARG1$ -H $HOSTNAME$
}

# 'check_rabbitmq_aliveness' command definition
define command{
command_name check_rabbitmq_aliveness
command_line $USER1$/check_rabbitmq_aliveness -p $ARG1$ -H $HOSTADDRESS$
}

# 'check_rabbitmq_objects' command definition
define command{
command_name check_rabbitmq_objects
command_line $USER1$/check_rabbitmq_objects -p $ARG1$ -H $HOSTADDRESS$
}

# 'check_rabbitmq_overview' command definition
define command{
command_name check_rabbitmq_overview
command_line $USER1$/check_rabbitmq_overview -p $ARG1$ -H $HOSTADDRESS$
}

# 'check_rabbitmq_queue' command definition
define command{
command_name check_rabbitmq_queue
command_line $USER1$/check_rabbitmq_queue -p $ARG1$ -H $HOSTADDRESS$
}

转载于:https://www.cnblogs.com/whymaths/archive/2013/01/27/2878529.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值