rabbitmq集羣搭建

mq集羣:node

192.168.6.61    rabbitmq-server1    master
192.168.6.62    rabbitmq-server2    slave
192.168.6.71    rabbitmq-server3    slave

 

1.配置yum源(全部節點執行)linux

yum -y install vim bash-completion rabbitmq-server

 

2.設置selinux和防火牆(全部節點執行)vim

# 重啓生效
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 臨時生效
setenforce 0
systemctl stop firewalld systemctl disable firewalld systemctl mask firewalld

 

3.設置主機名
192.168.6.61:bash

echo rabbitmq-server1 > /etc/hostname
hostnamectl set-hostname rabbitmq-server1
echo 192.168.6.61 rabbitmq-server1 >> /etc/hosts
echo 192.168.6.62 rabbitmq-server2 >> /etc/hosts
echo 192.168.6.71 rabbitmq-server3 >> /etc/hosts

 

192.168.6.62:cookie

echo rabbitmq-server2 > /etc/hostname
hostnamectl set-hostname rabbitmq-server2
echo 192.168.6.61 rabbitmq-server1 >> /etc/hosts
echo 192.168.6.62 rabbitmq-server2 >> /etc/hosts
echo 192.168.6.71 rabbitmq-server3 >> /etc/hosts


192.168.6.71:app

echo rabbitmq-server3 > /etc/hostname
hostnamectl set-hostname rabbitmq-server3
echo 192.168.6.61 rabbitmq-server1 >> /etc/hosts
echo 192.168.6.62 rabbitmq-server2 >> /etc/hosts
echo 192.168.6.71 rabbitmq-server3 >> /etc/hosts


4.配置rabbitmq-server
各個節點:tcp

systemctl start rabbitmq-server
systemctl enable rabbitmq-server

 

192.168.6.61(以第1臺節點爲master節點):spa

scp /var/lib/rabbitmq/.erlang.cookie 192.168.6.62:/var/lib/rabbitmq/
scp /var/lib/rabbitmq/.erlang.cookie 192.168.6.71:/var/lib/rabbitmq/

 

192.168.6.62和192.168.6.71加入集羣:rest

chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie
chmod 400 /var/lib/rabbitmq/.erlang.cookie
systemctl restart rabbitmq-server
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@rabbitmq-server1
rabbitmqctl start_app

 

# 配置rabbitmq用戶和許可(192.168.6.61執行)code

rabbitmqctl add_user 用戶名 密碼
rabbitmqctl set_user_tags 用戶名 administrator
rabbitmqctl set_permissions -p / 用戶名 '.*' '.*' '.*'

 

# 配置鏡像隊列(messages自動同步)

rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all","ha-sync-mode":"automatic"}'

 

# 修改本節點爲ram模式

rabbitmqctl stop_app
rabbitmqctl change_cluster_node_type ram
rabbitmqctl start_app

 

# haproxy配置:

listen rabbitmq_5672
bind 0.0.0.0:5672
balance roundrobin
timeout connect 10s
timeout client 10s
timeout server 10s
mode tcp
option tcpka
option tcplog
server rabbitmq-server1 192.168.6.61:5672 check inter 2000 rise 2 fall 5
server rabbitmq-server2 192.168.6.62:5672 check inter 2000 rise 2 fall 5
server rabbitmq-server3 192.168.6.71:5672 check inter 2000 rise 2 fall 5

listen rabbitmq_15672
bind 0.0.0.0:15672
balance source
option tcpka
option tcplog
server rabbitmq-server1 192.168.6.61:15672 check inter 2000 rise 2 fall 5
server rabbitmq-server2 192.168.6.62:15672 check inter 2000 rise 2 fall 5
server rabbitmq-server3 192.168.6.71:15672 check inter 2000 rise 2 fall 5
相關文章
相關標籤/搜索