目錄html
本文只討論linux下的Rabbitmq安裝。linux
rabbitmq依賴於Erlang,需先安裝,推薦安裝rabbitmq/erlang-rpm:ios
#clone源碼 git clone https://github.com/rabbitmq/erlang-rpm.git #make cd erlang-rpm make #須要等待較長時間 cd RPMS/x86_64 #其下有兩個rpm包 erlang-19.3.6-1.alios6.x86_64.rpm erlang-debuginfo-19.3.6-1.alios6.x86_64.rpm, 選擇前者安裝 #安裝 sudo rpm -ivh erlang-19.3.6-1.alios6.x86_64.rpm
在官網下載頁面找到和系統版本對應的rabbitmq版本:git
#安裝rabbitmq-server sudo yum install rabbitmq-server-3.6.10-1.el6.noarch.rpm #此時可能報:Requires: socat, 如下是解決方法, 參考:http://www.cnblogs.com/ray30th/p/6651800.html sudo wget --no-cache http://www.convirture.com/repos/definitions/rhel/6.x/convirt.repo -O /etc/yum.repos.d/convirt.repo sudo yum makecache sudo yum install socat #從新安裝rabbitmq-server sudo yum install rabbitmq-server-3.6.10-1.el6.noarch.rpm
#啓動/中止 start/stop $sudo /sbin/service rabbitmq-server start Starting rabbitmq-server: SUCCESS rabbitmq-server. $sudo /sbin/service rabbitmq-server stop Stopping rabbitmq-server: rabbitmq-server. #狀態查看 sudo rabbitmqctl status
其中狀態查看會返回詳細的狀態信息:github
[{pid,2022}, {running_applications, [{rabbit,"RabbitMQ","3.6.10"}, {os_mon,"CPO CXC 138 46","2.4.2"}, {rabbit_common, "Modules shared by rabbitmq-server and rabbitmq-erlang-client", "3.6.10"}, {ranch,"Socket acceptor pool for TCP protocols.","1.3.0"}, {ssl,"Erlang/OTP SSL application","8.1.3"}, {public_key,"Public key infrastructure","1.4"}, {crypto,"CRYPTO","3.7.4"}, {compiler,"ERTS CXC 138 10","7.0.4"}, {asn1,"The Erlang ASN1 compiler version 4.0.4","4.0.4"}, {xmerl,"XML parser","1.3.14"}, {syntax_tools,"Syntax tools","2.1.1"}, {mnesia,"MNESIA CXC 138 12","4.14.3"}, {sasl,"SASL CXC 138 11","3.0.3"}, {stdlib,"ERTS CXC 138 10","3.3"}, {kernel,"ERTS CXC 138 10","5.2"}]}, {os,{unix,linux}}, {erlang_version, "Erlang/OTP 19 [erts-8.3.5] [source] [64-bit] [smp:2:2] [async-threads:64] [hipe] [kernel-poll:true]\n"}, {memory, [{total,53336792}, {connection_readers,0}, {connection_writers,0}, {connection_channels,0}, {connection_other,0}, {queue_procs,2832}, {queue_slave_procs,0}, {plugins,0}, {other_proc,20729016}, {mnesia,60688}, {metrics,184080}, {mgmt_db,0}, {msg_index,42608}, {other_ets,2138344}, {binary,116568}, {code,21389077}, {atom,891849}, {other_system,7962978}]}, {alarms,[]}, {listeners,[{clustering,25672,"::"},{amqp,5672,"0.0.0.0"}]}, {vm_memory_high_watermark,0.4}, {vm_memory_limit,1660447948}, {disk_free_limit,50000000}, {disk_free,94489919488}, {file_descriptors, [{total_limit,65435}, {total_used,2}, {sockets_limit,58889}, {sockets_used,0}]}, {processes,[{limit,1048576},{used,152}]}, {run_queue,0}, {uptime,15}, {kernel,{net_ticktime,60}}]
SELinux和與其機制相似的系統可能會阻止RabbtMQ綁定相應端口,因此安裝完以後須要確保一下端口能夠打開:shell
rabbitmq-plugins enable rabbitmq_management
,訪問http://server-name:15672/
Installing on RPM-based Linux(Port Access)
RabbitMQ~開篇與環境部署json
RabbitMQ有一個默認的用戶"guest",密碼也是"guest",這個用戶默認只能經過本機訪問,eg:http://localhost:15672/
,在經過http訪問以前記得啓用management插件:網絡
$rabbitmq-plugins enable rabbitmq_management
要讓其餘機器能夠訪問,須要建立一個新用戶,爲其分配權限。用戶權限能夠經過rabbitmqctl
執行相關命令來維護,rabbitmqctl是管理rabbitmq的命令行管理工具,下面介紹相關的命令:app
rabbitmqctl set_user_tags chris administrator
,設置爲管理員;rabbitmqctl set_user_tags chris
,清除chris與角色的關聯。#用戶列表查看 $sudo rabbitmqctl list_users Listing users guest [administrator] #添加用戶 $sudo rabbitmqctl add_user chris 123 Creating user "chris" #爲用戶分配權限 $sudo rabbitmqctl set_user_tags chris administrator Setting tags for user "chris" to [administrator] #而後就能夠經過http://host:15672 登陸management界面管理rabbitmq了,但此時用戶chris尚未訪問隊列資源的權限
RabbitMQ客戶端鏈接到一個服務端的時候,在它的操做指令中指定了一個虛擬主機。服務端首先檢查是否有訪問該虛擬主機的權限,沒有權限的會拒絕鏈接。socket
對於exchanges和queues等資源,位於某個虛擬主機內;不一樣虛擬主機內即使名稱相同也表明不一樣的資源。當特定操做在資源上執行時第二級訪問控制開始生效。
RabbitMQ在某個資源上區分了配置、寫和讀操做。配置操做建立或者銷燬資源,或者更改資源的行爲。寫操做將消息注入進資源之中。讀操做從資源中獲取消息。
要執行特定操做用戶必須授予合適的權限。
下面介紹相關命令:
rabbitmqctl add_vhost test
rabbitmqctl set_permissions -p /myvhost chris "^chris-.*" ".*" ".*"
,這條指令,給用戶chris在myvhost分配了權限,權限包括:以"chris-"開頭的所有資源的配置權限,和全部資源的讀寫權限$sudo rabbitmqctl set_permissions -p / chris ".*" ".*" ".*" Setting permissions for user "chris" in vhost "/" #此時用戶chris纔有訪問隊列資源的權限
rabbitmqctl(1) manual page(User management, Access control)
rabbitmq會維持大量的網絡鏈接,因此係統容許同時打開的最大文件數須要調整。推薦的容許同時打開的最大文件數爲65535。有兩個地方須要設置:
ulimit -n size
設置系統級限制查看與設置:
#查看 $ cat /proc/sys/fs/file-max 184289 $ cat /proc/sys/fs/file-nr 1024 0 184289 #已分配文件句柄的數目 分配了但沒有使用的句柄數 文件句柄最大數目 #設置 $echo 284289 > /proc/sys/fs/file-max
ulimit 命令詳解
ulimit用於shell啓動進程所佔用的資源,是shell內建命令。
參數介紹:
-H 設置硬件資源限制.
-S 設置軟件資源限制.
-a 顯示當前全部的資源限制.
-c size:設置core文件的最大值.單位:blocks
-d size:設置數據段的最大值.單位:kbytes
-f size:設置建立文件的最大值.單位:blocks
-l size:設置在內存中鎖定進程的最大值.單位:kbytes
-m size:設置可使用的常駐內存的最大值.單位:kbytes
-n size:設置內核能夠同時打開的文件描述符的最大值.單位:n
-p size:設置管道緩衝區的最大值.單位:kbytes
-s size:設置堆棧的最大值.單位:kbytes
-t size:設置CPU使用時間的最大上限.單位:seconds
-v size:設置虛擬內存的最大值.單位:kbytesLinux
能夠經過rabbitmqctl status
查看當前的限制狀態,status中的file_descriptors
描述了當前的限制:
{file_descriptors, [{total_limit,65435}, {total_used,2}, {sockets_limit,58889}, {sockets_used,0}]}, {processes,[{limit,1048576},{used,330}]}
rabbitmqctl(1) manual page (Controlling System Limits on Linux)
linux限制打開文件數量
Rabbitmq默認日誌路徑:/var/log/rabbitmq/
,路徑之下有兩類日誌文件: