esl-erlang安装方法

  • sudo yum install epel-release
  • sudo yum install wget
  • wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
  • sudo rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
  • sudo yum install esl-erlang

RabbitMQ安装

  • sudo rpm -ivh –nodeps –force rabbitmq-server-3.6.1-1.noarch.rpm

RabbitMQ启用management plugin

  • sbin/rabbitmq-plugins enable rabbitmq_management

RabbitMQ允许使用guest远程登录

  1. add rabbitmq.config to /etc/rabbitmq
  2. add [{rabbit, [{loopback_users, []}]}]. to rabbitmq.config

RabbitMQ后台运行

sudo ./rabbitmq-server -detached

RabbitMQ集群配置

  • 将组成集群的机器添加到/etc/hosts
192.168.1.2 rabbit1
192.168.1.3 rabbit2
192.168.1.4 rabbit3
  • 配置.erlang.cookie

How Nodes (and CLI tools) Authenticate to Each Other: the Erlang Cookie

RabbitMQ nodes and CLI tools (e.g. rabbitmqctl) use a cookie to determine whether they are allowed to communicate with each other. For two nodes to be able to communicate they must have the same shared secret called the Erlang cookie. The cookie is just a string of alphanumeric characters. It can be as long or short as you like. Every cluster node must have the same cookie.

Erlang VM will automatically create a random cookie file when the RabbitMQ server starts up. The easiest way to proceed is to allow one node to create the file, and then copy it to all the other nodes in the cluster.

On Unix systems, the cookie will be typically located in /var/lib/rabbitmq/.erlang.cookie or $HOME/.erlang.cookie.

Tips

坑:请注意/root/.erlang.cookie,使用sudo命令启动rabbitmq时会用/root/.erlang.cookie,其他位置的.erlang.cookie修改无效,被它坑坏了。

  • 各个服务器独立启动RabbitMQ
rabbit1$ rabbitmq-server -detached
rabbit2$ rabbitmq-server -detached
rabbit3$ rabbitmq-server -detached
  • 查看集群信息 rabbitmqctl cluster_status

  • 创建集群 rabbit1作为集群中心,rabbit2和rabbit3 join到rabbit1

rabbit2$ rabbitmqctl stop_app
rabbit2$ rabbitmqctl join_cluster rabbit@rabbit1

rabbit3$ rabbitmqctl stop_app
rabbit3$ rabbitmqctl join_cluster rabbit@rabbit2

Reference

Install Erlang on CentOS 7
RabbitMQ Tutorial
RabbitMQ Clustering
RabbitMQ docs