【安装epel软件包库】
# yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # yum install -y epel-release
# 更新库 # yum update -y
【安装依赖包】
# yum install gcc glibc-devel make ncurses-devel openssl-devel xmlto -y
# rpm -qa|grep logrotate # rpm -qa|grep socat
# yum install socat logrotate -y
【安装erlang】
# erl -v -bash: erl: 未找到命令 [root@app-server1 rabbitmq]#?
# 下载或上传对应版本的rpm安装包: erlang-23.3.4.5-1.el7.x86_64.rpm
# 执行安装: # rpm -Uvh erlang-23.3.4.5-1.el7.x86_64.rpm # sudo yum install erlang -y
# 测试: erl -v [root@app-server1 rabbitmq]# erl -v Erlang/OTP 23 [erts-11.2.2.4] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]
Eshell V11.2.2.4 ?(abort with ^G) 1>?
Ctrl + c 退出
【安装rabbitmq】
1.下载或上传安装包:rabbitmq-server-3.8.21-1.el7.noarch.rpm
# 根据下载源确定是否需要密钥签名验证安装包安全性
# 执行安装: sudo yum install rabbitmq-server-3.8.21-1.el7.noarch.rpm -y
2.查看相关路径
# find / -name rabbitmq ?或者? # whereis rabbitmq /etc/selinux/targeted/active/modules/100/rabbitmq /etc/rabbitmq /var/lib/rabbitmq /var/log/rabbitmq /usr/lib/ocf/resource.d/rabbitmq /usr/lib/rabbitmq /usr/local/software/rabbitmq
# find / -name rabbitmq-server find / -name rabbitmq-server-version
# 3.8.x安装版本安装后位置
/usr/lib/rabbitmq/lib/rabbitmq_server-3.8.21/escript /usr/lib/rabbitmq/lib/rabbitmq_server-3.8.21/plugins /usr/lib/rabbitmq/lib/rabbitmq_server-3.8.21/sbin
【安装 - web管理插件】
# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@app-server1: rabbitmq_management The following plugins have been configured: ? rabbitmq_management ? rabbitmq_management_agent ? rabbitmq_web_dispatch Applying plugin configuration to rabbit@app-server1... The following plugins have been enabled: ? rabbitmq_management ? rabbitmq_management_agent ? rabbitmq_web_dispatch
set 3 plugins. Offline change; changes will take effect at broker restart. [root@app-server1 rabbitmq]#?
【安装 - 延迟队列插件】
插件地址: https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases 本次安装使用插件:rabbitmq_delayed_message_exchange-3.8.17.8f537ac.ez
# 下载或上传插件到插件目录:/usr/lib/rabbitmq/lib/rabbitmq_server-3.8.21/plugins # cd /usr/lib/rabbitmq/lib/rabbitmq_server-3.8.21/plugins # 授权文件权限:文件所有者、群组用户、其他用户需要"-rw-r--r--"权限
当前权限: -r--------. 1 root root ? 50926 8月 ?25 11:26 rabbitmq_delayed_message_exchange-3.8.17.8f537ac.ez
执行授权: sudo chmod 644 rabbitmq_delayed_message_exchange-3.8.17.8f537ac.ez 权限变为: -rw-r--r--. 1 root root ? 50926 8月 ?25 11:26 rabbitmq_delayed_message_exchange-3.8.17.8f537ac.ez
# chmod 授权命令数字含义: ? ? 英文字符? r ? ? w ? ? ?x ?十进制代表 4 ? ? 2 ? ? ?1
rwx=7=4+2+1 rw=6=4+2
# 启用激活延迟队列插件: # rabbitmq-plugins enable rabbitmq_delayed_message_exchange
Enabling plugins on node rabbit@app-server1: rabbitmq_delayed_message_exchange The following plugins have been configured: ? rabbitmq_delayed_message_exchange ? rabbitmq_management ? rabbitmq_management_agent ? rabbitmq_web_dispatch Applying plugin configuration to rabbit@app-server1... The following plugins have been enabled: ? rabbitmq_delayed_message_exchange
set 4 plugins. Offline change; changes will take effect at broker restart. [root@app-server1 plugins]#?
【配置rabbitmq】
配置参考:https://www.rabbitmq.com/install-rpm.html#configuration 配置参考:https://www.rabbitmq.com/configure.html
1.配置允许远程访问:guest -- User can only log in via localhost
# cd /usr/share/doc/rabbitmq-server-3.8.21
# 集群策略文件:set_rabbitmq_policy.sh.example vim /usr/share/doc/rabbitmq-server-3.8.21/set_rabbitmq_policy.sh.example
注意:
3.8.x版本及以后版本没有rabbitmq.config配置文件,想要解决guest用户远程访问问题,需要自己手动在/etc/rabbitmq/目录下创建rabbitmq.config文件, ? ? ?并添加[{rabbit, [{loopback_users, []}]}]相关配置,详见官方文档(https://www.rabbitmq.com/configure.html)
2.配置新用户
rabbitmqctl add_user admin admin123 rabbitmqctl set_permissions -p / admin ".*" ".*" ".*" rabbitmqctl set_user_tags admin administrator
【配置防火墙开放端口】
systemctl stop firewalld systemctl status firewalld systemctl restart firewalld
# 查看已经开放端口 # firewall-cmd --list-port # 检查端口 firewall-cmd --query-port=15672/tcp # 如果为no,则执行下述命令 firewall-cmd --zone=public --add-port=15672/tcp --permanent # 重新加载防火墙配置 firewall-cmd --reload
# 重启防火墙 systemctl restart firewalld
【根据需要配置连接符文件句柄数量】
# ulimit -a? ?-- 详见linux相关教程
【启动rabbitmq】 [root@app-server1 escript]# systemctl start rabbitmq-server
# 查看进程启动情况 [root@app-server1 escript]# ps -ef|grep rabbitmq|grep -v grep rabbitmq ?89153 ? ? ?1 20 13:36 ? ? ? ? ?00:00:11 /usr/lib64/erlang/erts-11.2.2.4/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/lib64/erlang -progname erl -- -home /var/lib/rabbitmq -- -pa ?-noshell -noinput -s rabbit boot -boot start_sasl -lager crash_log false -lager handlers [] rabbitmq ?89168 ?89153 ?0 13:36 ? ? ? ? ?00:00:00 erl_child_setup 32768 rabbitmq ?89245 ?89168 ?0 13:36 ? ? ? ? ?00:00:00 inet_gethost 4 rabbitmq ?89892 ?89245 ?0 13:37 ? ? ? ? ?00:00:00 inet_gethost 4 [root@app-server1 escript]#?
访问:http://10.31.192.11:15672/
guest/guest -- User can only log in via localhost admin/admin123
【常用命令】
# 当前窗口启动 rabbitmq rabbitmq-server
# 后台启动 rabbitmq rabbitmq-server -detached
# 停止 rabbitmq rabbitmqctl stop
# 查看所有队列 rabbitmqctl list_queues
# 查看所有虚拟主机 rabbitmqctl list_vhosts
# 在Erlang VM运行的情况下启动RabbitMQ应用 rabbitmqctl start_app? rabbitmqctl stop_app
# 查看节点状态 rabbitmqctl status
# 查看所有可用的插件 rabbitmq-plugins list
# 启用插件 rabbitmq-plugins enable <plugin-name>
# 停用插件 rabbitmq-plugins disable <plugin-name>
【rabbitmqctl - 命令 - 用户&权限管理】
# 添加用户 rabbitmqctl add_user username password
# 列出所有用户 rabbitmqctl list_users # 删除用户 rabbitmqctl delete_user username
# 清除用户权限 rabbitmqctl clear_permissions -p vhostpath username
# 列出用户权限 rabbitmqctl list_user_permissions username
# 修改密码 rabbitmqctl change_password username newpassword
# 设置用户权限 rabbitmqctl set_permissions -p vhostpath username ".*" ".*" ".*"
【rabbitmqctl - 命令 - 虚拟主机管理】
# 创建虚拟主机 rabbitmqctl add_vhost vhostpath
# 列出虚拟主机上的所有权限 rabbitmqctl list_permissions -p vhostpath
# 删除虚拟主机 rabbitmqctl delete_vhost vhost vhostpath
# 移除所有数据,要在 rabbitmqctl stop_app 之后使用 rabbitmqctl reset
rabbitmqctl set_permissions -p / guest ".*" ".*" ".*"
|