RabbitMQ服务主机名更改导致消息队列无法连接

时间:2023-03-08 16:39:25
RabbitMQ服务主机名更改导致消息队列无法连接

RabbitMQ服务主机名更改导致消息队列无法连接

在多节点环境中,RabbitMQ服务使用一个独立节点部署。在此环境下,如果修改了RabbitMQ节点的主机名,则需要更新RabbitMQ用户才能保证服务能够被正确访问。

RabbitMQ节点原主机名为:

root@Aloe-Express-20:/etc# cat /etc/hostname

Aloe-Express-20

root@Aloe-Express-20:/etc# cat /etc/hosts

127.0.0.1 localhost

127.0.1.1 Aloe-Express-20

172.16.112.81 CCnode

修改RabbitMQ节点主机名为:

root@Aloe-Express-22:/etc# cat /etc/hostname

Aloe-Express-22

root@Aloe-Express-22:/etc# cat /etc/hosts

127.0.0.1 localhost

127.0.1.1 Aloe-Express-22

172.16.112.81 CCnode

重启RabbitMQ节点后,发现nova服务无法连接rabbitMQ消息队列,日志抱错如下:

2016-03-29 10:34:39.477 1012 ERROR oslo_messaging._drivers.impl_rabbit [req-9beb2426-1c81-45d8-b340-1fbc7487e221 - - - - -] AMQP server ccnode:5672 closed the connection. Check login credentials: Socket closed

2016-03-29 10:34:44.492 1012 ERROR oslo_messaging._drivers.impl_rabbit [req-9beb2426-1c81-45d8-b340-1fbc7487e221 - - - - -] AMQP server ccnode:5672 closed the connection. Check login credentials: Socket closed

2016-03-29 10:34:49.508 1012 ERROR oslo_messaging._drivers.impl_rabbit [req-9beb2426-1c81-45d8-b340-1fbc7487e221 - - - - -] AMQP server ccnode:5672 closed the connection. Check login credentials: Socket closed

2016-03-29 10:34:54.523 1012 ERROR oslo_messaging._drivers.impl_rabbit [req-9beb2426-1c81-45d8-b340-1fbc7487e221 - - - - -] AMQP server ccnode:5672 closed the connection. Check login credentials: Socket closed

2016-03-29 10:34:59.539 1012 ERROR oslo_messaging._drivers.impl_rabbit [req-9beb2426-1c81-45d8-b340-1fbc7487e221 - - - - -] AMQP server ccnode:5672 closed the connection. Check login credentials: Socket closed

此错误是由于用户密码验证不通过造成。

于是回到RabbitMQ节点,查看RabbitMQ服务运行状态:

root@Aloe-Express-22:/etc/sahara# ps -ef | grep rabbit

rabbitmq  1939     1  0 10:20 ?        00:00:00 /usr/lib/erlang/erts-5.10.4/bin/epmd -daemon

rabbitmq  2065     1  0 10:20 ?        00:00:00 /bin/sh /usr/sbin/rabbitmq-server

rabbitmq  2079  2065  2 10:20 ?        00:00:11 /usr/lib/erlang/erts-5.10.4/bin/beam.smp -W w -K true -A30 -P 1048576 -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -pa /usr/lib/rabbitmq/lib/rabbitmq_server-3.4.3/sbin/../ebin -noshell -noinput -s rabbit boot -sname rabbit@Aloe-Express-22 -boot start_sasl -config /etc/rabbitmq/rabbitmq -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,"/var/log/rabbitmq/rabbit@Aloe-Express-22.log"} -rabbit sasl_error_logger {file,"/var/log/rabbitmq/rabbit@Aloe-Express-22-sasl.log"} -rabbit enabled_plugins_file "/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/lib/rabbitmq/lib/rabbitmq_server-3.4.3/sbin/../plugins" -rabbit plugins_expand_dir "/var/lib/rabbitmq/mnesia/rabbit@Aloe-Express-22-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/var/lib/rabbitmq/mnesia/rabbit@Aloe-Express-22" -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672

rabbitmq  2258  2079  0 10:20 ?        00:00:00 inet_gethost 4

