当前位置:首页 > 服务端 > RabbitMQ 安装及服务化

RabbitMQ 安装及服务化

2022年09月17日 09:08:09服务端8

一、RabbitMQ运行需要的基础环境,Erlang安装

1.从官网(http://erlang.org/download/)下载安装包,示例版本:otp_src_21.3.tar.gz

2.解压otp_src_21.3.tar.gz

tar -zvxf opt_src_21.3.tar.gz

3.配置

./configure
或者

./configure --prefix=/usr/local/erlang

4.编译

make install
或
make && make install

5.环境变量配置

vi /etc/profile

在文件末尾加一行

PATH=$PATH:/usr/local/erlang/bin

保存文件并退出:

Esc
:wq

执行指令,使文件生效

source /etc/profile

6.验证安装是否成功

[root@localhost ~]# erl
Erlang/OTP 21 [erts-10.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Eshell V10.3  (abort with ^G)
1> exit
1> quit
1> halt()
1> halt().
* 2: syntax error before: quit
1> halt()。
* 1: illegal character
1> halt().
[root@localhost ~]# erl
Erlang/OTP 21 [erts-10.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Eshell V10.3  (abort with ^G)
1> ssl:versions().
[{ssl_app,"9.2"},
 {supported,['tlsv1.2','tlsv1.1',tlsv1]},
 {supported_dtls,['dtlsv1.2',dtlsv1]},
 {available,['tlsv1.2','tlsv1.1',tlsv1,sslv3]},
 {available_dtls,['dtlsv1.2',dtlsv1]}]
2> halt().
[root@localhost ~]#

至此,Erlang安装成功。

注意:Erlang运行还需要以下基础环境

yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel

二、RabbitMQ安装

1.从官网(https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.15/)下载安装包,示例版本:rabbitmq-server-generic-unix-3.7.10.tar.xz

2.解压rabbitmq-server-generic-unix-3.7.10.tar.xz

xz -d rabbitmq-server-generic-unix-3.7.10.tar.xz
tar -xvf rabbitmq-server-generic-unix-3.7.10.tar
或者
tar xvjf rabbitmq-server-generic-unix-3.7.10..tar.xz

3.配置环境变量

vi /etc/profile
在文件末尾添加一行:
#set rabbitmq enviroment
PATH=$PATH:/usr/local/rabbitmq_server-3.6.15/sbin

Esc
:wq

4.启动RabbitMQ

[root@localhost rabbitmq_server-3.7.10]# ./sbin/rabbitmq-server

  ##  ##  
  ##  ##      RabbitMQ 3.7.10. Copyright (C) 2007-2018 Pivotal Software, Inc.
  ##########  Licensed under the MPL.  See http://www.rabbitmq.com/
  ######  ##
  ##########  Logs: /home/h4kit/tools/rabbitmq_server-3.7.10/var/log/rabbitmq/rabbit@localhost.log
                    /home/h4kit/tools/rabbitmq_server-3.7.10/var/log/rabbitmq/rabbit@localhost_upgrade.log

              Starting broker...
 completed with 5 plugins.

5.启动RabbitMQ管理后台

[root@localhost rabbitmq_server-3.7.10]# ./sbin/rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@localhost:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_delayed_message_exchange
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_mqtt
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@localhost...
Plugin configuration unchanged.
[root@localhost rabbitmq_server-3.7.10]#

6.后台启动rabbitmq

[root@localhost rabbitmq_server-3.7.10]# ./sbin/rabbitmq-server -detach

  ##  ##
  ##  ##      RabbitMQ 3.7.10. Copyright (C) 2007-2018 Pivotal Software, Inc.
  ##########  Licensed under the MPL.  See http://www.rabbitmq.com/
  ######  ##
  ##########  Logs: /home/h4kit/tools/rabbitmq_server-3.7.10/var/log/rabbitmq/rabbit@localhost.log
                    /home/h4kit/tools/rabbitmq_server-3.7.10/var/log/rabbitmq/rabbit@localhost_upgrade.log

              Starting broker...
 completed with 5 plugins.

7.访问管理后台

http://127.0.0.1:15672/

RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

 

 

 至此,RabbitMQ安装完成。但是需要注意的是RabbitMQ默认账号密码为guest/guest,只能本机访问。所以需要创建一个远程访问的用户,并设置管理员权限。具体如下:

添加用户:
rabbitmqctl add_user test test
添加权限:
rabbitmqctl set_permissions -p "/" test ".*" ".*" ".*"
修改用户角色:
rabbitmqctl set_user_tags test administrator

三、RabbitMQ常用命令行

1.启动方式
rabbitmq-server -detached 后台启动
rabbitmq-server          直接启动
2.服务管理
rabbitmq-service install 安装服务
rabbitmq-service start  开始服务
rabbitmq-service stop  停止服务
rabbitmq-service enable 使服务有效
rabbitmq-service disable 使服务无效
rabbitmq-service help   帮助
3.关闭
rabbitmqctl stop
4.rabbitmq管理插件启用
rabbitmq-plugins enable rabbitmq_management 启用后台管理插件可视化界面
rabbitmq-plugins disable rabbitmq_management 关闭后台管理插件可视化界面
5.查看服务状态
rabbitmqctl status
[root@localhost rabbitmq_server-3.7.10]# ./sbin/rabbitmqctl status
Status of node rabbit@localhost ...
[{pid,3800},
 {running_applications,
     [{rabbitmq_management,"RabbitMQ Management Console","3.7.10"},
      {rabbitmq_management_agent,"RabbitMQ Management Agent","3.7.10"},
      {rabbitmq_delayed_message_exchange,"RabbitMQ Delayed Message Exchange",
          "3.8.0"},
      {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.7.10"},
      {rabbitmq_mqtt,"RabbitMQ MQTT Adapter","3.7.10"},
      {rabbit,"RabbitMQ","3.7.10"},
      {os_mon,"CPO  CXC 138 46","2.4.7"},
      {amqp_client,"RabbitMQ AMQP Client","3.7.10"},
      {rabbit_common,
          "Modules shared by rabbitmq-server and rabbitmq-erlang-client",
          "3.7.10"},
      {xmerl,"XML parser","1.3.19"},
      {cowboy,"Small, fast, modern HTTP server.","2.6.1"},
      {ranch,"Socket acceptor pool for TCP protocols.","1.7.1"},
      {ssl,"Erlang/OTP SSL application","9.2"},
      {public_key,"Public key infrastructure","1.6.5"},
      {asn1,"The Erlang ASN1 compiler version 5.0.8","5.0.8"},
      {mnesia,"MNESIA  CXC 138 12","4.15.6"},
      {jsx,"a streaming, evented json parsing toolkit","2.9.0"},
      {cowlib,"Support library for manipulating Web protocols.","2.7.0"},
      {crypto,"CRYPTO","4.4.1"},
      {inets,"INETS  CXC 138 49","7.0.6"},
      {recon,"Diagnostic tools for production use","2.3.6"},
      {lager,"Erlang logging framework","3.6.5"},
      {goldrush,"Erlang event stream processor","0.1.9"},
      {compiler,"ERTS  CXC 138 10","7.3.2"},
      {syntax_tools,"Syntax tools","2.1.7"},
      {sasl,"SASL  CXC 138 11","3.3"},
      {stdlib,"ERTS  CXC 138 10","3.8"},
      {kernel,"ERTS  CXC 138 10","6.3"}]},
 {os,{unix,linux}},
 {erlang_version,
     "Erlang/OTP 21 [erts-10.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:64] [hipe]\n"},
 {memory,
     [{connection_readers,42644},
      {connection_writers,1452},
      {connection_channels,5076},
      {connection_other,74756},
      {queue_procs,881148},
      {queue_slave_procs,0},
      {plugins,1720784},
      {other_proc,22698808},
      {metrics,237748},
      {mgmt_db,259672},
      {mnesia,130264},
      {other_ets,2980584},
      {binary,153832},
      {msg_index,62944},
      {code,23731442},
      {atom,1172689},
      {other_system,11885549},
      {allocated_unused,12399008},
      {reserved_unallocated,446464},
      {strategy,rss},
      {total,[{erlang,66039392},{rss,78884864},{allocated,78438400}]}]},
 {alarms,[]},
 {listeners,
     [{clustering,25672,"::"},
      {amqp,5672,"::"},
      {mqtt,1883,"::"},
      {http,15672,"::"}]},
 {vm_memory_calculation_strategy,rss},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,11712584089},
 {disk_free_limit,50000000},
 {disk_free,927859998720},
 {file_descriptors,
     [{total_limit,924},{total_used,12},{sockets_limit,829},{sockets_used,0}]},
 {processes,[{limit,1048576},{used,449}]},
 {run_queue,1},
 {uptime,1540},
 {kernel,{net_ticktime,60}}]
[root@localhost rabbitmq_server-3.7.10]#

四、常见问题总结

问题一:启动rabbitMQ报错,具体如下

./rabbitmq-server: line 80: erl: command not found

原因:ErlangRabbitMQ环境变量没有配置

 

问题二:启动rabbitMQ报错

Error description : noproc

原因:rabbitmqerlang版本不一致,前往rabbitMQ官网查找应下载版本

 

问题三:本地访问成功,其他主机访问失败

原因:rabbitmq的管理端口15672,防火墙端口未开放

解决过程:

1. 检查防火墙是否启用

systemctl status firewalld

RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

 

 

 2检查端口15672是否开放

firewall-cmd --query-port=15672/tcp

RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

 3.  开放15672端口

 

firewall-cmd --permanent --add-port=80/tcp

 

 RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

 

 

 4. 重启防火墙

firewall-cmd --reload

RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

 

 

 5.  查看端口15672是否开放

 

firewall-cmd --query-port=8080/tcp

RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

 

 

 

问题四:

 RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

原因:系统默认的HOME/root,可能造成erlang语言环境获取不到HOME参数。

查看一个erl进程:ps aux | grep beam

 RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

可以看出-home参数实在启动的时候加载进去的,启动一个erl实例。

解决:

 RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

问题五:

 RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

原因:erlang环境加载不到

解决:在rabbitmq-server文件中加入

ERLANG_HOME=/usr/local/lib/erlang/erts-10.3/bin

PATH=$PATH:$ERLANG_HOME

 

问题六:

RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

原因:erlang环境加载不到

解决:在rabbitmqctl文件中加入

ERLANG_HOME=/usr/local/lib/erlang/erts-10.3/bin

PATH=$PATH:$ERLANG_HOME

五、系统服务

方式一、service服务

1.创建自动启动脚本

vi /etc/init.d/rabbitmq
#
# chkconfig: 2345 90 10
# description: start the RabbitMQ
#
 
#脚本名称
prog=rabbitmq
export HOME=/home/h4kit/tools/rabbitmq_server-3.7.10
PATH=$PATH:$HOME/sbin
#RabbitMQ安装目录
RABBITMQ_HOME=/home/h4kit/tools/rabbitmq_server-3.7.10/sbin
export RABBITMQ_HOME
case "$1" in
    start)
    echo "Starting RabbitMQ ..."
    $RABBITMQ_HOME/rabbitmq-server start
    ;;
 
 
stop)
    echo "Stopping RabbitMQ ..."
    $RABBITMQ_HOME/rabbitmqctl stop
    ;;
 
 
restart)
    echo "no restart command"
    ;;
 
 
