运维之路_rabbitmq
[环境:centos 7]
##下在erlang安装包
wget https://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
##下载rabbimq 仓库
rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
cat > /etc/yum.repos.d/rabbitmq.repo << EOF
[rabbitmq]
name=rabbitmq
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/el/7/
gpgcheck=0
enabled=1
EOF
#安装erlang和rabbixmq
yum repolist
yum -y install erlang.x86_64
yum -y install erlang-solutions-1.0-1.noarch.rpm
yum -y install rabbitmq-server.noarch
#rabbitmq 启动管理插件与增加用户和设置权限
rabbitmq-plugins enable rabbitmq_management
rabbitmqctl add_user leo leo123
rabbitmqctl setset_user_tags administrator
rabbitmqctl set_user_tags administrator
rabbitmqctl set_permissions -p / leo ".*" ".*" ".*"
#启动服务
systemctl start rabbitmq
###########################################
###########################################
#修改主机名 (各台主机上操作)
echo "leo1" > /etc/hostname ;hostname leo1
echo "leo2" > /etc/hostname;hostname leo2
echo "leo3" > /etc/hostname;hostname leo3
#修改host(三台主机都需要操作)
cat > /etc/hosts << EOF
172.20.101.56 leo1
172.20.101.114 leo2
172.20.101.18 leo3
EOF
##########################################
集群配置:
ip 主机名
172.20.101.56 leo1
172.20.101.114 leo2
172.20.101.18 leo3
#保证他们直接能够用主机名ping通
#杀死从进程节点
ps -ef|grep rab|grep -v grep |awk '{print $2}'|xargs kill -9
#集群主节点操作(保证cookie相同)
cd /var/lib/rabbitmq/
chmod 777 .erlang.cookie
scp .erlang.cookie rabbitmq@172.20.101.114:/var/lib/rabbitmq/
scp .erlang.cookie rabbitmq@172.20.101.18:/var/lib/rabbitmq/
chmod 400 .erlang.cookie
#启动从节点
systemctl restart rabbitmq-server.service
rabbitmqctl cluster_status
#从节点加入集群
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@leo1
rabbitmqctl start_app
rabbitmqctl cluster_status
#登陆http://172.20.101.56:15672/#/查看web界面
#增加镜像
rabbitmqctl set_policy ha-all "hello" '{"ha-mode":"all"}' #增加hellp队列镜像