本文共 4952 字,大约阅读时间需要 16 分钟。
Linux软件包的安装方法有很多,RabbitMQ也不例外,这里记录一下强列推荐的安装方法!
首先进入(https://www.rabbitmq.com/download.html),选择合适你的操作系统的下载和安装指引,我这边是CentOS(请确保你的服务器能连上外网,否则请用离线安装方式):
进去后,我们根据说明,点进强列推荐的安装方式(即使用Package Cloud上的Yum库)的说明链接:
由于Package Cloud签发安装包时使用的是他们自己的GPG key,虽然2018他们开始做Key迁移,但还是建设大家先导一下Package Cloud的Key:
# rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
# rpm --import https://packagecloud.io/gpg.key
然后,因为RabbitMQ是由Erlang语言开发,RabbitMQ安装包也依赖于Erlang,所以我们先根据提示安装好Erlang相关的包:
# curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
然后再回过头来根据提示安装RabbitMQ:
# curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
当然,以后有新版本了,你还可以用下面的命令将RabbitMQ更新到最新版本(生产环境不要随便更新升级哦!!!):
# yum install rabbitmq-server.noarch
做完这些以后,安装工作可以说是完成了!是不是很快!但是,我们后面还得做一下基本配置的和验证的!
安装完后,我们设置RabbitMQ为开机启动:
# chkconfig rabbitmq-server on # systemctl enable rabbitmq-server.service
然后我们在 /etc/rabbitmq/ 目录下新增一个环境配置文件 rabbitmq-env.conf
# vim /etc/rabbitmq/rabbitmq-env.confNODENAME=rabbit@localhost
接着尝试启动RabbitMQ服务:
# systemctl start rabbitmq-server
最后查看一下RabbitMQ是否启动成功:
# rabbitmqctl statusError: unable to perform an operation on node 'rabbit@localhost'. Please see diagnostics information and suggestions below.Most common reasons for this are: * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues) * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server) * Target node is not runningIn addition to the diagnostics info below: * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more * Consult server logs on node rabbit@localhost * If target node is configured to use long node names, don't forget to use --longnames with CLI toolsDIAGNOSTICS===========attempted to contact: [rabbit@localhost]rabbit@localhost: * connected to epmd (port 4369) on localhost * epmd reports node 'rabbit' uses port 25672 for inter-node and CLI tool traffic * TCP connection succeeded but Erlang distribution failed * Node name (or hostname) mismatch: node "rabbit@mqserver" believes its node name is not "rabbit@mqserver" but something else. All nodes and CLI tools must refer to node "rabbit@mqserver" using the same name the node itself uses (see its logs to find out what it is)Current node details: * node name: 'rabbitmqcli-33080-rabbit@localhost' * effective user's home directory: /var/lib/rabbitmq * Erlang cookie hash: V4dlxLzzzHnrAyZ80UrlSg==
结果报错了!!!给出的可能原因的第一条是“Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)”,目标节点不可达!所谡的目标节点,就是我们在 /etc/rabbitmq/rabbitmq-env.conf 文件中配置的 rabbit@localhost ,进于步推测的原因是hostname解析问题,或防火墙问题!
我们先试将localhost这个主机名做一个host映射(映射的IP 192.168.0.108是我的,你要换成你自己的):
# echo 192.168.0.108 localhost >> /etc/hosts
完了后,重启一下RabbitMQ服务:
# systemctl restart rabbitmq-server
再次查看一下RabbitMQ服务的状态(竟然好了,果然是hostname解析的问题):
# rabbitmqctl statusStatus of node rabbit@localhost ...RuntimeOS PID: 33539OS: LinuxUptime (seconds): 23RabbitMQ version: 3.8.7Node name: rabbit@localhostErlang configuration: Erlang/OTP 23 [erts-11.0.3] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:64] [hipe]Erlang processes: 276 used, 1048576 limitScheduler run queue: 1Cluster heartbeat timeout (net_ticktime): 60PluginsEnabled plugin file: /etc/rabbitmq/enabled_pluginsEnabled plugins:Data directoryNode data directory: /var/lib/rabbitmq/mnesia/rabbit@localhostRaft data directory: /var/lib/rabbitmq/mnesia/rabbit@localhost/quorum/rabbit@localhostConfig filesLog file(s) * /var/log/rabbitmq/rabbit@localhost.log * /var/log/rabbitmq/rabbit@localhost_upgrade.logAlarms(none)MemoryTotal memory used: 0.0976 gbCalculation strategy: rssMemory high watermark setting: 0.4 of available memory, computed to: 0.7576 gbother_proc: 0.0295 gb (30.22 %)code: 0.0289 gb (29.62 %)reserved_unallocated: 0.0191 gb (19.61 %)other_system: 0.0126 gb (12.89 %)other_ets: 0.0029 gb (2.95 %)allocated_unused: 0.0023 gb (2.34 %)atom: 0.0013 gb (1.37 %)plugins: 0.0005 gb (0.47 %)metrics: 0.0002 gb (0.2 %)binary: 0.0002 gb (0.18 %)mnesia: 0.0001 gb (0.08 %)quorum_ets: 0.0 gb (0.05 %)msg_index: 0.0 gb (0.03 %)connection_channels: 0.0 gb (0.0 %)connection_other: 0.0 gb (0.0 %)connection_readers: 0.0 gb (0.0 %)connection_writers: 0.0 gb (0.0 %)mgmt_db: 0.0 gb (0.0 %)queue_procs: 0.0 gb (0.0 %)queue_slave_procs: 0.0 gb (0.0 %)quorum_queue_procs: 0.0 gb (0.0 %)File DescriptorsTotal: 2, limit: 32671Sockets: 0, limit: 29401Free Disk SpaceLow free disk space watermark: 0.05 gbFree disk space: 12.3948 gbTotalsConnection count: 0Queue count: 0Virtual host count: 1ListenersInterface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communicationInterface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
至此使用官方推荐方法初步安装RabbitMQ就算完成了!
转载地址:http://devbz.baihongyu.com/