rabbitmq集群环境安装配置

原创
2019/08/09 23:03
阅读数 18

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

  
  
  1. 10.0.0.216 shiguang-rabbitmq-01

  2. 10.0.0.223 shiguang-rabbitmq-02

  3. 注意:请将上面内容加入2台机器 /etc/hosts (集群环境必须要加)

  • 1、安装erlang和rabbitmq-server

  
  
  1. yum -y install erlang

  2. http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.12/rabbitmq-server-3.6.12-1.el7.noarch.rpm

  3. yum -y install rabbitmq-server-3.6.12-1.el7.noarch.rpm

  • 1-最新版本安装 erlang版本必须大于erlang-20

  
  
  1. 旧版本请卸载

  2. yum -y remove erlang-*


  3. cat>>/etc/yum.repos.d/rabbitmq-erlang.repo <<\EOF

  4. [rabbitmq-erlang]

  5. name=rabbitmq-erlang

  6. baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/21/el/7

  7. gpgcheck=1

  8. gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc

  9. repo_gpgcheck=0

  10. enabled=1

  11. EOF


  12. yum clean all

  13. yum makecache

  14. yum install erlang


  15. wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.14/rabbitmq-server-3.7.14-1.el7.noarch.rpm

  16. yum install rabbitmq-server-3.7.14-1.el7.noarch.rpm

  • 2、启动mq

  
  
  1. systemctl start rabbitmq-server

  • 3、开启插件功能

  
  
  1. mkdir -p /etc/rabbitmq/

  2. chmod 777 /etc/rabbitmq

  3. rabbitmq-plugins enable rabbitmq_management

  • 4、添加用户名和密码

  
  
  1. rabbitmqctl add_user admin VQ9SBsBztjMbFuVw

  2. rabbitmqctl set_user_tags admin administrator

  3. rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"

  
  
  1. guest 默认就是guest,记住要改密码

  2. 修改密码 rabbitmqctl change_password guest phPu7Zl7uJ8fSvrf

  • 5、添加配置文件

  
  
  1. 此处可忽略

  2. #cp /usr/share/doc/rabbitmq-server-3.6.12/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config

  
  
  1. touch /etc/rabbitmq/rabbitmq.config

  2. echo "[{rabbit, [{loopback_users, []}]}]." >>/etc/rabbitmq/rabbitmq.config


  3. touch /etc/rabbitmq/rabbitmq-env.conf

  4. mkdir -p /data/logs/rabbitmq

  5. mkdir -p /data/rabbitmq

  6. chown -R rabbitmq:rabbitmq /data/rabbitmq

  7. chown -R rabbitmq:rabbitmq /data/logs/rabbitmq



  8. cat > /etc/rabbitmq/rabbitmq-env.conf <<EOF

  9. RABBITMQ_MNESIA_BASE=/data/rabbitmq

  10. RABBITMQ_LOG_BASE=/data/logs/rabbitmq

  11. RABBITMQ_PLUGINS_DIR=/usr/lib/rabbitmq/lib/rabbitmq_server-3.6.12/plugins/

  12. EOF

  • 6 如果是单点安装,执行上面步骤即可,访问http://IP:15672

