logo头像
Snippet 博客主题

rabbitmq搭建

一.配置erlang环境

rabbitmq是用erlang语言编写的消息队列,Erlang([‘ə:læŋ])是一种通用的面向并发的编程语言.

Erlang的官方网站上下载erlang博主下载的是otp_src_21.0.tar.gz版本点击下载即可.

下载完成后把文件解压出来进入文件夹编译安装erlang

1
2
3
[root@localhost otp_src_21.0]# chmod +x configure          #授权configure文件
[root@localhost otp_src_21.0]# configure --prefix=/usr/local/erlang #执行configure并指定安装目录
[root@localhost otp_src_21.0]# make && make install #编译与安装

如果没有报错,然后再去指定的安装文件夹下看到了bin和lib文件夹,那么就安装完成了.

然后配置环境变量在/etc/profile文件夹下加入

export ERL_HOME=/usr/local/erlang

export PATH=:$ERL_HOME/bin

加入好环境变量之后执行erl命令如果进入erl命令行就说明erlang完成搭建了

1
2
3
4
5
[lzq996298643@localhost ~]$ erl
Erlang/OTP 21 [erts-10.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Eshell V10.0 (abort with ^G)
1>

二. 编译安装rabbitmq

二.一 下载rabbitmq源代码包

RabbitMQ官方网站可以找到下载的源代码地址

博主下载的是3.7.7的版本的RabbitMQ下载地址这里可以下载源代码也可以下载rpm包和window下的exe软件安装包.

本宝宝下载的是源代码包,下载完成后解压软件包,然后进入解压的文件夹,打开Makefile文件,找到RMQ_ERLAPP_DIR这一段然后修改成要编译的地址

我修改到了/usr/local文件夹下

RMQ_ERLAPP_DIR ?= /usr/local/rabbitmq_server

修改完后执行make && make install

1
2
3
make[2]: elixir:命令未找到
GEN escript/rabbitmqctl
/bin/sh:行1: mix: 未找到命令

但是报了上面的错误了,是因为elixir没有安装

二.二 elixir的安装

Elixir 是一个基于 Erlang 虚拟机的函数式、面向并行的通用编程语言。Elixir 以 Erlang 为基础,支持分布式、高容错、实时应用程序的开发,同时亦对其进行扩展使之借助宏实现元编程,并通过协议支持多态。

首先现将elixir项目在github上面克隆下来git clone https://github.com/elixir-lang/elixir.git

1
[lzq996298643@localhost 开源代码]$ git clone https://github.com/elixir-lang/elixir.git

进入elixir文件夹,然后直接make clean test,make install,执行make test可能会有错误(去谷歌搜索可以找到答案).

1
2
[lzq996298643@localhost elixir]$ make clean test
[lzq996298643@localhost elixir]$ make install

安装完exlixir在去make安装rabbitemq报了下面的错误,意思就是只支持exlixir1.6.0版本的

(Mix) You’re trying to run :rabbitmqctl on Elixir v1.8.0-dev but it has declared in its mix.exs file it supports only Elixir ~> 1.6.0

git branch -a 查看有什么其它版本,然后替换为1.6.0的版本.再重新make安装exlixir

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[lzq996298643@localhost elixir]$ git branch -a                  #查看项目版本有多少
* master
remotes/origin/HEAD -> origin/master
remotes/origin/emj/deps-paths-level
remotes/origin/jv-no-19
remotes/origin/master
remotes/origin/mm/compiler-warnings-errors
remotes/origin/mm/records
remotes/origin/v1.0
remotes/origin/v1.1
remotes/origin/v1.2
remotes/origin/v1.3
remotes/origin/v1.4
remotes/origin/v1.5
remotes/origin/v1.6
remotes/origin/v1.7



[lzq996298643@localhost elixir]$ git checkout origin/v1.6 #替换为1.6版本
Note: checking out 'origin/v1.6'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

HEAD 目前位于 b6d27b5... Ignore unknown child info in Logger.Translator (#7892)
[lzq996298643@localhost elixir]$ cat VERSION #查看版本
1.6.6
[lzq996298643@localhost elixir]$ make clean test
[lzq996298643@localhost elixir]$ make install

结束了elixir的安装到rabbitmq源代码源文件夹下直接make && make install

1
[root@localhost rabbitmq]# make && make install
二.三 启动rabbitmq和安装web管理界面

创建/etc/rabbitmq目录,这个必须要创建且不能修改

然后到rabbitmq安装目录下sbin执行rabbitmq-plugins enable rabbitmq_management

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost sbin]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@localhost...
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.

然后新建/etc/rabbitmq/rabbitmq-env.conf文件添加以下内容

RABBITMQ_LOG_BASE=/data/rabbitmq/logs #日志存放地址
RABBITMQ_MNESIA_BASE=/data/rabbitmq/mnesia #mnesia数据库地址

配置完成后到安装目录sbin目录下启动rabbitmq服务

1
2
3
[root@localhost sbin]# ./rabbitmq-server -detached
WARNING: Removing trailing slash from RABBITMQ_LOG_BASE
Warning: PID file not written; -detached was passed.

rabbitemq默认服务端口是5672,http界面默认的端口是15672

1
2
3
[root@localhost rabbitmq]# lsof -i:5672
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
beam.smp 12831 root 69u IPv6 129168 0t0 TCP *:amqp (LISTEN)

执行上面命令如果有东西,说明服务已经启动了.

打开 http://localhost:15672/ 地址
image

默认帐号密码都是guest,登录进入.

image

微信打赏