(1)下载
https://www.erlang.org/downloads
https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.25/rabbitmq-server-windows-3.7.25.zip
(2)安装Erlang
① 安装 otp_win64_22.3.exe
②新增系统环境变量 ERLANG_HOME
C:\Program Files\erl10.7③ path 新增Erlang的环境变量(win10编辑path,新增,老系统自行编辑使用‘;’分隔)
%ERLANG_HOME%\bin④cmd 运行erl命令 检测是否配置成功
C:\Users\Jason>erl Eshell V10.7 (abort with ^G) 1>(3)安装rabbitMQ
①解压zip文件,放置需安装的目录
②新增系统环境变量
RABBITMQ_SERVER = C:\Program Files\rabbitMQ\rabbitmq_server-3.7.25
③path新增rabbitmq的环境变量(win10编辑path,新增,老系统自行编辑使用‘;’分隔)
%RABBITMQ_SERVER%\sbin
④cmd 安装 web管理插件,命令:rabbitmq-plugins.bat enable rabbitmq_management
C:\Program Files\rabbitMQ\rabbitmq_server-3.7.25\sbin>rabbitmq-plugins.bat enable rabbitmq_management Enabling plugins on node rabbit@DESKTOP-L7KEGJ6: rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch Applying plugin configuration to rabbit@DESKTOP-L7KEGJ6... The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch set 3 plugins. Offline change; changes will take effect at broker restart.⑤启动rabbitmq,命令: rabbitmq-server.bat
C:\Program Files\rabbitMQ\rabbitmq_server-3.7.25\sbin>rabbitmq-server.bat ## ## ## ## RabbitMQ 3.7.25. Copyright (c) 2007-2020 Pivotal Software, Inc. ########## Licensed under the MPL. See https://www.rabbitmq.com/ ###### ## ########## Logs: C:/Users/Jason/AppData/Roaming/RabbitMQ/log/rabbit@DESKTOP-L7KEGJ6.log C:/Users/Jason/AppData/Roaming/RabbitMQ/log/rabbit@DESKTOP-L7KEGJ6_upgrade.log Starting broker... completed with 3 plugins.⑥浏览器访问:http://localhost:15672,本地访问guest/guest(3.3.1版本以后默认不允许用guest远程管理,需先添加管理用户)
https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.25/rabbitmq-server-generic-unix-3.7.25.tar.xz
https://packagecloud.io/rabbitmq/erlang/packages/el/7/erlang-22.3.2-1.el7.x86_64.rpm/download.rpm(7.x)
https://packagecloud.io/rabbitmq/erlang/packages/el/6/erlang-22.3.2-1.el6.x86_64.rpm/download.rpm(6.x)
①安装对应rpm文件
[root@localhost rabbitMQ]# rpm -ivh erlang-22.3.2-1.el6.x86_64.rpm warning: erlang-22.3.2-1.el6.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 6026dfca: NOKEY Preparing... ########################################### [100%] 1:erlang ########################################### [100%]若出现以下错误
[root@node01 rabbitMQ]# rpm -ivh erlang-22.3.2-1.el7.x86_64.rpm 警告:erlang-22.3.2-1.el7.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID 6026dfca: NOKEY 错误:依赖检测失败: libcrypto.so.10(OPENSSL_1.0.2)(64bit) 被 erlang-22.3.2-1.el7.x86_64 需要则升级 openssl-libs-1.0.2k-19.el7.x86_64.rpm,再安装Erlang
[root@node01 rabbitMQ]# rpm -ivh openssl-libs-1.0.2k-19.el7.x86_64.rpm --force 警告:openssl-libs-1.0.2k-19.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:openssl-libs-1:1.0.2k-19.el7 ################################# [100%]②检查是否安装成功
[root@localhost rabbitMQ]# erl Erlang/OTP 22 [erts-10.7.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] Eshell V10.7.1 (abort with ^G) 1>①解压rabbitmq-server-generic-unix-3.7.25.tar.xz
tar -xvf rabbitmq-server-generic-unix-3.7.25.tar.xz②进入sbin目录
cd rabbitmq_server-3.7.25/sbin③启动服务
[root@localhost sbin]# ./rabbitmq-server -detached Warning: PID file not written; -detached was passed.④开启web管理界面(http://ServerIP:15672)
[root@localhost sbin]# ./rabbitmq-plugins enable rabbitmq_management Enabling plugins on node rabbit@localhost: rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch Applying plugin configuration to rabbit@localhost... The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch started 3 plugins.⑤添加用户,需先启动服务(3.3.1版本以后默认不允许用guest远程管理。需手动创建管理员帐号来远程管理)
[root@localhost sbin]# ./rabbitmqctl add_user admin admin Adding user "admin" ... [root@localhost sbin]# ./rabbitmqctl set_user_tags admin administrator Setting tags for user "admin" to [administrator] ... [root@localhost sbin]# ./rabbitmqctl set_permissions -p / admin '.*' '.*' '.*' Setting permissions for user "admin" in vhost "/" ...⑥添加环境变量
# vi /etc/profile 添加 export PATH=$PATH:/usr/local/xiaoll/rabbitMQ/rabbitmq_server-3.7.25/sbin # source /etc/profile # env⑦设置开机自启并加入系统服务
1)添加启动文件
# vi /etc/init.d/rabbitmq #!/bin/bash export RABBITMQ_HOME=/usr/local/xiaoll/rabbitMQ/rabbitmq_server-3.7.25 export PATH=$PATH:$RABBITMQ_HOME/sbin #erlang文件路径 export HOME=/root export LC_ALL=en_US.UTF-8 # chkconfig: 2345 80 05 # description: rabbitmq # processname: rabbitmq case "$1" in start) echo "Starting RabbitMQ ..." cd $RABBITMQ_HOME/sbin ./rabbitmq-server -detached sleep 30s ./rabbitmqctl trace_on ;; stop) echo "Stopping RabbitMQ ..." cd $RABBITMQ_HOME/sbin ./rabbitmqctl stop ;; status) echo "Status RabbitMQ ..." cd $RABBITMQ_HOME/sbin ./rabbitmqctl status ;; *) echo "Usage: $prog {start|stop|status}" ;; esac exit 02)授予执行权限
# chmod +x /etc/init.d/rabbitmq3)添加到系统服务
# chkconfig --add rabbitmq # chkconfig --list rabbitmq4)启动并检查是否成功
# service rabbitmq start # ps -ef|grep rabbitmq5)重启服务器,检验开机自启是否配置成功
(即镜像模式,其实就是普通模式开启队列复制,分全部节点复制(all)、固定份数(exactly)、固定节点复制(nodes)三种)
RabbitMQ 的 Cluster 集群模式一般分为两种,普通模式和镜像模式。
普通模式:默认的集群模式,以两个节点(rabbit01、rabbit02)为例来进行说明。对于 Queue 来说,消息实体只存在于其中一个节点 rabbit01(或者 rabbit02),rabbit01 和 rabbit02 两个节点仅有相同的元数据,即队列的结构。当消息进入 rabbit01 节点的 Queue 后,consumer 从 rabbit02 节点消费时,RabbitMQ 会临时在 rabbit01、rabbit02 间进行消息传输,把 A 中的消息实体取出并经过 B 发送给 consumer。所以 consumer 应尽量连接每一个节点,从中取消息。即对于同一个逻辑队列,要在多个节点建立物理 Queue。否则无论 consumer 连 rabbit01 或 rabbit02,出口总在 rabbit01,会产生瓶颈。当 rabbit01 节点故障后,rabbit02 节点无法取到 rabbit01 节点中还未消费的消息实体。如果做了消息持久化,那么得等 rabbit01 节点恢复,然后才可被消费;如果没有持久化的话,就会产生消息丢失的现象。镜像模式:将需要消费的队列变为镜像队列,存在于多个节点,这样就可以实现 RabbitMQ 的 HA 高可用性。作用就是消息实体会主动在镜像节点之间实现同步,而不是像普通模式那样,在 consumer 消费数据时临时读取。缺点就是,集群内部的同步通讯会占用大量的网络带宽。①准备两台或两台以上服务器(本次配置157、158、159)
②并修改三台服务器的/etc/hosts, vi /etc/hosts,内容如下
192.168.166.159 rabbit1 192.168.166.158 rabbit2 192.168.166.157 rabbit3③互相测试网络,检查是否正常
#ping rabbit1 #ping rabbit2 #ping rabbit3④在每台服务器上安装Erlang和rabbitMQ(后续两台只解压即可,若第一台159已经启动请先关闭)
⑤把192.168.166.159上的.erlang.cookie以scp的方式拷贝到另外两台机器。(如果mq没有启动过是没有erlang.cookie的)
Rabbitmq的集群是依附于erlang的集群来工作的,所以必须先构建起erlang的集群景象。Erlang的集群中各节点是经由过程一个magic cookie来实现的,这个cookie存放在/root/.erlang.cookie(隐藏文件)中,文件是400的权限。所以必须保证各节点cookie一致,不然节点之间就无法通信。
#scp /root/.erlang.cookie root@rabbit2:/root/.erlang.cookie #scp /root/.erlang.cookie root@rabbit3:/root/.erlang.cookie⑥检查3台服务器文件内容是否一致
#cat /root/.erlang.cookie⑦修改每一台的node名称(linux 默认节点名为 rabbit@$hostname)
[root@localhost sbin]# vi ../etc/rabbitmq/rabbitmq-env.conf内容如下(rabbit@rabbit1、rabbit@rabbit2、rabbit@rabbit3)
NODENAME=rabbit@rabbit1⑧三台服务器,都启动rabbitmq
#./rabbitmq-server -detached⑧在157、158上执行以下命令,以ram类型节点加入159集群
./rabbitmqctl stop_app ./rabbitmqctl join_cluster rabbit@rabbit1 --ram ./rabbitmqctl start_app⑨在157、158上,开启web管理界面(http://ServerIP:15672),否则在159的管理界面上,监控不到157、158的信息,开启后可连接任意一台的管理界面查看集群信息
[root@node01 sbin]# ./rabbitmq-plugins enable rabbitmq_management Enabling plugins on node rabbit@rabbit2: rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch Applying plugin configuration to rabbit@rabbit2... The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch started 3 plugins.⑩开启镜像复制(在集群任意一台执行即可)
[root@orcldb sbin]# ./rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all","ha-sync-mode":"automatic"}' Setting policy "ha-all" for pattern "^" to "{"ha-mode":"all","ha-sync-mode":"automatic"}" with priority "0" for vhost "/" ...选择一个节点安装(本次选择159)
①下载
https://src.fedoraproject.org/repo/pkgs/haproxy/haproxy-1.8.25.tar.gz/sha512/655eb4056989a3fee321ea9278a2085b0a999e522293f1f6229ebb8d17f3d33cb78abb4fd55a06d0218082e632b2d42de105575d0acd0c1b49996d4b45aa78e8/haproxy-1.8.25.tar.gz
②解压
tar -zxvf haproxy-1.8.25.tar.gz③打开haproxy目录
cd haproxy-1.8.25④编译安装(uname -r 先查看系统内核版本。centos6.x使用linux26,centos7.x使用linux31)
make TARGET=linux26 ARCH=x86_64 make install PREFIX=/usr/local/xiaoll/haproxy⑤创建配置文件
mkdir /usr/local/xiaoll/haproxy/conf vi /usr/local/xiaoll/haproxy/conf/haproxy.cfg⑥修改配置文件
### 公共配置 global maxconn 20000 log 127.0.0.1 local0 chroot /usr/local/xiaoll/haproxy pidfile /usr/local/xiaoll/haproxy/haproxy.pid ###haproxy的pid存放路径,启动进程的用户必须有权限访问此文件 daemon ### 默认配置 defaults mode tcp retries 3 timeout connect 20s timeout client 60s timeout server 60s #每个进程可用的最大连接数 maxconn 2500 ### haproxy 监控页面地址是:http://192.168.166.159:9188/rabbit_status listen admin_stats bind *:9188 mode http log 127.0.0.1 local3 err stats refresh 60s stats uri /rabbit_status stats realm welcome login\ Haproxy stats auth admin:admin stats hide-version stats admin if TRUE ### rabbitmq 集群配置,转发到 listen rabbitmq_cluster bind *:9189 mode tcp balance roundrobin server rabbit1 192.168.166.159:5672 check inter 2000 rise 2 fall 3 weight 1 server rabbit2 192.168.166.158:5672 check inter 2000 rise 2 fall 3 weight 1 server rabbit3 192.168.166.157:5672 check inter 2000 rise 2 fall 3 weight 1 ### rabbitmq management 配置,转发到 listen rabbitmq_management bind *:15673 mode http balance roundrobin server rabbit1 192.168.166.159:15672 check inter 2000 rise 2 fall 3 weight 1 server rabbit2 192.168.166.158:15672 check inter 2000 rise 2 fall 3 weight 1 server rabbit3 192.168.166.157:15672 check inter 2000 rise 2 fall 3 weight 1⑦启动
/usr/local/xiaoll/haproxy/sbin/haproxy -f /usr/local/xiaoll/haproxy/conf/haproxy.cfg⑧开机自启
编辑启动文件
# vi /etc/init.d/haproxy #!/bin/bash #chkconfig: 2345 10 90 #description:haproxy BASE_DIR=/usr/local/xiaoll/haproxy ARGV="$@" start() { echo "START HAPoxy SERVERS" $BASE_DIR/sbin/haproxy -f $BASE_DIR/conf/haproxy.cfg } stop() { echo "STOP HAPoxy Listen" kill -TTOU $(cat $BASE_DIR/haproxy.pid) echo "STOP HAPoxy process" kill -USR1 $(cat $BASE_DIR/haproxy.pid) } case $ARGV in start) start ERROR=$? ;; stop) stop ERROR=$? ;; restart) stop start ERROR=$? ;; *) echo "hactl.sh [start|restart|stop]" esac exit $ERROR授权并加入服务
# chmod +x /etc/init.d/haproxy # chkconfig --add haproxy # service haproxy start