操作步骤
1)部署RabbitMQ服务
ln -s /opt/rabbitmq_server-3.6.10/sbin/rabbitmq-server /etc/init.d/rabbitmq-server
ln -s /opt/rabbitmq_server-3.6.10/sbin/rabbitmq-env /etc/init.d/rabbitmq-env
cp /opt/rabbitmq_server-3.6.10/.erlang.cookie /root/
chmod +x /etc/init.d/rabbitmq-server
chkconfig --add rabbitmq-server
echo "LANG=zh_CN.UTF-8" > /etc/locale.conf
source /etc/locale.conf
echo "export PATH=$PATH:/opt/otp/bin:/opt/mysql/bin:/opt/rabbitmq_server-3.6.10/sbin" >> /etc/profile
source /etc/profile
2)配置用户名和密码
#!/bin/sh
service rabbitmq-server start
rabbitmq-plugins enable rabbitmq_management
rabbitmqctl add_user admin 123456
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
上面脚本运行只能执行到service rabbitmq-server start,然后就出现rabbitmq server启动的详细打印信息,无法执行下面的启动组件,以及创建用户密码赋予访问权限等操作
#!/bin/sh
rabbitmq-server -detached
sleep 120
rabbitmq-plugins enable rabbitmq_management
rabbitmqctl add_user root 123456
rabbitmqctl set_user_tags root administrator
rabbitmqctl set_permissions -p "/" root ".*" ".*" ".*"
修改后rabbitmq-server以后台方式启动,继续执行,但是需要睡眠一下,保证rabbitmq server 正常启动之后,进行其他的创建授权操作
问题记录
1)RabbitMQ:address (cannot connect to host/port)问题解决
场景
[root@taishan-atlas init.d]# service rabbitmq-server start
Failed to get D-Bus connection: Operation not permitted
ERROR: epmd error for host taishan-atlas: address (cannot connect to host/port)
解决方案
修改/etc/hosts,添加127.0.0.1 taishan-atlas
127.0.0.1 localhost
127.0.0.1 taishan-atlas
192.168.12.42 taishan-atlas
注意:这里的 127.0.0.1 taishan-atlas 192.168.12.42 taishan-atlas 对应的主机名前面的IP地址,一个是回环的IP地址,一个是设备真实的IP地址,如果真实IP地址没有配置正确,也会出现类似的问题:ERROR: epmd error for host taishan-atlas: address (cannot connect to host/port)
2)RabbitMQ erl: command not found解决方案
要求
系统环境:CentOS Linux release 7.7.1908 (Core),将RabbitMQ注册成开机服务程序
创建软连接 ln -s /opt/rabbitmq_server-3.6.10/sbin/rabbitmq-server /etc/init.d/rabbitmq-server
创建软连接 ln -s /opt/rabbitmq_server-3.6.10/sbin/rabbitmq-env /etc/init.d/rabbitmq-env
执行脚本 service rabbitmq-server start
提示出错:erl: command not found
解决方案
编辑/etc/init.d/rabbitmq-server脚本,NOTIFY_SOCKET注释之后添加rabbitmq的HOME目录和erlang的路径
# NOTIFY_SOCKET is needed here to prevent epmd from impersonating the
# success of our startup sequence to systemd.
export HOME=/opt/rabbitmq_server-3.6.10
export PATH=$PATH:/opt/otp/lib/erlang/bin
疑窦
已经将erlang的路径添加到/etc/profile文件中,并且已经执行source /etc/profile,但是service无法读取到该环境变量
释疑
1、/etc/profile或者/etc/security/limit.d这些文件中配置的环境变量仅对通过pam登录的用户生效,而systemd是不读这些配置的,所以这就造成登录到终端时查看环境变量和手动启动应用都一切正常,但是systemd无法正常启动应用
2、如果需要给systemd配置默认参数,全局的配置在/etc/systemd/system.conf和/etc/systemd/user.conf中。同时还会加载两个配置文件对应的目录中所有的.conf配置文件/etc/systemd/system.conf.d/.conf和/etc/systemd/user.conf.d/.conf,一般的服务单元使用system.conf即可。加载优先级system.conf最低,所以system.conf.d目录中的配置会覆盖system.conf的配置
3、目前我已知的是更改system.conf配置,需要重启系统才能生效,还没找到如何重新加载此配置
注意 erlexec: HOME must be set
说明没有设置HOME目录: export HOME=/opt/rabbitmq_server-3.6.10
3)RabbitMQ 无法正常停止问题未解决
问题
ERROR: node with name "rabbit" already running on "localhost"
[root@localhost init.d]# rabbitmqctl stop
Stopping and halting node rabbit@localhost
Error: unable to connect to node rabbit@localhost: nodedown
ERROR: node with name "rabbit" already running on "localhost"
//常用的rabbitmq的命令
service rabbitmq-server start
service rabbitmq-server stop
service rabbitmq-server status
service rabbitmq-server rotate-logs|
service rabbitmq-server restart
service rabbitmq-server condrestart
service rabbitmq-server try-restart
service rabbitmq-server reload
service rabbitmq-server force-reload
service rabbitmq-server -detached //后台启动(注意前面只有一个横杠)
ps -ef | grep rabbitmq 查看RabbitMQ进程
netstat -anplt | grep LISTEN rabbitmq默认监听端口15672/5672
然后kill -9 PID结束进程
目前只能通过找到PID,停掉进程
4)RabbitMQ:Erlang distribution failed解决方案
前言
系统版本:CentOS Linux release 7.7.1908 (Core)
通过rabbitmqctl add_user admin 12345指令,给rabbitmq添加用户提示出错:
[root@localhost perl]# rabbitmqctl add_user admin 12345
Error: unable to connect to node rabbit@localhost: nodedown
DIAGNOSTICS
===========
attempted to contact: [rabbit@localhost]
rabbit@localhost:
* connected to epmd (port 4369) on localhost
* epmd reports node 'rabbit' running on port 25672
* TCP connection succeeded but Erlang distribution failed
* Authentication failed (rejected by the remote node), please check the Erlang cookie
current node details:
- node name: 'rabbitmq-cli-49@localhost'
- home dir: /root
- cookie hash: BgvEr+lGkDjLTQzT85cpyw==
解决方案
1)搜索.erlang.cookie文件
[root@localhost mnesia]# find / -name *.cookie
/root/.erlang.cookie
/opt/rabbitmq_server-3.6.10/.erlang.cookie
2)覆盖掉/root/.erlang.cookie文件
cp /opt/rabbitmq_server-3.6.10/.erlang.cookie /root/
原因
RabbitMQ的.erlang.cookie和用户的cookie冲突了,需要用RabbitMQ的cookie去覆盖用户的cookie
5)RabbitMQ:Erlang distribution failed解决方案
场景
CentOS7.6启动RabbitMQ,登陆WEB网页,提示Config file /opt/rabbitmq_server-3.6.10/etc/rabbitmq/rabbitmq.config (not found)
解决
在windows平台找到安装目录,拷贝配置文件到对应的目录:
cd /opt/rabbitmq.config.example /opt/rabbitmq_server-3.6.10/etc/rabbitmq/rabbitmq.config
重启服务