1. 程式人生 > >RabbitMQ概念及環境搭建(一)單節點安裝與配置

RabbitMQ概念及環境搭建(一)單節點安裝與配置

###############################################
#非同步、分散式訊息處理模型
###############################################

                                                    binding  +----------+    +----------------+
                                                 /------------+ queue +---+ consumer +
+---------------+   +----------------+   |            +-----------+   +----------------+
+ publisher +---+ exchange +---|
+---------------+   +----------------+   \           +-----------+   +----------------+
                                                      -----------+ queue +---+ consumer +
                                                   binding  +-----------+   +----------------+

################################################
RabbitMQ Server安裝
################################################
1.安裝Erlang
sudo yum install erlang

2.安裝RabbitMQ Server
需要先匯入key
sudo rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
可先將內容儲存至文字檔案,如,rabbitmq-signing-key-public.asc.txt
sudo rpm --import rabbitmq-signing-key-public.asc.txt 

3.安裝rabbitmq-server-3.4.1-1.noarch.rpm
sudo yum install rabbitmq-server-3.4.1-1.noarch.rpm

4.啟動RabbitMQ Server
註冊為系統服務
sudo chkconfig rabbitmq-server on
啟動RabbitMQ Server
sudo /etc/init.d/rabbitmq-server stop/start/etc
sudo service rabbitmq-server stop/start/etc

5.若啟動失敗檢測埠是否被佔用
4369 (epmd), 25672 (Erlang distribution)
5672, 5671 (AMQP 0-9-1 without and with TLS)
15672 (if management plugin is enabled)
61613, 61614 (if STOMP is enabled)
1883, 8883 (if MQTT is enabled)

參考:
http://www.rabbitmq.com/install-rpm.html

##################################################
RabbitMQ Server 配置
##################################################
1.通過環境變數進行配置
可直接在Shell中進行配置
或在rabbitmq-env.conf中配置

2.通過配置檔案進行配置
sudo cp /usr/share/doc/rabbitmq-server-3.4.1/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config
sudo vim /etc/rabbitmq/rabbitmq.config

相關檔案位置 
對於RPM為/etc/rabbitmq/,如/etc/rabbitmq/rabbitmq.config、/etc/rabbitmq/rabbitmq-env.conf

3.執行時配置

參考:
http://www.rabbitmq.com/configure.html

#################################################
#RabbitMQ 日誌、使用者、client
#################################################
1.日誌
ls -l /var/log/rabbitmq

2.預設virtual host與預設user
virtual host: /
user:guest
passwd:guest
注:預設使用者只可在localhost上連至/且有全部許可權

3.RabbitMQ Client
python client
pika-0.9.14.tar.gz
tar -xzvf pika-0.9.14.tar.gz
cd pika-0.9.14
sudo python27 setup.py install

JS client
amqp.node