*)
    echo "Usage: $prog {start|stop|restart}"
    ;;
esac
exit 0

2.修改脚本为可执行文件

chmod a+x rabbitmq

3.查看rabbitmq开机启动情况

chkconfig --list

RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

 

4.没有rabbitmq,则添加到系统启动队列中

chkconfig --add rabbitmq

5.查看rabbitmq开机启动情况

chkconfig --list

RabbitMQ 安装及服务化 _ JavaClub全栈架构师技术笔记

方式二、systemctl服务

1. 进入系统服务目录

cd /usr/lib/systemd/system

2. 创建文件rabbitmq.service

3. 编辑rabbitmq.service

vi rabbitmq.service

[Unit]

Description=rabbitmq

 

[Service]

#Type=forking

User=root

Group=root

KillMode=/home/h4kit/tools/rabbitmq_server-3.7.10/sbin/rabbitmqctl stop

PIDFile=/home/h4kit/tools/rabbitmq_server-3.7.10/rabbitmq.pid

Restart=no

ExecStart=/home/h4kit/tools/rabbitmq_server-3.7.10/sbin/rabbitmq-server start

PrivateTmp=true

 

[Install]   

WantedBy=multi-user.target

4. 重新加载systemd程序的配置文件保存文件Esc :wq

systemctl start rabbitmq.service

