rabbitmq集群环境安装配置

2022-06-07 09:08:03 浏览数 (2)

一、主机清单 2台机器同时执行下面安装步骤

代码语言:javascript复制
10.0.0.216 shiguang-rabbitmq-01  
10.0.0.223 shiguang-rabbitmq-02
注意:请将上面内容加入2台机器 /etc/hosts (集群环境必须要加)
  • 1、安装erlang和rabbitmq-server
代码语言:javascript复制
yum -y install erlang
http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.12/rabbitmq-server-3.6.12-1.el7.noarch.rpm
yum -y install rabbitmq-server-3.6.12-1.el7.noarch.rpm
  • 1-最新版本安装 erlang版本必须大于erlang-20
代码语言:javascript复制
旧版本请卸载
yum -y remove erlang-*

cat>>/etc/yum.repos.d/rabbitmq-erlang.repo <<EOF
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/21/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1
EOF

yum clean all
yum makecache
yum install erlang

wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.14/rabbitmq-server-3.7.14-1.el7.noarch.rpm
yum install rabbitmq-server-3.7.14-1.el7.noarch.rpm
  • 2、启动mq
代码语言:javascript复制
systemctl start rabbitmq-server
  • 3、开启插件功能
代码语言:javascript复制
mkdir -p /etc/rabbitmq/
chmod 777 /etc/rabbitmq
rabbitmq-plugins enable rabbitmq_management
  • 4、添加用户名和密码
代码语言:javascript复制
rabbitmqctl add_user admin VQ9SBsBztjMbFuVw
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
代码语言:javascript复制
guest 默认就是guest,记住要改密码
修改密码 rabbitmqctl change_password guest  phPu7Zl7uJ8fSvrf
  • 5、添加配置文件
代码语言:javascript复制
此处可忽略
#cp /usr/share/doc/rabbitmq-server-3.6.12/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config
代码语言:javascript复制
touch /etc/rabbitmq/rabbitmq.config
echo "[{rabbit, [{loopback_users, []}]}]." >>/etc/rabbitmq/rabbitmq.config

touch /etc/rabbitmq/rabbitmq-env.conf
mkdir -p /data/logs/rabbitmq
mkdir -p /data/rabbitmq
chown -R rabbitmq:rabbitmq /data/rabbitmq
chown -R rabbitmq:rabbitmq /data/logs/rabbitmq


cat > /etc/rabbitmq/rabbitmq-env.conf <<EOF
RABBITMQ_MNESIA_BASE=/data/rabbitmq
RABBITMQ_LOG_BASE=/data/logs/rabbitmq
RABBITMQ_PLUGINS_DIR=/usr/lib/rabbitmq/lib/rabbitmq_server-3.6.12/plugins/
EOF
  • 6 如果是单点安装,执行上面步骤即可,访问http://IP:15672

二、配置集群

  • 1、cookie信息复制 ,将10.0.0.216的信息复制10.0.0.223服务器。
代码语言:javascript复制
[root@shiguang-rabbitmq-01 ~]# more  /var/lib/rabbitmq/.erlang.cookie
YEADMFLXEDVJQBFIWAMW
[root@shiguang-rabbitmq-01 ~]#
  • 2、 2台机器分别启动rabbitmq-server启动
代码语言:javascript复制
systemctl restart rabbitmq-server
  • 3、在shiguang-rabbitmq-02上 将223加入主节点216服务器 (加入集群)
代码语言:javascript复制
在10.0.0.223 shiguang-rabbitmq-02执行命令
rabbitmqctl cluster_status
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@shiguang-rabbitmq-01
rabbitmqctl start_app
rabbitmqctl cluster_status

输出此信息,表示成功加入集群
[root@shiguang-rabbitmq-02 rabbitmq]# rabbitmqctl  join_cluster rabbit@shiguang-rabbitmq-01
Clustering node 'rabbit@shiguang-rabbitmq-02' with 'rabbit@shiguang-rabbitmq-01'
[root@shiguang-rabbitmq-02 rabbitmq]# rabbitmqctl start_app
Starting node 'rabbit@shiguang-rabbitmq-02'

注意:默认是磁盘节点,如果是内存节点的话,需要加--ram参数
(rabbitmqctl join_cluster --raw rabbit@shiguang-rabbitmq-01)
  • 4、查看集群信息
代码语言:javascript复制
[root@shiguang-rabbitmq-01 ~]# rabbitmqctl cluster_status
WARNING: Removing trailing slash from RABBITMQ_PLUGINS_DIR
Cluster status of node 'rabbit@shiguang-rabbitmq-01'
[{nodes,[{disc,['rabbit@shiguang-rabbitmq-01','rabbit@shiguang-rabbitmq-02']}]},
 {running_nodes,['rabbit@shiguang-rabbitmq-02','rabbit@shiguang-rabbitmq-01']},
 {cluster_name,<<"rabbit@shiguang-rabbitmq-02">>},
 {partitions,[]},
 {alarms,[{'rabbit@shiguang-rabbitmq-02',[]},{'rabbit@shiguang-rabbitmq-01',[]}]}]
  • 5、更改节点类型(内存型或磁盘型)我们默认是disc磁盘类型(此处清忽略,一般上面默认磁盘就行)
代码语言:javascript复制
sudo rabbitmqctl stop_app
sudo rabbitmqctl change_cluster_node_type disc
或
sudo rabbitmqctl change_cluster_node_type ram
sudo rabbitmqctl start_app
  • 6 做完集群配置过后,用户名和账号可能需要重新添加,添加完重启动rabbitmq-server
代码语言:javascript复制
添加用户名和密码

rabbitmqctl add_user admin VQ9SBsBztjMbFuVw
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"

guest 默认就是guest,记住要改密码
修改密码 rabbitmqctl change_password guest  1234567890
代码语言:javascript复制
systemctl restart rabbitmq-server

三、配置nginx访问

代码语言:javascript复制
upstream rabbit.shiguang.com {
    session_sticky;
        server 10.0.0.216:15672 max_fails=1 fail_timeout=5s;
        server 10.0.0.223:15672 max_fails=1 fail_timeout=5s;
}
server {
        listen       80;
        server_name  rabbit.shiguang.com;
       
        access_log   /data/logs/nginx/access.log  main;
         error_log    /data/logs/nginx/error.log  warn;

 
        location / {
           proxy_next_upstream error timeout http_503 http_502 http_504 invalid_header;
       #limit_req zone=one burst=20 nodelay;
           proxy_pass http://rabbit.shiguang.com;
           proxy_set_header Host  $host;
           proxy_set_header REMOTE-HOST $remote_addr;
           client_max_body_size 300m;
           client_body_buffer_size 512k;
           proxy_ignore_client_abort on;
           proxy_connect_timeout 900s;
           proxy_send_timeout 900s;
           proxy_read_timeout 900s;
           proxy_buffer_size 64k;
           proxy_buffers 4 32k;
           proxy_busy_buffers_size 64k;
           proxy_temp_file_write_size 64k;
           proxy_intercept_errors off;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

访问http://域名

0 人点赞