二、配置集群

  • 1、cookie信息复制 ,将10.0.0.216的信息复制10.0.0.223服务器。

  
  
  1. [root@shiguang-rabbitmq-01 ~]# more /var/lib/rabbitmq/.erlang.cookie

  2. YEADMFLXEDVJQBFIWAMW

  3. [root@shiguang-rabbitmq-01 ~]#

  • 2、 2台机器分别启动rabbitmq-server启动

  
  
  1. systemctl restart rabbitmq-server

  • 3、在shiguang-rabbitmq-02上 将223加入主节点216服务器 (加入集群)

  
  
  1. 10.0.0.223 shiguang-rabbitmq-02执行命令

  2. rabbitmqctl cluster_status

  3. rabbitmqctl stop_app

  4. rabbitmqctl reset

  5. rabbitmqctl join_cluster rabbit@shiguang-rabbitmq-01

  6. rabbitmqctl start_app

  7. rabbitmqctl cluster_status


  8. 输出此信息,表示成功加入集群

  9. [root@shiguang-rabbitmq-02 rabbitmq]# rabbitmqctl join_cluster rabbit@shiguang-rabbitmq-01

  10. Clustering node 'rabbit@shiguang-rabbitmq-02' with 'rabbit@shiguang-rabbitmq-01'

  11. [root@shiguang-rabbitmq-02 rabbitmq]# rabbitmqctl start_app

  12. Starting node 'rabbit@shiguang-rabbitmq-02'


  13. 注意:默认是磁盘节点,如果是内存节点的话,需要加--ram参数

  14. rabbitmqctl join_cluster --raw rabbit@shiguang-rabbitmq-01

  • 4、查看集群信息

  
  
  1. [root@shiguang-rabbitmq-01 ~]# rabbitmqctl cluster_status

  2. WARNING: Removing trailing slash from RABBITMQ_PLUGINS_DIR

  3. Cluster status of node 'rabbit@shiguang-rabbitmq-01'

  4. [{nodes,[{disc,['rabbit@shiguang-rabbitmq-01','rabbit@shiguang-rabbitmq-02']}]},

  5. {running_nodes,['rabbit@shiguang-rabbitmq-02','rabbit@shiguang-rabbitmq-01']},

  6. {cluster_name,<<"rabbit@shiguang-rabbitmq-02">>},

  7. {partitions,[]},

  8. {alarms,[{'rabbit@shiguang-rabbitmq-02',[]},{'rabbit@shiguang-rabbitmq-01',[]}]}]

  • 5、更改节点类型(内存型或磁盘型)我们默认是disc磁盘类型(此处清忽略,一般上面默认磁盘就行)

  
  
  1. sudo rabbitmqctl stop_app

  2. sudo rabbitmqctl change_cluster_node_type disc

  3. sudo rabbitmqctl change_cluster_node_type ram

  4. sudo rabbitmqctl start_app

  • 6 做完集群配置过后,用户名和账号可能需要重新添加,添加完重启动rabbitmq-server

  
  
  1. 添加用户名和密码


  2. rabbitmqctl add_user admin VQ9SBsBztjMbFuVw

  3. rabbitmqctl set_user_tags admin administrator

  4. rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"


  5. guest 默认就是guest,记住要改密码

  6. 修改密码 rabbitmqctl change_password guest phPu7Zl7uJ8fSvrf

  
  
  1. systemctl restart rabbitmq-server

三、配置nginx访问

  
  
  1. upstream rabbit.shiguang.com {

  2. session_sticky;

  3. server 10.0.0.216:15672 max_fails=1 fail_timeout=5s;

  4. server 10.0.0.223:15672 max_fails=1 fail_timeout=5s;

  5. }

  6. server {

  7. listen 80;

  8. server_name rabbit.shiguang.com;

  9. # access_log /data/logs/nginx/rabbit.st.com.access.log st_logs;

  10. access_log /data/logs/nginx/rabbit.st.com.access.log main;

  11. error_log /data/logs/nginx/rabbit.st.com.error.log warn;


  12. location ~ /\.

  13. {

  14. deny all;

  15. }

  16. location / {

  17. proxy_next_upstream error timeout http_503 http_502 http_504 invalid_header;

  18. #limit_req zone=one burst=20 nodelay;

  19. proxy_pass http://rabbit.shiguang.com;

  20. proxy_set_header Host $host;

  21. proxy_set_header REMOTE-HOST $remote_addr;

  22. client_max_body_size 300m;

  23. client_body_buffer_size 512k;

  24. proxy_ignore_client_abort on;

  25. proxy_connect_timeout 900s;

  26. proxy_send_timeout 900s;

  27. proxy_read_timeout 900s;

  28. proxy_buffer_size 64k;

  29. proxy_buffers 4 32k;

  30. proxy_busy_buffers_size 64k;

  31. proxy_temp_file_write_size 64k;

  32. proxy_intercept_errors off;

  33. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  34. }


  35. error_page 500 502 503 504 /50x.html;

  36. location = /50x.html {

  37. root html;

  38. }

  39. }

访问http://域名


本文分享自微信公众号 - Linux运维技术之路(Linux-devops)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
在线直播报名
返回顶部
顶部