5. 查看rabbitmq是否已启动

方式一:

ps -ef|grep rabbitmq  

[root@localhost ~]# ps -ef|grep rabbitmq

root       724     1  0 10:07 ?        00:00:00 /bin/sh /home/h4kit/tools/rabbitmq_server-3.7.10/sbin/rabbitmq-server start

root      1423   724  0 10:08 ?        00:00:05 /usr/local/lib/erlang/erts-10.3/bin/beam.smp -W w -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -B i -- -root /usr/local/lib/erlang -progname erl -- -home /root -- -pa /home/h4kit/tools/rabbitmq_server-3.7.10/ebin  -noshell -noinput -s rabbit boot -sname rabbit@localhost -boot start_sasl -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit lager_log_root "/home/h4kit/tools/rabbitmq_server-3.7.10/var/log/rabbitmq" -rabbit lager_default_file "/home/h4kit/tools/rabbitmq_server-3.7.10/var/log/rabbitmq/rabbit@localhost.log" -rabbit lager_upgrade_file "/home/h4kit/tools/rabbitmq_server-3.7.10/var/log/rabbitmq/rabbit@localhost_upgrade.log" -rabbit enabled_plugins_file "/home/h4kit/tools/rabbitmq_server-3.7.10/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/home/h4kit/tools/rabbitmq_server-3.7.10/plugins" -rabbit plugins_expand_dir "/home/h4kit/tools/rabbitmq_server-3.7.10/var/lib/rabbitmq/mnesia/rabbit@localhost-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/home/h4kit/tools/rabbitmq_server-3.7.10/var/lib/rabbitmq/mnesia/rabbit@localhost" -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672 start

