欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ipv6 环境下搭建rabbitmq集群

程序员文章站 2022-03-05 18:29:12
...

环境信息

节点 地址
node1 1111::1
node2 1111::2
node3 1111::3

rabbitmq-server-3.7.8-1.el7.src.rpm
erlang-21.1-2.el7.centos.src.rpm
centos7.5.1804

集群配置

  1. 配置/etc/hosts
1111::1    node1  
1111::2    node2  
1111::3    node3  
  1. 配置/etc/rabbitmq/rabbitmq-env.conf
[email protected]
SERVER_ADDITIONAL_ERL_ARGS="-proto_dist inet6_tcp"
CTL_ERL_ARGS="-proto_dist inet6_tcp"
  1. 创建集群
#!/usr/bin/env bash

this_node=1111::1
other_node2=1111::2
other_node3=1111::3

scp_node2=[1111::2]
scp_node3=[1111::3]

other_name1=$(hostname)
other_name2=$(ssh ${other_node2} hostname)
other_name3=$(ssh ${other_node3} hostname)

#sync cookie
echo ">>> sync cookie"
rm /root/.erlang.cookie  -f
cp /var/lib/rabbitmq/.erlang.cookie /root/.erlang.cookie
chown rabbitmq /root/.erlang.cookie 
chgrp rabbitmq /root/.erlang.cookie 

for i in 2 3
do
    node=other_node$i
    scp_node=scp_node$i
    ssh ${!node} rm /var/lib/rabbitmq/.erlang.cookie /root/.erlang.cookie  -f
    scp /var/lib/rabbitmq/.erlang.cookie ${!scp_node}:/var/lib/rabbitmq/.erlang.cookie
    scp /var/lib/rabbitmq/.erlang.cookie ${!scp_node}:/root/.erlang.cookie
    ssh ${!node} chown rabbitmq /root/.erlang.cookie  /var/lib/rabbitmq/.erlang.cookie
    ssh ${!node} chgrp rabbitmq /root/.erlang.cookie  /var/lib/rabbitmq/.erlang.cookie

done

#restart rabbit
echo ">>> restart rabbit"
echo "on ${this_node}"
systemctl restart rabbitmq-server
for i in 2 3
do
    node=other_node$i
    echo "on ${!node}"
    ssh ${!node} rm /var/lib/rabbitmq/mnesia/ -rf
    ssh ${!node} systemctl restart rabbitmq-server
done


#enable management
echo ">>> enable management"
rabbitmq-plugins enable rabbitmq_management
for i in 2 3
do
    node=other_node$i
    ssh ${!node} rabbitmq-plugins enable rabbitmq_management
done


#build cluster
echo ">>> build cluster"
for i in 2 3
do
    node=other_node$i
    ssh ${!node} rabbitmqctl stop_app
    ssh ${!node} rabbitmqctl join_cluster [email protected]${other_name1}
    ssh ${!node} rabbitmqctl start_app
done

#show rabbitmq cluster status
echo ">>> show status"
rabbitmqctl cluster_status
ssh ${other_node2} rabbitmqctl cluster_status
ssh ${other_node3} rabbitmqctl cluster_status


# set ha strategy: sync all nodes
echo ">>> set ha strategy"
rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'


#config haproxy
#echo ">>> config haproxy"
#edit_script2=/tmp/tmp_edit_ha_config_script.sh
#haproxy_conf_file=/etc/haproxy/haproxy.cfg
#if [ ! -e ${haproxy_conf_file} ];then
#    echo -e "\033[47;31m the haproxy conifg file:${haproxy_conf_file} is not exit!\033[0m"
#    exit 1
#fi
#echo ''>${edit_script2}
#echo 'sed -i "/rabbitmq_cluster/,/server.*5672/d" '$haproxy_conf_file >> ${edit_script2}
#echo 'sed -i "/server.*5672/d" '$haproxy_conf_file >> ${edit_script2}
#echo 'echo "listen rabbitmq_cluster '${ManageNetwork}':5672" >>'${haproxy_conf_file} >> ${edit_script2}
#echo 'echo "    mode tcp" >>'${haproxy_conf_file} >> ${edit_script2}
#echo 'echo "    balance roundrobin" >>'${haproxy_conf_file} >> ${edit_script2}
#for i in 1 2 3
#do
#    node=other_node$i
#    hostname=other_name$i
#    echo 'echo "    server   '${!hostname}' '${!node}':5672 check inter 2000 rise 2 fall 3" >> '${haproxy_conf_file} >> ${edit_script2}
#done
#chmod +x ${edit_script2}
#$edit_script2
#for i in 2 3
#do
#    node=other_node$i
#    scp_node=scp_node$i
#    scp ${edit_script2} ${!scp_node}:${edit_script2}
#    ssh ${!node} ${edit_script2}
#done
#
#systemctl restart haproxy
#sleep 10
#ssh ${other_node2} systemctl restart haproxy
#sleep 10
#ssh ${other_node3} systemctl restart haproxy



相关标签: rabbitmq