180 lines
4.3 KiB
Markdown
180 lines
4.3 KiB
Markdown
|
# Howto RabbitMQ
|
||
|
|
||
|
<https://www.rabbitmq.com/>
|
||
|
|
||
|
## Installation
|
||
|
|
||
|
~~~
|
||
|
# apt install rabbitmq-server
|
||
|
~~~
|
||
|
|
||
|
~~~
|
||
|
# rabbitmqctl status
|
||
|
|
||
|
{running_applications,[{rabbit,"RabbitMQ","3.3.5"},
|
||
|
{mnesia,"MNESIA CXC 138 12","4.12.3"},
|
||
|
{os_mon,"CPO CXC 138 46","2.3"},
|
||
|
{xmerl,"XML parser","1.3.7"},
|
||
|
{sasl,"SASL CXC 138 11","2.4.1"},
|
||
|
{stdlib,"ERTS CXC 138 10","2.2"},
|
||
|
{kernel,"ERTS CXC 138 10","3.0.3"}]},
|
||
|
{os,{unix,linux}},
|
||
|
{erlang_version,"Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:4:4] [async-threads:30] [kernel-poll:true]\n"},
|
||
|
~~~
|
||
|
|
||
|
## Configuration
|
||
|
|
||
|
La configuration par défaut de RabbitMQ est souvent utilisable en l'état, sans besoin de modification.
|
||
|
|
||
|
Si l'on doit modifier la configuration, voici les fichiers :
|
||
|
|
||
|
* `/etc/rabbitmq/rabbitmq-env.conf` : variables d'environnement pour RabbitMQ
|
||
|
* `/etc/rabbitmq/rabbitmq.config` : options pour RabbitMQ
|
||
|
* `/etc/default/rabbitmq-server` : configuration système (ulimit)
|
||
|
|
||
|
### Variables d'environnement pour RabbitMQ
|
||
|
|
||
|
Il faut donc créer le fichier :
|
||
|
|
||
|
~~~
|
||
|
# touch /etc/rabbitmq/rabbitmq-env.conf
|
||
|
# chmod 600 /etc/rabbitmq/rabbitmq-env.conf
|
||
|
# chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq-env.conf
|
||
|
~~~
|
||
|
|
||
|
Différentes variables *RABBITMQ_\** sont utilisables :
|
||
|
|
||
|
~~~
|
||
|
RABBITMQ_NODE_PORT=672
|
||
|
RABBITMQ_SERVER_ERL_ARGS="+K true +A30 +P 1048576 -kernel inet_default_connect_options [{nodelay,true}]"
|
||
|
~~~
|
||
|
|
||
|
### Options pour rabbitmq.config
|
||
|
|
||
|
Il faut donc créer le fichier :
|
||
|
|
||
|
~~~
|
||
|
# touch /etc/rabbitmq/rabbitmq.config
|
||
|
# chmod 600 /etc/rabbitmq/rabbitmq.config
|
||
|
# chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config
|
||
|
~~~
|
||
|
|
||
|
Différentes options sont utilisables (voir `/usr/share/doc/rabbitmq-server/rabbitmq.config.example.gz` pour un exemple).
|
||
|
|
||
|
Si l'on veut que RabbitMQ n'écoute que sur l'interface *localhost* :
|
||
|
|
||
|
~~~
|
||
|
[
|
||
|
{rabbit, [
|
||
|
{tcp_listeners, [{"127.0.0.1", 5672},
|
||
|
{"::1", 5672}]}
|
||
|
]}
|
||
|
].
|
||
|
~~~
|
||
|
|
||
|
### Configuration système
|
||
|
|
||
|
`/etc/default/rabbitmq-server` :
|
||
|
|
||
|
~~~
|
||
|
ulimit -n 2048
|
||
|
~~~
|
||
|
|
||
|
## Management RabbitMQ
|
||
|
|
||
|
### rabbitmqctl
|
||
|
|
||
|
~~~
|
||
|
# rabbitmqctl status
|
||
|
# rabbitmqctl list_connections
|
||
|
# rabbitmqctl list_queues
|
||
|
~~~
|
||
|
|
||
|
### Activation de l'interface web de management
|
||
|
|
||
|
Pour activer l'interface web de management :
|
||
|
|
||
|
~~~
|
||
|
# rabbitmq-plugins enable rabbitmq_management
|
||
|
# chown rabbitmq:rabbitmq /etc/rabbitmq/enabled_plugins
|
||
|
# systemctl restart rabbitmq-server
|
||
|
# rabbitmqctl add_user admin PASSWORD
|
||
|
# rabbitmqctl set_user_tags admin administrator
|
||
|
~~~
|
||
|
|
||
|
On a ainsi accès à l'interface web via <http://127.0.0.1:15672/>
|
||
|
|
||
|
On peut aussi mettre en place un proxy via Nginx :
|
||
|
|
||
|
~~~
|
||
|
location /rabbitmq/ {
|
||
|
proxy_pass http://127.0.0.1:15672/;
|
||
|
include proxy_params;
|
||
|
}
|
||
|
~~~
|
||
|
|
||
|
### Activation CLI (TODO: à vérifier)
|
||
|
|
||
|
<https://www.rabbitmq.com/management-cli.html>
|
||
|
|
||
|
On peut installer un binaire permettant d'avoir un mode CLI pour RabbitMQ :
|
||
|
|
||
|
{{{
|
||
|
$ curl localhost:15672/cli/rabbitmqadmin > /usr/local/bin/rabbitmqadmin
|
||
|
$ chmod 755 /usr/local/bin/rabbitmqadmin
|
||
|
$ rabbitmqadmin --bash-completion > /etc/bash_completion.d/rabbitmqadmin
|
||
|
}}}
|
||
|
|
||
|
/root/.rabbitmqadmin.conf
|
||
|
{{{
|
||
|
[default]
|
||
|
username = admin
|
||
|
password = PASSWORD
|
||
|
}}}
|
||
|
|
||
|
## Sauvegarde
|
||
|
|
||
|
À l'aide du CLI :
|
||
|
|
||
|
~~~
|
||
|
# rabbitmqadmin export rabbitmq.config
|
||
|
~~~
|
||
|
|
||
|
## Munin
|
||
|
|
||
|
On utilise *rabbitmq_connections* :
|
||
|
|
||
|
~~~
|
||
|
$ wget https://raw.githubusercontent.com/ask/rabbitmq-munin/master/rabbitmq_connections
|
||
|
$ chmod +x rabbitmq_connections
|
||
|
$ ./rabbitmq_connections
|
||
|
~~~
|
||
|
|
||
|
Attention, *rabbitmq_connections* utilise la commande `rabbitmqctl` vous devez donc adapter le script ou configurer `/etc/munin/plugin-conf.d/munin-node` ainsi :
|
||
|
|
||
|
~~~
|
||
|
[rabbitmq_connections]
|
||
|
user rabbitmq
|
||
|
EOT
|
||
|
~~~
|
||
|
|
||
|
|
||
|
## Nagios
|
||
|
|
||
|
On utilise *check_rabbitmq* (merci à <https://github.com/CaptPhunkosis>) :
|
||
|
|
||
|
~~~
|
||
|
# apt install python-requests
|
||
|
$ wget https://raw.githubusercontent.com/CaptPhunkosis/check_rabbitmq/master/check_rabbitmq
|
||
|
$ chmod +x check_rabbitmq
|
||
|
$ ./check_rabbitmq -a connection_count -C 100 -W 80
|
||
|
~~~
|
||
|
|
||
|
Attention, *check_rabbitmq* utilise la commande `sudo rabbitmqctl` vous devez donc adapter le script ou configurer *sudo*.
|
||
|
|
||
|
~~~
|
||
|
nagios ALL = (rabbitmq) NOPASSWD: /usr/sbin/rabbitmqctl list_connections
|
||
|
nagios ALL = (rabbitmq) NOPASSWD: /usr/sbin/rabbitmqctl list_queues
|
||
|
nagios ALL = (rabbitmq) NOPASSWD: /usr/sbin/rabbitmqctl list_status
|
||
|
~~~
|