RabbitMQ集群
环境:
CentOS7
erlang-18.3
rabbitmq-3.6.5
erlang-18.3
rabbitmq-3.6.5
3节点集群,添加hosts
192.168.130.45 192-168-130-45
192.168.130.46 192-168-130-46
192.168.130.47 192-168-130-47
本实验采用yum安装
一.Erlang
yum安装erlang-18.3,略
或
源码安装
http://www.erlang.org
https://github.com/erlang/otp/blob/maint/HOWTO/INSTALL.md
yum -y install fop
curl -SLhttp://erlang.org/download/otp_src_19.3.tar.gz|tar
-xvf - -C /usr/local/src
cd /usr/local/src/otp_src_19
./configure --prefix=/opt/erlang && make -j4 && make install
提示:默认没有wxWidgets,有需要的同学可以参看https://www.wxwidgets.org
rpm包见https://www.erlang-solutions.com/resources/download.html
二.RabbiMQ
yum安装rabbitmq-3.6.5,安装略
http://www.erlang.org
https://github.com/erlang/otp/blob/maint/HOWTO/INSTALL.md
yum -y install fop
curl -SL
cd /usr/local/src/otp_src_19
./configure --prefix=/opt/erlang && make -j4 && make install
提示:默认没有wxWidgets,有需要的同学可以参看https://www.wxwidgets.org
rpm包见https://www.erlang-solutions.com/resources/download.html
二.RabbiMQ
yum安装rabbitmq-3.6.5,安装略
或
二进制包
http://www.rabbitmq.com/install-generic-unix.html
curl -SLhttp://www.rabbitmq.com/releases/rabbitmq-server/v3.6.9/rabbitmq-server-generic-unix-3.6.9.tar.xz|tar
-xvf - -C /opt/
mv /opt/rabbitmq_server-3.6.9/ /opt/rabbitmq
cp -a /opt/rabbitmq/share/man/* /usr/share/man/
echo 'RABBITMQ_HOME=/opt/rabbitmq' >/etc/profile.d/rabbitmq.env
source /etc/profile.d/rabbitmq.env
提示:必要时还可增加自定义配置文件
echo > /opt/rabbitmq/etc/rabbitmq/rabbitmq-env.conf <<'EOF'
NODENAME=node1@rabbit
CONFIG_FILE=$RABBITMQ_HOME/etc/rabbitmq/rabbitmq.config
EOF
三.配置RabbiMQ集群
http://www.rabbitmq.com/configure.html
curl -SL
mv /opt/rabbitmq_server-3.6.9/ /opt/rabbitmq
cp -a /opt/rabbitmq/share/man/* /usr/share/man/
echo 'RABBITMQ_HOME=/opt/rabbitmq' >/etc/profile.d/rabbitmq.env
source /etc/profile.d/rabbitmq.env
提示:必要时还可增加自定义配置文件
echo > /opt/rabbitmq/etc/rabbitmq/rabbitmq-env.conf <<'EOF'
NODENAME=node1@rabbit
CONFIG_FILE=$RABBITMQ_HOME/etc/rabbitmq/rabbitmq.config
EOF
三.配置RabbiMQ集群
http://www.rabbitmq.com/configure.html
http://www.rabbitmq.com/clustering.html
{ram,['rabbit@192-168-130-47','rabbit@192-168-130-46']}]},
{running_nodes,['rabbit@192-168-130-47','rabbit@192-168-130-46',
'rabbit@192-168-130-45']},
{cluster_name,<<"rabbit@192-168-130-45">>},
{partitions,[]},
{alarms,[{'rabbit@192-168-130-47',[]},
{'rabbit@192-168-130-46',[]},
{'rabbit@192-168-130-45',[]}]}]
四.测试
http://www.rabbitmq.com/tutorials/tutorial-one-python.html
http://github.com/rabbitmq/rabbitmq-tutorials/blob/master/python/send.py
http://github.com/rabbitmq/rabbitmq-tutorials/blob/master/python/receive.py
https://github.com/rabbitmq/rabbitmq-server/blob/stable/docs/rabbitmq.config.example
1.停止rabbitmq(所有节点)
1.停止rabbitmq(所有节点)
systemctl stop rabbitmq-server
2.同步.erlang.cookie到其它集群节点
scp /var/lib/rabbitmq/.erlang.cookie root@192.168.130.46:/var/lib/rabbitmq/.erlang.cookie
scp /var/lib/rabbitmq/.erlang.cookie root@192.168.130.47:/var/lib/rabbitmq/.erlang.cookie
3.修改.erlang.cookie的权限(46,47上操作)
chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie
chmod 400 /var/lib/rabbitmq/.erlang.cookie
4.启动rabbitmq(所有节点)
systemctl start rabbitmq-server
systemctl enable rabbitmq-server
5.加入集群(46,47上操作)
rabbitmqctl stop_app
rabbitmqctl join_cluster
--ram rabbit@192-168-130-45
rabbitmqctl start_app
注意:rabbit@192-168-130-45是主机名
6.查看集群状态(任意节点)
[root@192-168-130-45 ~]#
rabbitmqctl cluster_status
Cluster status of node
'rabbit@192-168-130-45' ...
[{nodes,[{disc,['rabbit@192-168-130-45']},
7.配置所有节点镜像queue(任意节点上操作一次即可)
rabbitmqctl set_policy ha-all '^(?!amq.).*' '{"ha-mode":
"all"}'
8.启用web插件
rabbitmq-plugins enable rabbitmq_management
rabbitmqctl add_user admin admin
rabbitmqctl set_user_tags admin administrator
9.修改节点持久化为ram
rabbitmqctl stop_app
rabbitmqctl change_cluster_node_type ram
rabbitmqctl start_app
提示:集群中至少有一个为本地磁盘持久化
提示: 可以重置rabbit,例如
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
rabbitmqctl
add_user openstack RABBIT_PASS
rabbitmqctl
set_permissions openstack ".*" ".*" ".*"
http://www.rabbitmq.com/tutorials/tutorial-one-python.html
http://github.com/rabbitmq/rabbitmq-tutorials/blob/master/python/send.py
http://github.com/rabbitmq/rabbitmq-tutorials/blob/master/python/receive.py