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:

Tag Capabilities
(None) No access to the management plugin
management Anything 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
monitoring Everything "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
administrator Everything "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$
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM