centos7.9 安装rabbitmq 3.6.15 集群

安装依赖

yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel libxml2-utils libxml2 \
libxslt openssl-devel unixODBC unixODBC-devel unixODBC-bin gtk2 fop wxWidgets-devel wxBase

ln -s /usr/bin/wx-config-3.0 /usr/bin/wx-config

安装erlang

mkdir /opt/erlang
cd /opt/erlang
wget http://soft.download/soft/linux/mq-server/erlang_otp_src_20.3.tar.gz
tar zxvf erlang_otp_src_20.3.tar.gz

cd otp_src_20.3
./configure --prefix=/usr/local/erlang --with-ssl -enable-threads \
-enable-smmp-support -enable-kernel-poll --enable-hipe --disable-javac
make && make install

安装java

参考java安装

export JAVA_HOME=/usr/local/java/
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

添加erlang环境变量

vim /etc/profile.d/erlang.sh

export ERLANG_HOME=/usr/local/erlang
export ERL_DIR=${ERLANG_HOME}/bin
export PATH=${ERLANG_HOME}/bin:$PATH

source /etc/profile

安装rabbitmq

yum install -y xz

groupadd rabbitmq
useradd -g rabbitmq rabbitmq -d /var/lib/rabbitmq -s /sbin/nologin
mkdir /opt/rabbitmq
cd /opt/rabbitmq
wget  http://soft.download/soft/linux/mq-server/rabbitmq-server-generic-unix-3.6.15.tar.xz 
unxz rabbitmq-server-generic-unix-3.6.15.tar.xz 
tar -xvf rabbitmq-server-generic-unix-3.6.15.tar 
mv rabbitmq_server-3.6.15/ /data/rabbitmq-server
chown -R rabbitmq:rabbitmq /data/rabbitmq-server/

ln -s /data/rabbitmq-server/sbin/rabbitmqctl /usr/bin/rabbitmqctl
ln -s /data/rabbitmq-server/sbin/rabbitmq-defaults /usr/bin/rabbitmq-defaults
ln -s /data/rabbitmq-server/sbin/rabbitmq-env /usr/bin/rabbitmq-env
ln -s /data/rabbitmq-server/sbin/rabbitmq-plugins /usr/bin/rabbitmq-plugins
ln -s /data/rabbitmq-server/sbin/rabbitmq-server /usr/bin/rabbitmq-server

cd /data/rabbitmq-server/etc/rabbitmq/
##要修改node名称,结合/etc/hosts
wget http://soft.download/soft/linux/mq-server/config/rabbitmq-env.conf
wget  http://soft.download/soft/linux/mq-server/config/rabbitmq.config

cat  /data/rabbitmq-server/etc/rabbitmq/rabbitmq-env.conf

#RABBITMQ_NODE_IP_ADDRESS= //IP地址,空串bind所有地址,指定地址bind指定网络接口
#RABBITMQ_NODE_PORT=       //TCP端口号,默认是5672
#RABBITMQ_NODENAME=        //节点名称。默认是rabbit
#RABBITMQ_CONFIG_FILE= //配置文件路径 ,即rabbitmq.config文件路径
#RABBITMQ_MNESIA_BASE=     //mnesia所在路径
#RABBITMQ_LOG_BASE=        //日志所在路径
#RABBITMQ_PLUGINS_DIR=     //插件所在路径

# mq01为主机名
RABBITMQ_NODENAME=rabbit@mq1

cat  /data/rabbitmq-server/etc/rabbitmq/rabbitmq.config

[
 {rabbit,
  [
   {vm_memory_high_watermark,0.6},
   {vm_memory_watermark_paging_ratio,0.5}
  ]},
 {kernel,
  []},
 {rabbitmq_management,
  []},
 {rabbitmq_shovel,
  [{shovels,
    []}
  ]},
 {rabbitmq_stomp,
  []},
 {rabbitmq_mqtt,
  []},
 {rabbitmq_amqp1_0,
  []},
 {rabbitmq_auth_backend_ldap,
  []}
].

设置hosts

192.168.1.120 mq1
192.168.1.121 mq2
192.168.1.122 mq3

开机自启

cd /etc/systemd/system/
wget  http://soft.download/soft/linux/mq-server/config/rabbitmq-server.service -O /etc/systemd/system/rabbitmq-server.service

cat /etc/systemd/system/rabbitmq-server.service

[Unit]
Description=RabbitMQ broker
After=syslog.target network.target

[Service]
Type=simple
User=rabbitmq
Group=rabbitmq
LimitNOFILE=65535
WorkingDirectory=/data/rabbitmq-server
ExecStart=/data/rabbitmq-server/sbin/rabbitmq-server
ExecStop=/data/rabbitmq-server/sbin/rabbitmqctl stop
NotifyAccess=all
TimeoutStartSec=3600

[Install]
WantedBy=multi-user.target

修改启动脚本

vim +80 /data/rabbitmq-server/sbin/rabbitmq-server
#加入erlang环境变量
export ERLANG_HOME=/usr/local/erlang
export PATH=${ERLANG_HOME}/bin:$PATH

sed -i '80i export PATH=${ERLANG_HOME}/bin:$PATH' rabbitmq-server
sed -i '80i export ERLANG_HOME=/usr/local/erlang' rabbitmq-server

启动服务

systemctl start rabbitmq-server.service
systemctl status rabbitmq-server.service
systemctl enable rabbitmq-server.service

开放端口

firewall-cmd --zone=public --add-port=4369/tcp --permanent&&firewall-cmd --reload
firewall-cmd --zone=public --add-port=5672/tcp --permanent&&firewall-cmd --reload
firewall-cmd --zone=public --add-port=25672/tcp --permanent&&firewall-cmd --reload
firewall-cmd --zone=public --add-port=15672/tcp --permanent&&firewall-cmd --reload

创建账号、vhost、开启管理插件、删除guest账号

rabbitmqctl list_users -n rabbit@mq01

rabbitmq-plugins enable rabbitmq_management -n rabbit@mq1


rabbitmqctl add_user gadmin 123456 -n rabbit@mq01
rabbitmqctl add_user dev 123456 -n rabbit@mq1
rabbitmqctl add_user cloud 123456 -n rabbit@mq1
rabbitmqctl add_user test 123456 -n rabbit@mq1
#分配用户标签
rabbitmqctl set_user_tags gadmin administrator
rabbitmqctl set_user_tags dev administrator
rabbitmqctl set_user_tags cloud administrator
rabbitmqctl set_user_tags test administrator


添加vhost
rabbitmqctl add_vhost /dev -n rabbit@mq1
rabbitmqctl add_vhost /cloud -n rabbit@mq1
rabbitmqctl add_vhost /test -n rabbit@mq1


授权账号vhost权限
rabbitmqctl  set_permissions -p /  gadmin '.*' '.*' '.*' -n rabbit@mq01
rabbitmqctl  set_permissions -p /dev  dev '.*' '.*' '.*' -n rabbit@mq1
rabbitmqctl  set_permissions -p /cloud  cloud '.*' '.*' '.*' -n rabbit@mq1
rabbitmqctl  set_permissions -p /test  test '.*' '.*' '.*' -n rabbit@mq1

查看集群状态
rabbitmqctl cluster_status -n rabbit@mq1

# 设置权限
rabbitmqctl  set_permissions -p /  gadmin '.*' '.*' '.*'


rabbitmqctl delete_user guest -n rabbit@mq1

新节点加入集群

注意:
	所有节点的.erlang.cookie的值要一致
	如果需要root账号也能执行rabbitmqctl命令,需要把.erlang.cookie拷贝到/root/路径下

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@mq1
rabbitmqctl start_app
相关推荐
黑龙江亿林等保几秒前
深入探索哈尔滨二级等保下的负载均衡SLB及其核心算法
运维·算法·负载均衡
黄小耶@1 分钟前
linux常见命令
linux·运维·服务器
叫我龙翔3 分钟前
【计网】实现reactor反应堆模型 --- 框架搭建
linux·运维·网络
古驿幽情5 分钟前
CentOS AppStream 8 手动更新 yum源
linux·运维·centos·yum
BillKu6 分钟前
Linux(CentOS)安装 Nginx
linux·运维·nginx·centos
BillKu9 分钟前
Linux(CentOS)yum update -y 事故
linux·运维·centos
明达技术11 分钟前
物联优化汽车齿轮锻造
分布式·物联网
a2663789614 分钟前
解决yum命令报错“Could not resolve host: mirrorlist.centos.org
linux·运维·centos
上海文顺负载箱27 分钟前
如何评估焊机测试负载均衡性能
运维·负载均衡
铁锤妹妹头发多1 小时前
新手用docker真**难受
运维·docker·容器