Difference between revisions of "AMQP server: RabbitMQ"
(Created page with " ----------------------------- Requirements ----------------------------- # PostgreSQL + Python sudo apt-get install postgresql python3 sudo apt-get install python3-amqplib ...") |
(→Firewall) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [[Category:Linux]] | ||
+ | [[Category:Development]] | ||
− | - | + | RabbitMQ is an excellent low-level messaging server. You can use it with different technologies. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | --- | + | |
− | + | =Requirements= | |
− | + | ||
+ | You need PostgreSQL + Python | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | apt-get install postgresql python3 | ||
+ | apt-get install python3-amqplib | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | |||
+ | =Installation= | ||
+ | |||
+ | |||
+ | ==Add repository== | ||
+ | |||
+ | You must add a new repository for RabbitMQ. | ||
+ | * Even though the name is "testing" it's actually the latest stable version | ||
+ | * They use "testing" as this is not in the "main" Ubuntu repo yet. | ||
+ | |||
[source: http://www.rabbitmq.com/install-debian.html] | [source: http://www.rabbitmq.com/install-debian.html] | ||
− | |||
− | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | vim /etc/apt/sources.list | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | Add the new repository | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
deb http://www.rabbitmq.com/debian/ testing main | deb http://www.rabbitmq.com/debian/ testing main | ||
+ | </syntaxhighlight> | ||
− | + | Add repo key | |
− | |||
− | + | <syntaxhighlight lang="bash"> | |
− | |||
wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc | wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc | ||
sudo apt-key add rabbitmq-signing-key-public.asc | sudo apt-key add rabbitmq-signing-key-public.asc | ||
+ | </syntaxhighlight> | ||
− | + | ||
+ | Update package list | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
sudo apt-get update | sudo apt-get update | ||
+ | </syntaxhighlight> | ||
+ | |||
− | + | ==Binary installation== | |
− | |||
− | |||
− | + | <syntaxhighlight lang="bash"> | |
− | + | apt-get install rabbitmq-server amqp-tools | |
+ | </syntaxhighlight> | ||
− | + | ||
− | Enable plugins | + | ==Enable plugins== |
− | + | ||
− | + | Enable RabbitMQ command line client | |
− | + | ||
− | + | <syntaxhighlight lang="bash"> | |
rabbitmq-plugins enable amqp_client | rabbitmq-plugins enable amqp_client | ||
− | + | </syntaxhighlight> | |
+ | |||
+ | |||
+ | Enable web console | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
rabbitmq-plugins enable rabbitmq_management | rabbitmq-plugins enable rabbitmq_management | ||
− | + | </syntaxhighlight> | |
+ | |||
+ | |||
+ | Restart server to take on your changes | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
service rabbitmq-server restart | service rabbitmq-server restart | ||
+ | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | + | Now you can access RabbitMQ using the default ports: | |
− | + | * Web console: TCP 15672, http://localhost:15672/ | |
− | + | * AMQP Messages: TCP 5672 | |
− | |||
− | |||
− | + | ||
+ | ==Create administration user== | ||
+ | |||
+ | Create new user, replace ''rtd'' by your username. | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | rabbitmqctl add_user rtd strong_password | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | Set user rights | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
rabbitmqctl set_user_tags rtd administrator | rabbitmqctl set_user_tags rtd administrator | ||
rabbitmqctl set_permissions -p / rtd ".*" ".*" ".*" | rabbitmqctl set_permissions -p / rtd ".*" ".*" ".*" | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | Remove default guest user | ||
− | + | <syntaxhighlight lang="bash"> | |
rabbitmqctl delete_user guest | rabbitmqctl delete_user guest | ||
+ | </syntaxhighlight> | ||
− | + | ||
+ | Restart service to take on your changes | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
service rabbitmq-server restart | service rabbitmq-server restart | ||
+ | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | + | ||
+ | =Advanced configuration= | ||
+ | |||
+ | ==Change port number== | ||
+ | |||
+ | source: https://www.rabbitmq.com/configure.html | ||
+ | |||
+ | |||
+ | If activeMq is install, stop it | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
service activemq stop | service activemq stop | ||
+ | </syntaxhighlight> | ||
+ | |||
− | |||
− | + | Create or update the configuration file: | |
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | vim /etc/rabbitmq/rabbitmq-env.conf | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | Add the following at the beginning of the file | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
NODE_PORT=5673 | NODE_PORT=5673 | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | Restart server | ||
− | + | <syntaxhighlight lang="bash"> | |
service rabbitmq-server restart | service rabbitmq-server restart | ||
− | + | </syntaxhighlight> | |
+ | |||
+ | |||
+ | ==Firewall== | ||
+ | |||
+ | You must let the '''OUTPUT unfiltered''' because RabbitMQ port is dynamic. | ||
+ | |||
+ | You have to open Input TCP 5672 (messages), TCP 15672 (web interface). | ||
− | + | <syntaxhighlight lang="bash"> | |
− | |||
− | |||
− | |||
vi /etc/init.d/firewall | vi /etc/init.d/firewall | ||
+ | </syntaxhighlight> | ||
− | + | ||
+ | Add this rules | ||
+ | <syntaxhighlight lang="bash"> | ||
#rabbitMq | #rabbitMq | ||
$IPT -A INPUT -p tcp --dport 15672 -j ACCEPT | $IPT -A INPUT -p tcp --dport 15672 -j ACCEPT | ||
− | $IPT -A INPUT -p tcp --dport | + | $IPT -A INPUT -p tcp --dport 5672 -j ACCEPT |
+ | </syntaxhighlight> | ||
+ | ==Update startup== | ||
− | + | The server should start at every reboot. The following hack is only required if your installation is old or buggy. | |
− | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | cd /etc/init.d/ | ||
+ | update-rc.d rabbitmq-server defaults | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | |||
+ | =Apache 2 proxy= | ||
+ | |||
+ | You can put RabbitMQ behind a proxy using the following configuration: | ||
+ | |||
+ | |||
+ | Edit your Apache2 configuration: | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | vim /etc/apache2/sites-enabled/mySuperSite.conf | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | Set the following settings: | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | # Enable proxy | ||
+ | ProxyVia On | ||
+ | ProxyPreserveHost On | ||
+ | ProxyRequests Off | ||
+ | ProxyErrorOverride Off | ||
+ | <Proxy *> | ||
+ | AddDefaultCharset off | ||
+ | Order deny,allow | ||
+ | Allow from all | ||
+ | Satisfy Any | ||
+ | </Proxy> | ||
+ | |||
+ | ## Proxy to RabbitMQ | ||
+ | <Location /rabbitmq/> | ||
+ | ProxyPass http://smartcard-mq:15672/ | ||
+ | ProxyPassReverse http://smartcard-mq:15672/ | ||
+ | Order deny,allow | ||
+ | Deny from all | ||
+ | Allow from 127.0.0.1 172.16.50.0/24 192.168.1.0/24 | ||
+ | </Location> | ||
+ | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | =References= | ||
− | + | * https://www.rabbitmq.com/management-cli.html | |
− | + | * https://www.rabbitmq.com/configure.html | |
− | https://www.rabbitmq.com/management-cli.html | + | * https://www.rabbitmq.com/tutorials/tutorial-two-python.html |
− | https://www.rabbitmq.com/configure.html | ||
− | https://www.rabbitmq.com/tutorials/tutorial-two-python.html |
Latest revision as of 10:00, 1 April 2015
RabbitMQ is an excellent low-level messaging server. You can use it with different technologies.
Contents
Requirements
You need PostgreSQL + Python
apt-get install postgresql python3
apt-get install python3-amqplib
Installation
Add repository
You must add a new repository for RabbitMQ.
- Even though the name is "testing" it's actually the latest stable version
- They use "testing" as this is not in the "main" Ubuntu repo yet.
[source: http://www.rabbitmq.com/install-debian.html]
vim /etc/apt/sources.list
Add the new repository
deb http://www.rabbitmq.com/debian/ testing main
Add repo key
wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
sudo apt-key add rabbitmq-signing-key-public.asc
Update package list
sudo apt-get update
Binary installation
apt-get install rabbitmq-server amqp-tools
Enable plugins
Enable RabbitMQ command line client
rabbitmq-plugins enable amqp_client
Enable web console
rabbitmq-plugins enable rabbitmq_management
Restart server to take on your changes
service rabbitmq-server restart
Now you can access RabbitMQ using the default ports:
- Web console: TCP 15672, http://localhost:15672/
- AMQP Messages: TCP 5672
Create administration user
Create new user, replace rtd by your username.
rabbitmqctl add_user rtd strong_password
Set user rights
rabbitmqctl set_user_tags rtd administrator
rabbitmqctl set_permissions -p / rtd ".*" ".*" ".*"
Remove default guest user
rabbitmqctl delete_user guest
Restart service to take on your changes
service rabbitmq-server restart
Advanced configuration
Change port number
source: https://www.rabbitmq.com/configure.html
If activeMq is install, stop it
service activemq stop
Create or update the configuration file:
vim /etc/rabbitmq/rabbitmq-env.conf
Add the following at the beginning of the file
NODE_PORT=5673
Restart server
service rabbitmq-server restart
Firewall
You must let the OUTPUT unfiltered because RabbitMQ port is dynamic.
You have to open Input TCP 5672 (messages), TCP 15672 (web interface).
vi /etc/init.d/firewall
Add this rules
#rabbitMq
$IPT -A INPUT -p tcp --dport 15672 -j ACCEPT
$IPT -A INPUT -p tcp --dport 5672 -j ACCEPT
Update startup
The server should start at every reboot. The following hack is only required if your installation is old or buggy.
cd /etc/init.d/
update-rc.d rabbitmq-server defaults
Apache 2 proxy
You can put RabbitMQ behind a proxy using the following configuration:
Edit your Apache2 configuration:
vim /etc/apache2/sites-enabled/mySuperSite.conf
Set the following settings:
# Enable proxy
ProxyVia On
ProxyPreserveHost On
ProxyRequests Off
ProxyErrorOverride Off
<Proxy *>
AddDefaultCharset off
Order deny,allow
Allow from all
Satisfy Any
</Proxy>
## Proxy to RabbitMQ
<Location /rabbitmq/>
ProxyPass http://smartcard-mq:15672/
ProxyPassReverse http://smartcard-mq:15672/
Order deny,allow
Deny from all
Allow from 127.0.0.1 172.16.50.0/24 192.168.1.0/24
</Location>