每一个你不满意的现在,都有一个你不努力的曾经。
RabbitMQ二进制安装部署
rabbitmq是由erlang语言开发,那么rabbitmq版本都会对应不同的erlang的版本:
版本对照参考:https://www.rabbitmq.com/which-erlang.html#compatibility-matrix
本文安装信息如下:
OS : centos 7.9
RabbitMQ : 3.11.13
ERLANG : 25.0.4
下载地址
RabbitMQ下载:https://www.rabbitmq.com/install-generic-unix.html
ERLANG下载:https://www.erlang.org/patches/otp-25.0.4
一)安装erlang
1.安装依赖环境
[root@localhost opt]# yum install -y ncurses-devel make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel unixODBC unixODBC-devel
2.解压安装包
[root@localhost opt]# tar -zxf otp_src_25.0.4.tar.gz
3.编译安装
[root@localhost opt]# cd otp_src_25.0.4
[root@localhost opt]# ./configure --prefix=/usr/local/erlang
出现报错:
configure: creating x86_64-pc-linux-gnu/config.status
config.status: creating config.mk
config.status: creating c_src/Makefile
configure: WARNING: No OpenGL headers found, wx will NOT be usable #确少OpenGL
configure: WARNING: No GLU headers found, wx will NOT be usable #缺少CLU
configure: WARNING:
wxWidgets must be installed on your system.
Please check that wx-config is in path, the directory
where wxWidgets libraries are installed (returned by
'wx-config --libs' or 'wx-config --static --libs' command)
is in LD_LIBRARY_PATH or equivalent variable and
wxWidgets version is 3.0.2 or above.
需要安装OpenGL
[root@localhost opt]# yum install -y mesa* --skip-broken #或者yum install mesa*
[root@localhost opt]# yum install -y freeglut*
继续编译安装erlang再次出现报错,缺少wxWidgets,安装wxWidgets
configure: WARNING:
wxWidgets must be installed on your system.
Please check that wx-config is in path, the directory
where wxWidgets libraries are installed (returned by
'wx-config --libs' or 'wx-config --static --libs' command)
is in LD_LIBRARY_PATH or equivalent variable and
wxWidgets version is 3.0.2 or above.
*********************************************************************
********************** APPLICATIONS INFORMATION *******************
*********************************************************************
wx : wxWidgets was not compiled with --enable-webview or wxWebView developer package is not installed, wxWebView will NOT be available
wxWidgets must be installed on your system.
Please check that wx-config is in path, the directory
where wxWidgets libraries are installed (returned by
'wx-config --libs' or 'wx-config --static --libs' command)
is in LD_LIBRARY_PATH or equivalent variable and
wxWidgets version is 3.0.2 or above.
erts :
JIT disabled due to lack of compiler with C++17 support
下载wxWidgets 地址:http://www.wxwidgets.org/downloads/
安装解压:
[root@localhost opt]# bzip2 -dkv wxWidgets-3.2.2.1.tar.bz2
[root@localhost opt]# tar -xvf wxWidgets-3.2.2.1.tar
编译安装:
[root@localhost opt]# cd wxWidgets-3.2.2.1
[root@localhost opt]# ./configure --with-opengl --enable-debug --enable-unicode
编译报错,缺少GTK,需要安装GTK
checking for GTK+ - version >= 3.0.0... no
*** Could not run GTK+ test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occurred. This usually means GTK+ is incorrectly installed.
checking for pkg-config... (cached) /usr/bin/pkg-config
checking pkg-config is at least version 0.7... yes
checking for GTK+ - version >= 2.6.0... no
*** Could not run GTK+ test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means GTK+ is incorrectly installed.
checking for pkg-config... /usr/bin/pkg-config
checking for GTK+ - version >= 3.90.0... no
*** Could not run GTK+ test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occurred. This usually means GTK+ is incorrectly installed.
checking for gtk-config... no
checking for GTK - version >= 1.2.7... no
*** The gtk-config script installed by GTK could not be found
*** If GTK was installed in PREFIX, make sure PREFIX/bin is in
*** your path, or set the GTK_CONFIG environment variable to the
*** full path to gtk-config.
checking for gtk-config... (cached) no
checking for GTK - version >= 1.2.3... no
*** The gtk-config script installed by GTK could not be found
*** If GTK was installed in PREFIX, make sure PREFIX/bin is in
*** your path, or set the GTK_CONFIG environment variable to the
*** full path to gtk-config.
configure: error:
The development files for GTK+ were not found. For GTK+ 2, please
ensure that pkg-config is in the path and that gtk+-2.0.pc is
installed. For GTK+ 1.2 please check that gtk-config is in the path,
and that the version is 1.2.3 or above. Also check that the
libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
--libs' are in the LD_LIBRARY_PATH or equivalent.
安装GTK
yum install *gtk*或 yum install *gtk* --skip-broken
[root@localhost wxWidgets-3.2.2.1]# yum install *gtk* --skip-broken
继续编译安装
[root@localhost opt]# ./configure --with-opengl --enable-debug --enable-unicode
[root@localhost opt]# make && make install
安装完成后,继续编译erlang
[root@localhost wxWidgets-3.2.2.1]# cd ../otp_src_25.0.4
[root@localhost otp_src_25.0.4]# ./configure --prefix=/usr/local/erlang
[root@localhost otp_src_25.0.4]# make && make install
设置环境变量
[root@localhost otp_src_25.0.4]# vim /etc/profile
增加如下信息:
export PATH=$PATH:/usr/local/erlang/bin
[root@localhost otp_src_25.0.4]# source /etc/profile
检测安装结果
[root@localhost otp_src_25.0.4]# erl
Erlang/OTP 25 [erts-13.0.4] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1]
二)系统配置
1.修改主界面
[root@localhost local]# echo "rabbitmq-03" > /etc/hostname
[root@localhost local]# hostnamectl set-hostname rabbitma-03
2.配置host(集群需要)
[root@rabbitmq-03 ~]# echo "192.168.3.103 rabbitmq-01" >> /etc/hosts
[root@rabbitmq-03 ~]# echo "192.168.3.105 rabbitmq-02" >> /etc/hosts
[root@rabbitmq-03 ~]# echo "192.168.3.106 rabbitmq-03" >> /etc/hosts
3.修改内核参数
[root@rabbitmq-03 ~]# vim /etc/security/limits.conf
* hard nproc 65535
* soft nproc 65535
* soft nofile 65536
* hard nofile 65536
[root@rabbitmq-03 limits.d]# vim /etc/security/limits.d/20-nproc.conf
* soft nproc 65535
root soft nproc unlimited
三)安装rabbitmq
1.解压rabbitmq
[root@localhost local]# xz -d rabbitmq-server-generic-unix-3.11.13.tar.xz
[root@localhost local]# tar xf rabbitmq-server-generic-unix-3.11.13.tar
[root@localhost local]# cd /usr/local/
[root@localhost local]# mv rabbitmq_server-3.11.13 rabbitmq_server
2.安装必要环境
[root@localhost local]# yum install xmlto -y
[root@localhost local]# yum install python-simplejson -y
3.配置环境变量
[root@localhost local]# vim /etc/profile
增加 : PATH=$PATH:/usr/local/rabbitmq_server/sbin
[root@localhost local]# source /etc/profile
如下已经安装好
[root@localhost local]# rabbitmq
rabbitmqctl rabbitmq-diagnostics rabbitmq-plugins rabbitmq-server rabbitmq-tanzu
rabbitmq-defaults rabbitmq-env rabbitmq-queues rabbitmq-streams rabbitmq-upgrade
4.创建目录,创建用户
[root@rabbitmq-03 rabbitmq]# useradd -u 1020 -s /sbin/nologin rabbitmq -m
[root@rabbitmq-03 rabbitmq]# mkdir -p /data/rabbitmq/{mnesia,logs}
[root@rabbitmq-03 rabbitmq]# chown -R rabbitmq.rabbitmq /data/rabbitmq
#[root@rabbitmq-03 rabbitmq]# chown -R rabbitmq.rabbitmq /usr/local/rabbitmq_server
5.修改配置
[root@rabbitmq-03 rabbitmq]# vim /usr/local/rabbitmq_server/etc/rabbitmq/rabbitmq-env.conf
RABBITMQ_NODENAME=rabbitmq-03
RABBITMQ_NODE_IP_ADDRESS=192.168.3.106
RABBITMQ_NODE_PORT=5672
MNESIA_BASE=/data/rabbitmq/mnesia
LOG_BASE=/data/rabbitmq/logs
[root@rabbitmq-03 rabbitmq]# vim /usr/local/rabbitmq_server/etc/rabbitmq/rabbitmq.conf
loopback_users = none
listeners.tcp.default = 5672
num_acceptors.tcp = 20
handshake_timeout = 10000
vm_memory_high_watermark.relative = 0.4
vm_memory_calculation_strategy = rss
vm_memory_high_watermark_paging_ratio = 0.5
disk_free_limit.absolute = 10GB
frame_max = 131072
initial_frame_max = 4096
channel_max = 2047
heartbeat = 60
default_vhost = /
log.dir = /data/rabbitmq/logs
log.file = rabbit.log
log.file.level = info
log.file.rotation.size = 52428800
log.file.rotation.count = 10
6.启动服务
[root@rabbitmq-03 rabbitmq]# su -s /bin/bash - rabbitmq
[rabbitmq@rabbitmq-03 ~]# rabbitmq-server -detached # 后台启动
[rabbitmq@rabbitmq-03 ~]$ rabbitmqctl status
Interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Interface: 192.168.3.106, port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
服务已经正常启动
安装web管理插件
[rabbitmq@rabbitmq-03 ~]$ /usr/local/rabbitmq_server/sbin/rabbitmq-plugins enable rabbitmq_management
[rabbitmq@rabbitmq-03 ~]$ rabbitmqctl status #查看服务状态
Listeners
Interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Interface: 192.168.3.106, port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
Interface: [::], port: 15672, protocol: http, purpose: HTTP API
到这里,rabbitmq服务已经安装完成,要搭建集群,可以追个安装其他几个节点。
四)部署镜像集群
我们选择rabbitmq-01做为集群第一个节点,rabbitmq-02,rabbitmq-03 加入到集群
1)降rabbitmq-01节点额.erlang.cookie的key负责到rabbit-02,rabbit-03两个节点
注意:修改文件后:需要重启erl进程,或者rabbitmq的进程/usr/local/erlang/lib/erlang/erts-13.0.4/bin/epmd -daemon
2)在集群其他mq-02,mq-03分别执行下面的操作:
[rabbitmq@rabbitmq-03 ~]$ rabbitmqctl stop_app
Stopping rabbit application on node rabbitmq-03@rabbitmq-03 ...
^[[A[rabbitmq@rabbitmq-03 ~]$ rabbitmqctl reset
Resetting node rabbitmq-03@rabbitmq-03 ...
[rabbitmq@rabbitmq-03 ~]$ rabbitmqctl join_cluster rabbitmq-01@rabbitmq-01
Clustering node rabbitmq-03@rabbitmq-03 with rabbitmq-01@rabbitmq-01
[rabbitmq@rabbitmq-03 ~]$ rabbitmqctl start_app
Starting node rabbitmq-03@rabbitmq-03 ...
[rabbitmq@rabbitmq-03 ~]$
3)在任意节点执行:rabbitmqctl cluster_status 查询搭建集群的状态是否成功
[rabbitmq@rabbitmq-01 ~]$ rabbitmqctl cluster_status
Cluster status of node rabbitmq-01@rabbitmq-01 ...
Basics
Cluster name: rabbitmq-01@rabbitmq-01
Total CPU cores available cluster-wide: 4
Disk Nodes
rabbitmq-01@rabbitmq-01
rabbitmq-02@rabbitmq-02
rabbitmq-03@rabbitmq-03
表示集群已经成功了,这里只是把集群搭建好,但是并不是镜像集群,镜像集群是基于集群模式进行策略设置
4)配置镜像集群
rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'
[rabbitmq@rabbitmq-01 ~]$ rabbitmqctl cluster_status
Cluster status of node rabbitmq-01@rabbitmq-01 ...
Basics
Cluster name: rabbitmq-01@rabbitmq-01
Total CPU cores available cluster-wide: 4
Disk Nodes
rabbitmq-01@rabbitmq-01
rabbitmq-02@rabbitmq-02
rabbitmq-03@rabbitmq-03
Running Nodes
rabbitmq-01@rabbitmq-01
rabbitmq-02@rabbitmq-02
rabbitmq-03@rabbitmq-03
Versions
rabbitmq-01@rabbitmq-01: RabbitMQ 3.11.13 on Erlang 25.0.4
rabbitmq-02@rabbitmq-02: RabbitMQ 3.11.13 on Erlang 25.0.4
rabbitmq-03@rabbitmq-03: RabbitMQ 3.11.13 on Erlang 25.0.4
CPU Cores
Node: rabbitmq-01@rabbitmq-01, available CPU cores: 2
Node: rabbitmq-02@rabbitmq-02, available CPU cores: 1
Node: rabbitmq-03@rabbitmq-03, available CPU cores: 1
每一个你不满意的现在,都有一个你不努力的曾经。