在RabbitMQ官網上下載對應系統版本的rabbitmq-server安裝包進行安裝。(官網提示,雖然rabbitmq-server的源會添加到標準的Debian和Ubuntu源中,但是一般都是舊的包,建議在官網直接下載最新的包進行安裝)
由於RabbitMQ是使用Erlang語言寫的,所以需要Erlang環境,Erlang版本對應的RabbitMQ版本對應表如下:
Erlang Release Series | Repositories that provide it |
---|---|
20.x | Erlang Solutions. Supported starting with 3.6.11. NOT SUPPORTED by earlier versions. |
19.x | Erlang Solutions,Debian Stretch,Debian Jessie backports, Ubuntu Zesty (17.04) |
18.x | Erlang Solutions, Ubuntu Yakkety (16.10), Ubuntu Xenial (16.04) |
17.x | Erlang Solutions,Debian Jessie,Debian Wheezy backports |
當前官網最新的包爲rabbitmq-server_3.6.14-1_all.deb,因此需要使用Erlang 20以上的版本。
都下載完成後,使用對應系統的安裝命令進行包的安裝即可,此處以ubuntu16爲例:
sudo dpkg -i esl-erlang_20.1-1~ubuntu~xenial_amd64.deb
//如果報缺少依賴則執行下一句解決依賴問題
sudo apt -f install
sudo dpkg -i rabbitmq-server_3.6.14-1_all.deb
//如果缺少依賴,同上
安裝完成後服務會自動啓動。以下介紹常用命令:
//啓動服務
sudo rabbitmq-server start
//關閉服務
sudo rabbitmq-server stop
//重啓rabbitmq
sudo rabbitmq-server restart
//後臺啓動
sudo rabbitmq-server –detached
//關閉整個節點,包括應用
sudo rabbitmqctl stop
//僅關閉應用
sudo rabbitmqctl stop_app
//啓動應用
sudo rabbitmqctl start_app
//查看所有安裝了的插件
sudo rabbitmq-plugins list
//啓動管理模塊插件
sudo rabbitmq-plugins enable rabbitmq_management
//關閉插件
sudo rabbitmq-plugins disable rabbitmq_management
//查看所有用戶(默認用戶名和密碼均爲:guest)
sudo rabbitmqctl list_users
//添加用戶並設置密碼
sudo rabbitmqctl add_user username userpass
//設置用戶權限
sudo rabbitmqctl set_user_tags username tagname
//修改用戶密碼
sudo rabbitmqctl change_password username newuserpass
RabbitMQ啓動後,相應端口信息:
端口 | 描述 |
---|---|
4369 | epmd, a peer discovery service used by RabbitMQ nodes and CLI tools |
5672, 5671 | used by AMQP 0-9-1 and 1.0 clients without and with TLS |
25672 | used by Erlang distribution for inter-node and CLI tools communication and is allocated from a dynamic range (limited to a single port by default, computed as AMQP port + 20000). See networking guide for details. |
15672 | HTTP API clients and rabbitmqadmin (only if the management plugin is enabled) |
61613, 61614 | STOMP clients without and with TLS (only if the STOMP plugin is enabled) |
1883, 8883 | (MQTT clients without and with TLS, if the MQTT plugin is enabled |
15674 | STOMP-over-WebSockets clients (only if the Web STOMP plugin is enabled) |
15675 | MQTT-over-WebSockets clients (only if the Web MQTT plugin is enabled) |
Linux系統上的System Limits限制:
使用如下命令可以查看系統對鏈接數量的限制:
ulimit -n
默認設置一般爲1024.此數量對於RabbitMQ來講,太可憐了。。。建議設置爲65536.開發環境中,使用4096也足夠了。
這裏有兩個需要設置的限制數量:①系統內核的允許文件持有數量限制(fs.file-max)以及每個用戶的限制(ulimit -n),前者必須大於後者才行!!!
fs.file-max設置方式:
echo 6553560 > /proc/sys/fs/file-max
或修改 /etc/sysctl.conf, 加入
fs.file-max = 65536重啓生效
ulimit設置方法:
系統默認的ulimit對文件打開數量的限制是1024,修改/etc/security/limits.conf並加入以下配置,永久生效
* soft nofile 65536
* hard nofile 65536
修改完之後,重啓即可生效
較新的Linux發行版(使用systemd進行啓動的發行版),使用該文件進行相關配置:
/etc/systemd/system/rabbitmq-server.service.d/limits.conf,如:
[Service]
LimitNOFILE=300000
修改完成後,可以使用以下命令進行檢查:
sudo rabbitmqctl status