rabbitmq  2259  2258  0 10:20 ?        00:00:00 inet_gethost 4

root     17356  4079  0 10:29 pts/3    00:00:00 grep --color=auto rabbit

服务正常运行,查看服务状态:

root@Aloe-Express-22:/etc/sahara# rabbitmqctl status

Status of node 'rabbit@Aloe-Express-22' ...

[{pid,2079},

{running_applications,

[{rabbitmq_management,"RabbitMQ Management Console","3.4.3"},

{rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.4.3"},

{webmachine,"webmachine","1.10.3-rmq3.4.3-gite9359c7"},

{mochiweb,"MochiMedia Web Server","2.7.0-rmq3.4.3-git680dba8"},

{rabbitmq_management_agent,"RabbitMQ Management Agent","3.4.3"},

{inets,"INETS  CXC 138 49","5.9.7"},

{amqp_client,"RabbitMQ AMQP Client","3.4.3"},

{rabbit,"RabbitMQ","3.4.3"},

{os_mon,"CPO  CXC 138 46","2.2.14"},

{mnesia,"MNESIA  CXC 138 12","4.11"},

{xmerl,"XML parser","1.3.5"},

{sasl,"SASL  CXC 138 11","2.3.4"},

{stdlib,"ERTS  CXC 138 10","1.19.4"},

{kernel,"ERTS  CXC 138 10","2.16.4"}]},

{os,{unix,linux}},

{erlang_version,

"Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:30] [kernel-poll:true]\n"},

{memory,

[{total,40659504},

{connection_readers,339200},

{connection_writers,0},

{connection_channels,0},

{connection_other,79720},

{queue_procs,2704},

{queue_slave_procs,0},

{plugins,354560},

{other_proc,13826296},

{mnesia,60648},

{mgmt_db,80400},

{msg_index,46784},

{other_ets,1057432},

{binary,29600},

{code,19580581},

{atom,703377},

{other_system,4498202}]},

{alarms,[]},

{listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},

{vm_memory_high_watermark,0.4},

{vm_memory_limit,3349220556},

{disk_free_limit,50000000},

{disk_free,154967289856},

{file_descriptors,

[{total_limit,924},{total_used,11},{sockets_limit,829},{sockets_used,9}]},

{processes,[{limit,1048576},{used,201}]},

{run_queue,0},

{uptime,567}]

服务均正常运行,查看服务运行的/var目录:

root@Aloe-Express-22:/etc/sahara# cd /var/lib/rabbitmq/

root@Aloe-Express-22:/var/lib/rabbitmq# ls

mnesia

root@Aloe-Express-22:/var/lib/rabbitmq# cd mnesia/

root@Aloe-Express-22:/var/lib/rabbitmq/mnesia# ls

rabbit@Aloe-Express-20  rabbit@Aloe-Express-20-plugins-expand  rabbit@Aloe-Express-22  rabbit@Aloe-Express-22-plugins-expand

由于修改了主机名,导致RabbitMQ消息队列出现更改,此更改会导致用户的变化,查看当前环境的用户:

root@Aloe-Express-22:/var/lib/rabbitmq/mnesia# rabbitmqctl list_users

Listing users ...

guest [administrator]

guest用户为RabbitMQ默认创建的一个用户,但guest用户的密码为随机密码。需重新设置密码:

root@Aloe-Express-22:/var/lib/rabbitmq/mnesia# rabbitmqctl change_password guest password

Changing password for user "guest" ...

guest用户密码修改以后,发现nova服务日志恢复正常:

2016-03-29 10:35:01.557 1012 INFO oslo_messaging._drivers.impl_rabbit [req-9beb2426-1c81-45d8-b340-1fbc7487e221 - - - - -] Reconnected to AMQP server on ccnode:5672

2016-03-29 10:35:01.558 1012 INFO oslo_messaging._drivers.impl_rabbit [req-9beb2426-1c81-45d8-b340-1fbc7487e221 - - - - -] Connected to AMQP server on ccnode:5672

结论

当修改RabbitMQ主机的主机名时,需重新进行用户名密码创建才能保证外部服务正常使用RabbitMQ服务。