当我配置完rabbitmq之后想添加一个用户并且设置为管理员时,遇到了一些问题
[root@localhost ~]# rabbitmqctl add_user zhouniy 123456
Error: 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 running
In 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 tools
DIAGNOSTICS
===========
attempted to contact: [rabbit@localhost]
rabbit@localhost:
* connected to epmd (port 4369) on localhost
* epmd reports: node 'rabbit' not running at all
no other nodes on localhost
* suggestion: start the node
Current node details:
* node name: 'rabbitmqcli-2204-rabbit@localhost'
* effective user's home directory: /var/lib/rabbitmq
* Erlang cookie hash: RfbZNbhvxscoJBPZS60saQ==
经过搜索分析,得出的结论是rabbitmqcli并没有启动,需要重新启动rabbitmq服务
# 首先查询进程
[root@localhost ~]# ps -ef | grep rabbitmq
rabbitmq 2160 1 0 15:19 ? 00:00:00 /usr/lib64/erlang/erts-11.2.2.10/bin/epmd -daemon
root 2252 2086 0 15:23 pts/0 00:00:00 grep --color=auto rabbitmq
# 杀掉mq进程
[root@localhost ~]# ps -ef | grep rabbitmq | grep -v grep | awk '{print $2}' | xargs kill -9
# 启动mq进程
[root@localhost ~]# rabbitmq-server -detached
# 查看mq进程是否启动
[root@localhost ~]# ps -ef | grep rabbitmq
rabbitmq 2316 1 45 15:23 ? 00:00:11 /usr/lib64/erlang/erts-11.2.2.10/bin/beam.smp -W w -K true -A 128 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -B i -- -root /usr/lib64/erlang -progname erl -- -home /var/lib/rabbitmq -- -pa -noshell -noinput -s rabbit boot -boot start_sasl -lager crash_log false -lager handlers [] -noshell -noinput
rabbitmq 2447 2316 0 15:23 ? 00:00:00 erl_child_setup 1024
rabbitmq 2482 1 0 15:23 ? 00:00:00 /usr/lib64/erlang/erts-11.2.2.10/bin/epmd -daemon
rabbitmq 2515 2447 0 15:23 ? 00:00:00 inet_gethost 4
rabbitmq 2516 2515 0 15:23 ? 00:00:00 inet_gethost 4
root 2577 2086 0 15:24 pts/0 00:00:00 grep --color=auto rabbitmq
# 启动rabbitmqcli
[root@localhost ~]# rabbitmqctl start_app
Starting node rabbit@localhost ...
# 查看rabbitmqcli状态
[root@localhost ~]# rabbitmqctl status
Status of node rabbit@localhost ...
Runtime
此时就可以使用下面的命令完成添加管理员的操作了
[root@localhost ~]# rabbitmqctl add_user zhaibozhou 123456
Adding user "zhaibozhou" ...
[root@localhost ~]# rabbitmqctl set_user_tags zhaibozhou administrator
Setting tags for user "zhaibozhou" to [administrator] ...
[root@localhost ~]# sudo rabbitmqctl set_permissions -p "/" zhaibozhou ".*" ".*" ".*"
Setting permissions for user "zhaibozhou" in vhost "/" ...
# 查看用户列表
[root@localhost ~]# rabbitmqctl list_users
Listing users ...
user tags
zhaibozhou [administrator]
admin [administrator]
guest [administrator]
问题解决了!