RabbitMQ是一個開源的AMQP實現,服務器端用Erlang語言編寫,支持多種客戶端,如:Python、Ruby、.NET、Java、JMS、C、PHP、ActionScript、XMPP、STOMP等,支持AJAX。用於在分佈式系統中存儲轉發消息,在易用性、擴展性、高可用性等方面表現不俗。html
AMQP,即Advanced message Queuing Protocol,高級消息隊列協議,是應用層協議的一個開放標準,爲面向消息的中間件設計。消息中間件主要用於組件之間的解耦,消息的發送者無需知道消息使用者的存在,反之亦然。node
AMQP的主要特徵是面向消息、隊列、路由(包括點對點和發佈/訂閱)、可靠性、安全。segmentfault
關閉防火牆centos
centos 6.x 關閉 iptables安全
$ service iptables stop # 關閉命令:
centos 7.x 關閉firewall服務器
$ systemctl stop firewalld.service # 中止firewall
不想關閉防火牆,就開放15672端口,設置以後能夠經過網頁方式管理MQcookie
安裝安裝iptables防火牆網絡
yum install iptables-services
編輯配置app
$ vi /etc/sysconfig/iptables-config
添加配置less
iptables -I INPUT -p tcp --dport 5672 -j ACCEPT iptables -I INPUT -p tcp --dport 15672 -j ACCEPT
保存配置
$ service iptables save
重啓
systemctl restart iptables.service
設置開機自啓動
systemctl enable iptables.service
RabbitMQ 安裝須要依賴 Erlang 環境
$ cd /opt $ wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.centos.x86_64.rpm $ yum install erlang-19.0.4-1.el7.centos.x86_64.rpm
$ cd /opt $ wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server-3.6.10-1.el7.noarch.rpm $ yum install rabbitmq-server-3.6.10-1.el7.noarch.rpm
$ service rabbitmq-server start
$ service rabbitmq-server status
# service rabbitmq-server status Redirecting to /bin/systemctl status rabbitmq-server.service ● rabbitmq-server.service - RabbitMQ broker Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2017-08-16 11:43:33 CST; 8s ago Main PID: 17919 (beam) Status: "Initialized" CGroup: /system.slice/rabbitmq-server.service ├─17919 /usr/lib64/erlang/erts-8.0.3/bin/beam -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 32000 -K true -- -root /usr/lib64/erlang -progname erl -- -home /var/lib/rabbitmq -- -pa /us... ├─18062 /usr/lib64/erlang/erts-8.0.3/bin/epmd -daemon ├─18160 erl_child_setup 1024 ├─18165 inet_gethost 4 └─18166 inet_gethost 4 Aug 16 11:43:32 localhost.localdomain rabbitmq-server[17919]: RabbitMQ 3.6.10. Copyright (C) 2007-2017 Pivotal Software, Inc. Aug 16 11:43:32 localhost.localdomain rabbitmq-server[17919]: ## ## Licensed under the MPL. See http://www.rabbitmq.com/ Aug 16 11:43:32 localhost.localdomain rabbitmq-server[17919]: ## ## Aug 16 11:43:32 localhost.localdomain rabbitmq-server[17919]: ########## Logs: /var/log/rabbitmq/rabbit@localhost.log Aug 16 11:43:32 localhost.localdomain rabbitmq-server[17919]: ###### ## /var/log/rabbitmq/rabbit@localhost-sasl.log Aug 16 11:43:32 localhost.localdomain rabbitmq-server[17919]: ########## Aug 16 11:43:32 localhost.localdomain rabbitmq-server[17919]: Starting broker... Aug 16 11:43:33 localhost.localdomain rabbitmq-server[17919]: systemd unit for activation check: "rabbitmq-server.service" Aug 16 11:43:33 localhost.localdomain systemd[1]: Started RabbitMQ broker. Aug 16 11:43:33 localhost.localdomain rabbitmq-server[17919]: completed with 0 plugins.
$ less /var/log/rabbitmq/rabbit@localhost.log
=INFO REPORT==== 16-Aug-2017::11:43:32 === Starting RabbitMQ 3.6.10 on Erlang 19.0.4 Copyright (C) 2007-2017 Pivotal Software, Inc. Licensed under the MPL. See http://www.rabbitmq.com/ =INFO REPORT==== 16-Aug-2017::11:43:32 === node : rabbit@localhost home dir : /var/lib/rabbitmq config file(s) : /etc/rabbitmq/rabbitmq.config (not found) cookie hash : kuUba2xGLitNNO48qE0Hrg== log : /var/log/rabbitmq/rabbit@localhost.log sasl log : /var/log/rabbitmq/rabbit@localhost-sasl.log database dir : /var/lib/rabbitmq/mnesia/rabbit@localhost =INFO REPORT==== 16-Aug-2017::11:43:33 === Memory limit set to 390MB of 976MB total. =INFO REPORT==== 16-Aug-2017::11:43:33 === Enabling free disk space monitoring =INFO REPORT==== 16-Aug-2017::11:43:33 === Disk free limit set to 50MB =INFO REPORT==== 16-Aug-2017::11:43:33 === Limiting to approx 924 file handles (829 sockets) =INFO REPORT==== 16-Aug-2017::11:43:33 === FHC read buffering: OFF FHC write buffering: ON =INFO REPORT==== 16-Aug-2017::11:43:33 === Database directory at /var/lib/rabbitmq/mnesia/rabbit@localhost is empty. Initialising from scratch... =INFO REPORT==== 16-Aug-2017::11:43:33 === Waiting for Mnesia tables for 30000 ms, 9 retries left =INFO REPORT==== 16-Aug-2017::11:43:33 === Waiting for Mnesia tables for 30000 ms, 9 retries left
這裏顯示的是沒有找到配置文件,咱們能夠本身建立這個文件
config file(s) : /etc/rabbitmq/rabbitmq.config (not found)
建立rabbitmq.config
$ cd /etc/rabbitmq/ $ vi rabbitmq.config
編輯內容以下:
[{rabbit, [{loopback_users, []}]}].
保存配置後重啓服務
$ service rabbitmq-server restart
$ /sbin/rabbitmq-plugins enable rabbitmq_management
重啓服務
$ service rabbitmq-server restart
經過 http://ip:15672 使用guest,guest 進行登錄了
若是不能訪問,請檢查防火牆
處於安全的考慮,guest這個默認的用戶只能經過http://localhost:15672
來登陸,其餘的IP沒法直接使用這個帳號。 這對於服務器上沒有安裝桌面的狀況是沒法管理維護的,除非經過在前面添加一層代理向外提供服務,這個又有些麻煩了,這裏經過配置文件來實現這個功能
命令格式
rabbitmqctl add_user <username> <newpassword>
$ rabbitmqctl add_user ymq 123456 Creating user "ymq"
命令格式
rabbitmqctl delete_user <username>
$ rabbitmqctl delete_user penglei Deleting user "penglei"
命令格式
rabbitmqctl change_password <username> <newpassword>
$ rabbitmqctl change_password ymq 123456 Changing password for user "ymq"
命令格式
rabbitmqctl set_permissions [-pvhostpath] {user} {conf} {write} {read}
該命令使用戶ymq /(能夠訪問虛擬主機) 中全部資源的配置、寫、讀權限以便管理其中的資源
$ rabbitmqctl set_permissions -p "/" ymq ".*" ".*" ".*" Setting permissions for user "ymq" in vhost "/"
命令格式
rabbitmqctl list_permissions [-p VHostPath]
$ rabbitmqctl list_permissions -p / Listing permissions in vhost "/" guest .* .* .* ymq .* .* .*
能夠看到添加用戶成功了,但不是administrator
角色
$ rabbitmqctl list_users Listing users guest [administrator] ymq []
這裏咱們也將ymq用戶設置爲administrator
角色
命令格式
rabbitmqctl set_user_tags <username> <tag>
$ rabbitmqctl set_user_tags ymq administrator Setting tags for user "ymq" to [administrator]
再次查看權限
$ rabbitmqctl list_users Listing users guest [administrator] ymq [administrator]
清除權限信息
命令格式
rabbitmqctl clear_permissions [-p VHostPath] ymq
rabbitmqctl clear_permissions -p / ymq Clearing permissions for user "ymq" in vhost "/"
能夠看到 ymq 和 guest 的權限 同樣
鼠標點擊,劃紅線的角色,選擇一種
該用戶無權訪問任何虛擬主機
點擊 Set permission
CentOs7.3 搭建 RabbitMQ 3.6 Cluster 集羣服務