说明
- CentOS7离线安装RabbitMq
操作步骤
》撸一下官方
- 官方文档:https://www.rabbitmq.com/install-rpm.html#overview
- 来自 RabbitMQ 的零依赖 Erlang
-
官方的话:
Zero-dependency Erlang from RabbitMQ Zero dependency Erlang RPM package for running RabbitMQ can be installed from a direct download from GitHub, as well as Yum repositories on Cloudsmith.io and PackageCloud. As the name suggests, the package strips off some Erlang modules and dependencies that are not essential for running RabbitMQ.
-
这段话的意思就是:RabbitMQ官方提供了一个足够运行RabbitMQ所需依赖的Erlang的rpm包。nice~
-
》下载准备
- 下载RabbitMQ官方提供的零依赖Erlang包
-
下载地址:https://github.com/rabbitmq/erlang-rpm
-
大小:20M±
erlang-23.3.4.8-1.el7.x86_64.rpm
- 注意:CentOS7仅支持Erlang23,CentOS8支持Erlang24和Erlang23,下载的时候注意版本选择不要错。
- 注意:RabbitMQ从3.8.4开始支持Erlang23,RabbitMQ从3.8.16开始支持Erlang24,下载的时候注意版本选择不要错。
-
- 下载RabbitMQ包
-
下载地址:https://github.com/rabbitmq/rabbitmq-server
-
大小:15M±
rabbitmq-server-3.8.26-1.el7.noarch.rpm
- 注意:下载的时候看一下兼容性说明,比如我这个3.8.26版本就要求至少Erlang23.2,并且支持Erlang24。
-
- 下载Socat包
-
下载地址:http://rpmfind.net/linux/rpm2html/search.phpquery=socat
-
大小:300K±
socat-1.7.3.2-2.el7.x86_64.rpm
- 注意:下载Centos7版本对应的包,别下错。
- 这个包是RabbitMQ所依赖的包,必装。
-
》开始安装
-
将下载好的rpm包拷贝至你的CentOS7能访问的目录。
[admin@192 src]$ ll total 37284 -rw-r--r--. 1 501 games 20347704 Dec 19 16:35 erlang-23.3.4.8-1.el7.x86_64.rpm -rw-r--r--. 1 501 games 15855925 Dec 19 16:55 rabbitmq-server-3.8.26-1.el7.noarch.rpm -rw-r--r--. 1 501 games 296632 Dec 19 17:33 socat-1.7.3.2-2.el7.x86_64.rpm
-
安装
# 先安装Erlang [admin@192 src]$ sudo rpm -ivh erlang-23.3.4.8-1.el7.x86_64.rpm [sudo] password for admin: warning: erlang-23.3.4.8-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID cc4bbe5b: NOKEY Preparing... ################################# [100%] Updating / installing... 1:erlang-23.3.4.8-1.el7 ################################# [100%] # 直接安装RabbitMQ会报缺少socat依赖 [admin@192 src]$ sudo rpm -ivh rabbitmq-server-3.8.26-1.el7.noarch.rpm warning: rabbitmq-server-3.8.26-1.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 6026dfca: NOKEY error: Failed dependencies: socat is needed by rabbitmq-server-3.8.26-1.el7.noarch # 接下来安装socat [admin@192 src]$ sudo rpm -ivh socat-1.7.3.2-2.el7.x86_64.rpm [sudo] password for admin: Preparing... ################################# [100%] Updating / installing... 1:socat-1.7.3.2-2.el7 ################################# [100%] # 最后安装RabbitMQ [admin@192 src]$ sudo rpm -ivh rabbitmq-server-3.8.26-1.el7.noarch.rpm warning: rabbitmq-server-3.8.26-1.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 6026dfca: NOKEY Preparing... ################################# [100%] Updating / installing... 1:rabbitmq-server-3.8.26-1.el7 ################################# [100%]
-
启动
-
手动启动RabbitMQ报错
[admin@192 src]$ rabbitmq-server start Configuring logger redirection 19:06:14.045 [error] 19:06:14.048 [error] BOOT FAILED 19:06:14.048 [error] =========== 19:06:14.048 [error] ERROR: epmd error for host 192: badarg (unknown POSIX error) BOOT FAILED =========== ERROR: epmd error for host 192: badarg (unknown POSIX error) 19:06:14.048 [error]
-
该错误是本机hosts配置问题
[admin@192 src]$ cd /etc/ [admin@192 etc]$ sudo cp hostname hostname.default [admin@192 etc]$ sudo vi hostname # 删掉默认一行,改为自定义值,如下面一行 host001 [admin@192 etc]$ sudo cp hosts hosts.default [admin@192 etc]$ sudo vi hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 # 增加下面一行(注意:hostname与/etc/hostname中的值一致) 127.0.0.1 host001 # 修改完重启服务器 [admin@192 etc]$ sudo reboot
-
-
再次启动RabbitMQ
[admin@host001 ~]$ sudo rabbitmq-server start Configuring logger redirection ## ## RabbitMQ 3.8.26 ## ## ########## Copyright (c) 2007-2021 VMware, Inc. or its affiliates. ###### ## ########## Licensed under the MPL 2.0. Website: https://rabbitmq.com Erlang: 23.3.4.8 [emu] TLS Library: OpenSSL - OpenSSL 1.0.2k-fips 26 Jan 2017 Doc guides: https://rabbitmq.com/documentation.html Support: https://rabbitmq.com/contact.html Tutorials: https://rabbitmq.com/getstarted.html Monitoring: https://rabbitmq.com/monitoring.html Logs: /var/log/rabbitmq/rabbit@host001.log /var/log/rabbitmq/rabbit@host001_upgrade.log Config file(s): (none) Starting broker... completed with 0 plugins.
-
以后使用系统命令启动、停止、查看
# 查看状态 [admin@host001 ~]$ sudo service rabbitmq-server status Redirecting to /bin/systemctl status rabbitmq-server.service ● rabbitmq-server.service - RabbitMQ broker Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled) Active: inactive (dead) # 启动 [admin@host001 ~]$ sudo service rabbitmq-server start Redirecting to /bin/systemctl start rabbitmq-server.service # 查看状态 [admin@host001 ~]$ sudo service rabbitmq-server status Redirecting to /bin/systemctl status rabbitmq-server.service ● rabbitmq-server.service - RabbitMQ broker Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled) Active: active (running) since Sun 2021-12-19 19:32:48 CST; 4s ago Main PID: 2611 (beam.smp) Status: "Initialized" CGroup: /system.slice/rabbitmq-server.service ├─2611 /usr/lib64/erlang/erts-11.2.2.7/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -sbwt none -sbwtdcpu none -sbwtdio none -- -root /usr/li... ├─2626 erl_child_setup 32768 ├─2674 inet_gethost 4 └─2675 inet_gethost 4 Dec 19 19:32:47 host001 rabbitmq-server[2611]: TLS Library: OpenSSL - OpenSSL 1.0.2k-fips 26 Jan 2017 Dec 19 19:32:47 host001 rabbitmq-server[2611]: Doc guides: https://rabbitmq.com/documentation.html Dec 19 19:32:47 host001 rabbitmq-server[2611]: Support: https://rabbitmq.com/contact.html Dec 19 19:32:47 host001 rabbitmq-server[2611]: Tutorials: https://rabbitmq.com/getstarted.html Dec 19 19:32:47 host001 rabbitmq-server[2611]: Monitoring: https://rabbitmq.com/monitoring.html Dec 19 19:32:47 host001 rabbitmq-server[2611]: Logs: /var/log/rabbitmq/rabbit@host001.log Dec 19 19:32:47 host001 rabbitmq-server[2611]: /var/log/rabbitmq/rabbit@host001_upgrade.log Dec 19 19:32:47 host001 rabbitmq-server[2611]: Config file(s): (none) Dec 19 19:32:47 host001 rabbitmq-server[2611]: Starting broker... completed with 0 plugins. Dec 19 19:32:48 host001 systemd[1]: Started RabbitMQ broker. # 停止 [admin@host001 ~]$ sudo service rabbitmq-server stop Redirecting to /bin/systemctl stop rabbitmq-server.service
-
-
设置开启自启动
# 开启开机自启动 [admin@host001 ~]$ sudo systemctl enable rabbitmq-server Created symlink from /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service to /usr/lib/systemd/system/rabbitmq-server.service. # 关闭开机自启动 [admin@host001 ~]$ sudo systemctl disable rabbitmq-server Removed symlink /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service.
》关于配置
-
其他配置不多说了,具体参照官方文档
-
特别说明一下默认目录和文件
# 默认Debian和rpm包安装完${install_prefix}为空 Debian and RPM package installations use an empty ${install_prefix}. Name Location RABBITMQ_BASE (Not used - Windows only) # 配置文件 RABBITMQ_CONFIG_FILE ${install_prefix}/etc/rabbitmq/rabbitmq # 数据库目录(mnesia是Erlang内置数据库) RABBITMQ_MNESIA_BASE ${install_prefix}/var/lib/rabbitmq/mnesia RABBITMQ_MNESIA_DIR $RABBITMQ_MNESIA_BASE/$RABBITMQ_NODENAME # 日志目录 RABBITMQ_LOG_BASE ${install_prefix}/var/log/rabbitmq RABBITMQ_LOGS $RABBITMQ_LOG_BASE/$RABBITMQ_NODENAME.log # 插件目录 RABBITMQ_PLUGINS_DIR /usr/lib/rabbitmq/plugins:$RABBITMQ_HOME/plugins Note that /usr/lib/rabbitmq/plugins is used only when RabbitMQ is installed into the standard (default) location. RABBITMQ_PLUGINS_EXPAND_DIR $RABBITMQ_MNESIA_BASE/$RABBITMQ_NODENAME-plugins-expand # 开启的插件配置文件 RABBITMQ_ENABLED_PLUGINS_FILE ${install_prefix}/etc/rabbitmq/enabled_plugins RABBITMQ_PID_FILE $RABBITMQ_MNESIA_DIR.pid
- 具体参照官方文档:https://www.rabbitmq.com/relocate.html
》使用Management管理后台
-
官方文档:https://www.rabbitmq.com/management.html
-
Management管理后台是一个插件,默认未开启。开启插件:
[admin@host001 ~]$ sudo rabbitmq-plugins enable rabbitmq_management Enabling plugins on node rabbit@host001: rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch Applying plugin configuration to rabbit@host001... The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch started 3 plugins.
-
浏览器访问:http://ip:15672
- 默认内置用户:guest,密码:guest。但是直接访问会报域名权限问题,该账号默认只能本机访问。
-
添加一个用户,并赋予超管权限
# 添加用户:admin,密码:123456 [admin@host001 ~]$ sudo rabbitmqctl add_user admin 123456 Adding user "admin" ... Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more. # 赋予超管(administrator)权限 [admin@host001 ~]$ sudo rabbitmqctl set_user_tags admin administrator Setting tags for user "admin" to [administrator] ... [admin@host001 ~]$ sudo rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*" Setting permissions for user "admin" in vhost "/" ... # 配置好不用重启,直接生效
-
再次使用浏览器访问:http://ip:15672
- 使用admin账号登陆
》关于防火墙
- 如果配置完Management,浏览器访问不了,防火墙放行相关端口或关闭防火墙。
备注
- 该教程部分内容收集自网络,感谢原作者。
附录
- 无