root      4171  3929  0 10:19 pts/0    00:00:00 grep --color=auto rabbitmq

[root@localhost ~]#

方式二: 

systemctl status rabbitmq.service

[root@localhost ~]# systemctl status rabbitmq.service

 rabbitmq.service - rabbitmq

   Loaded: loaded (/usr/lib/systemd/system/rabbitmq.service; enabled; vendor preset: disabled)

   Active: active (running) since 一 2020-12-21 10:07:52 CST; 13min ago

 Main PID: 724 (rabbitmq-server)

   CGroup: /system.slice/rabbitmq.service

           ├─ 724 /bin/sh /home/h4kit/tools/rabbitmq_server-3.7.10/sbin/rabbitmq-server start

           ├─1288 /usr/local/lib/erlang/erts-10.3/bin/epmd -daemon

           ├─1423 /usr/local/lib/erlang/erts-10.3/bin/beam.smp -W w -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -B i -- -r...

           ├─1658 erl_child_setup 1024

           ├─3216 inet_gethost 4

           └─3217 inet_gethost 4

 

12月 21 10:07:52 localhost.localdomain systemd[1]: Started rabbitmq.

12月 21 10:08:07 localhost.localdomain rabbitmq-server[724]: ##  ##

12月 21 10:08:07 localhost.localdomain rabbitmq-server[724]: ##  ##      RabbitMQ 3.7.10. Copyright (C) 2007-2018 Pivotal Software, Inc.

12月 21 10:08:07 localhost.localdomain rabbitmq-server[724]: ##########  Licensed under the MPL.  See http://www.rabbitmq.com/

12月 21 10:08:07 localhost.localdomain rabbitmq-server[724]: ######  ##

12月 21 10:08:07 localhost.localdomain rabbitmq-server[724]: ##########  Logs: /home/h4kit/tools/rabbitmq_server-3.7.10/var/log/rabbitmq/rabbit@localhost.log

12月 21 10:08:07 localhost.localdomain rabbitmq-server[724]: /home/h4kit/tools/rabbitmq_server-3.7.10/var/log/rabbitmq/rabbit@localhost_upgrade.log

12月 21 10:08:07 localhost.localdomain rabbitmq-server[724]: Starting broker...

12月 21 10:08:09 localhost.localdomain rabbitmq-server[724]: completed with 5 plugins.

[root@localhost ~]#

6. 设置开机自启

systemctl enable rabbitmq

7. 服务器重启

systemctl reboot

8. 查看rabbitmq是否已启动,同5

1. 创建自动启动脚本

vi /etc/init.d/rabbitmq

2. 跳转目录

cd /etc/init.d

3. 修改脚本为可执行文件

chmod a+x rabbitmq

4. 查看rabbitmq开机启动情况

chkconfig --list

 

5. 没有rabbitmq,则添加到系统启动队列中

chkconfig --add rabbitmq

6. 查看rabbitmq开机启动情况

chkconfig --list

作者:若水0617
来源链接:https://www.cnblogs.com/babylove/p/14168234.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。


本文链接:https://www.javaclub.cn/server/42460.html

分享给朋友:

“RabbitMQ 安装及服务化” 的相关文章

MQ--01为什么要选择RabbitMQ ,RabbitMQ简介,各种MQ选型对比

MQ--01为什么要选择RabbitMQ ,RabbitMQ简介,各种MQ选型对比

MQ 是什么?队列是什么,MQ 我们可以理解为消息队列,队列我们可以理解为管道。以管道的方式做消息传递。 场景:     1.其实我们在双11的时候,当我们凌晨大量的秒杀和抢购商品,然后去结算的时候,就会发现,界面会提...

RabbitMQ配置SSL

RabbitMQ配置SSL

引言 主要介绍了如何通过Docker安装RabbitMQ并配置SSL;配置成功之后给出了SpringBoot和Python集成的例子。 生成证书 $ git clone https://github.com/Berico-Technol...

centos7 yum安装rabbitmq-server

centos7 yum安装rabbitmq-server

一、查看支持rabbitmq-server的软件包并安装 yum provides rabbitmq-server yum install rabbitmq-server yum安装时安装了其他依赖 二、启动rabbitmq-server...

RabbitMQ理解

RabbitMQ理解

RabbitMQ 1.什么是MQ MQ:(Message Queue)消息队列 对列:(Queue)简单的说 就是一种数据结构 先进先出 (Redis list) 消息队列:简单的说就是用来进行消息传输的 消...

RabbitMQ详解(一)

RabbitMQ详解(一)

一、消息队列相关概念 二、安装rabbitmq 三、配置rabbitmq 四、运行时参数配置 五、rabbitmq集群 一、消息队列相关概念 消息中间件: AMQP:高级消息队列协议  MQ是消费...

Win10上RabbitMQ的安装

Win10上RabbitMQ的安装

Win10上RabbitMQ的安装 1.下载安装Erlang(前提) 1.1 下载并安装 1.2 设置系统变量 2.下载安装RabbitMQ...

Web模式使用RabbitMQ

Web模式使用RabbitMQ

启动rabbitmq服务后,登陆网址:http://localhost:15672 ▎添加队列 ▎模拟生产者生产消息 1、进入交换机tab,点击默认交换机(AMQP default)进入...

Rabbitmq启动报错: Job for rabbitmq-server.service failed because the control process exited with error c

Rabbitmq启动报错: Job for rabbitmq-server.service failed because the control process exited with error c

Rabbitmq启动报错: Job for rabbitmq-server.service failed because the control process exited with error code Rabbi...

RabbitMQ的消息预取机制

rabbitMQ内部有消息预取机制,比如有两个消费队列,共同去消费50条消息,即便这两台机器有差异,也会因为消息预取机制,每台机器去抢25条消息,从而影响整体效率。 要解决可以在配置中限制消息预取的数量,原来默认是没有上限,现在可以限制为1,即每次处理完当前的消息之...

RabbitMQ入门3:RabbitMQ管理后台,简介;

RabbitMQ入门3:RabbitMQ管理后台,简介;

说明: (1)本篇博客的内容:简单介绍RabbitMQ的管理后台; 目录 1.使用【rabbitmq-plugins enable rabbitmq_management】,启动RabbitMQ的管理后台; 2.使用【rabbitmqc...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。