centos7.8环境安装rabbitmq3.8.5最新版并设置集群
一、编译安装,单机设置#1.增加用户groupadd rabbitmquseradd rabbitmq -g rabbitmq -s /sbin/nologin#2.安装必须编译基础包yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel#3.安装socatyum install socat -yyum install wxWidgets* -yyum install gtk+.x86_64 -y#4.环境变量,否则编译erlang可能会有问题PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/libexec/wxGTK3#5.下载ERLANG源码包wget http://erlang.org/download/otp_src_19.0.tar.gz(可不下载)wget https://erlang.org/download/otp_src_22.1.tar.gzwget https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.3/wxWidgets-3.1.3.tar.bz2(可不下载)#6.解压并安装(低版本)mkdir -p /usr/local/erlangtar xvf otp_src_19.0.tar.gzcd otp_src_19.0./configure --prefix=/usr/local/erlang --with-ssl --enable-threads --enable-smmp-support -enable-kernel-poll --enable-hipe --without-javacmake && make install#6.解压并安装(高版本)mkdir -p /usr/local/erlangtar xvf otp_src_22.1.tar.gzcd otp_src_22.1./configure --prefix=/usr/local/erlang --with-ssl=/usr/local/lab/openssl --enable-threads --enable-smmp-support -enable-kernel-poll --enable-hipe --without-javacmake && make install#7.解压并安装(由于是通过yum安装,无需执行,如果是编译安装可以按照下面方法)bzip2 -d wxWidgets-3.1.3.tar.bz2 tar xvf wxWidgets-3.1.3.tarcd wxWidgets-3.1.3./configure --with-opengl --enable-debug --enable-unicode#8.修改环境变量vi /etc/profileERLANG_HOME=/usr/local/erlangPATH=$ERLANG_HOME/bin:$PATHexport ERLANG_HOMEexport PATH#9.生效环境变量source /etc/profile#10.测试是否支持ERLANG语言,输入erl后会弹出提示 按CTRL+C 退出erl#11. 安装simpleJson wget https://github.com/simplejson/simplejson/releases/download/v3.16.1/simplejson-3.16.1.tar.gztar zxvf simplejson-3.16.1.tar.gzcd simplejson-3.16.1python setup.py install#12.下载rabbitmq二进制免编译包(最新版本)cd /usr/local/srcwget wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.5/rabbitmq-server-generic-unix-3.8.5.tar.xz#12.下载rabbitmq二进制免编译包cd /usr/local/srcwget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server-generic-unix-3.6.10.tar.xz#13.解压并安装xz -d rabbitmq-server-generic-unix-3.8.5.tar.xztar xvf rabbitmq-server-generic-unix-3.8.5.tarmv rabbitmq_server-3.8.5 /usr/localcd /usr/local/ln -s rrabbitmq_server-3.8.5 rabbitmqcd ./rabbitmq/sbin/#14.修改/etc/profile文件,添加下面的环境变量:export PATH=$PATH:/usr/local/rabbitmq/sbin执行source /etc/profile让文件生效。#15.设置开启自启脚本chown -R rabbitmq.rabbitmq rabbitmq_server-3.8.5添加 source /etc/profile 否则可能提示erl无法找到vi /usr/local/rabbitmq/sbin/rabbitmq-envsource /etc/profile/usr/local/rabbitmq/var/log/rabbitmq/rabbit@eus-video-compose02.log# cat ~/.erlang.cookie QBISJBZGKYVFNASJQWDQ注意 .erlang.cookie 文件在/home/rabbitmq 下,因通过rabbitmq账户去启动,并且/root/下的 .erlang.cookie值要和/home/rabbitmq 下的文件值保持一致,否则集群无法启动# 启动管理程序
cat /usr/lib/systemd/system/rabbitmq-server.service [Unit] Description=RabbitMQ broker After=syslog.target network.target [Service] Type=notify User=rabbitmq Group=rabbitmq UMask=0027 NotifyAccess=all TimeoutStartSec=3600 # To override LimitNOFILE, create the following file: # # /etc/systemd/system/rabbitmq-server.service.d/limits.conf # # with the following content: # # [Service] # LimitNOFILE=65536 LimitNOFILE=32768 # Note: systemd on CentOS 7 complains about in-line comments, # so only append them here # # Restart: # The following setting will automatically restart RabbitMQ # in the event of a failure. systemd service restarts are not a # replacement for service monitoring. Please see # https://www.rabbitmq.com/monitoring.html Restart=on-failure RestartSec=10 WorkingDirectory=/usr/local/rabbitmq/var/lib/rabbitmq ExecStart=/usr/local/rabbitmq/sbin/rabbitmq-server ExecStop=/usr/local/rabbitmq/sbin/rabbitmqctl shutdown # See rabbitmq/rabbitmq-server-release#51 SuccessExitStatus=69 [Install] WantedBy=multi-user.target# 无法启动的原因可能是日志使用rabbitmq用户没有权限chown -R rabbitmq.rabbitmq /usr/local/rabbitmq_server-3.8.5#15.启动rabbitMQsystemctl start rabbitmq-server.service#15.启动rabbitMQ(可选,但是最好不要这样启动)rabbitmq-server#15.后台运行服务(可选,但是最好不要这样启动)rabbitmq-server -detached#16.设置开机自启systemctl enable rabbitmq-server.service #17.关闭rabbitMQsystemctl stop rabbitmq-server.service#17.关闭rabbitMQrabbitmqctl stop#18.安装web界面扩展rabbitmq-plugins enable rabbitmq_management#19.添加用户rabbitmqctl add_user admin pass#20.列出用户rabbitmqctl list_users#21.将admin指定为管理员权限rabbitmqctl set_user_tags admin administrator#22.删除来宾用户rabbitmqctl delete_user guest#23.安装成功,访问如下地址http://192.168.101.21:15672/二.加入集群#1.修改 /etc/hosts# rabbitmq cluster172.30.0.1 eus-video-compose01172.30.0.2 eus-video-compose02#2.设置 Erlang Cookie,路径为/home/rabbitmq/.erlang.cookie,这里将 eus-video-compose01 的该文件复制到 eus-video-compose02,由于这个文件权限是 400,所以需要先修改 eus-video-compose02,中的该文件权限为 777,然后将 node1 中的该文件拷贝到 node2,最后将权限和所属用户/组修改回来chown rabbitmq /home/rabbitmq/.erlang.cookiechgrp rabbitmq /home/rabbitmq/.erlang.cookie也可以直接复制里面的内容,让两台机器的 .erlang.cookie 内容保持一致#3.使用 -detached 参数运行各节点systemctl stop rabbitmq-server.service #推荐rabbitmqctl stop #不推荐systemctl start rabbitmq-server.service #推荐rabbitmq-server -detached #不推荐#4.组成集群,注意防火墙开启4637端口,在eus-video-compose01上执行rabbitmqctl stop_apprabbitmqctl join_cluster rabbit@eus-video-compose02[root@eus-video-compose01:~]# rabbitmqctl join_cluster rabbit@eus-video-compose02Clustering node rabbit@eus-video-compose01 with rabbit@eus-video-compose02rabbitmqctl start_app#5.如果要使用内存节点,则可以使用下面的命令加入集群。rabbitmqctl join_cluster *--ram* rabbit@rabbitmq_02设置镜像集群模式:#6.设置镜像队列策略,在任意一个节点上执行下面的命令,将所有队列设置为镜像队列,即队列会被复制到各个节点,各个节点状态保持一直rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'[root@eus-video-compose01:~]# rabbitmqctl list_policiesListing policies for vhost "/" ...[root@eus-video-compose01:~]# rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'Setting policy "ha-all" for pattern "^" to "{"ha-mode":"all"}" with priority "0" for vhost "/" ...[root@eus-video-compose01:~]# rabbitmqctl list_policiesListing policies for vhost "/" ...vhost name pattern apply-to definition priority/ ha-all ^ all {"ha-mode":"all"} 0[root@eus-video-compose02:/usr/local]# rabbitmqctl list_policiesListing policies for vhost "/" ...vhost name pattern apply-to definition priority/ ha-all ^ all {"ha-mode":"all"} 0查看集群状态:# rabbitmqctl cluster_status