Rabbitmq安装和使用

前言

系统:centOS final6.5
文件的下载目录: /home/work/rabbitmq
安装目录: /home/work/
在我的每一步代码中都带有当前目录,切换目录我也会说明。

安装Erlang

1.下载最新版本的erlang到文件夹opt中,当前版本是20.0

[work@busi-cmdmq01 rabbitmq]$ wget http://erlang.org/download/otp_src_20.0.tar.gz

2.下载完成后查看文件

[work@busi-cmdmq01 rabbitmq]$ # ls
otp_src_20.0.tar.gz

3.解压下载好的文件

[work@busi-cmdmq01 rabbitmq]$ tar -zxvf otp_src_20.0.tar.gz

4.编译安装Erlang对环境有要求,为防止在编译的时候提示某些软件包未安装之类的错误,所以我将Erlang需要的软件提前安装,直接使用yum进行安装即可。

[work@busi-cmdmq01 rabbitmq]$ sudo yum install ncurses ncurses-base ncurses-devel ncurses-libs ncurses-static ncurses-term ocaml-curses ocaml-curses-devel -y
[work@busi-cmdmq01 rabbitmq]$sudo yum install openssl-devel zlib-devel –y
[work@busi-cmdmq01 rabbitmq]$ sudo yum -y install make ncurses-devel gcc gcc-c++ unixODBC unixODBC-devel openssl openssl-devel

5.编译安装Erlang:首先切换到解压好的目录里面去,然后再configure 。prefix后面指定的是安装目录,此时我把Erlang安装到了 /home/work/erlang目录下

[work@busi-cmdmq01 rabbitmq]$ cd /home/work/rabbitmq/otp_src_20.0
[work@busi-cmdmq01 otp_src_20.0]# sudo ./configure --prefix=/home/work/erlang --with-ssl -enable-threads -enable-smmp-support -enable-kernel-poll --enable-hipe --without-javac

接下来make一下

[work@localhost otp_src_20.0]$ sudo make&&make install

测试Erlang的安装是否成功:

work@localhost otp_src_20.0]$ cd /home/work/erlang/bin/
[work@busi-cmdmq01 bin]$ ./erl
Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-        threads:10] [hipe] [kernel-poll:false]
Eshell V9.0  (abort with ^G)
1>

6.到此时说明Erlang已经安装成功,下面我们要修改环境变量。

[work@busi-cmdmq01 bin]$ sudo vi /etc/profile

接下来会打开一个文件,按“i”键开始编辑文本,在文本的最后面添加如下几行代码:
(注意:此时的ERLANG_HOME是你的安装目录)

ERLANG_HOME=/home/work/erlang
PATH=$ERLANG_HOME/bin:$PATH
export ERLANG_HOME
export PATH

然后先按esc退出编辑,再按“:”和“wq”保存退出。保存后,重新激活使环境变量生效:

[work@busi-cmdmq01 bin]$ source /etc/profile

验证是否已经追加成功

[work@busi-cmdmq01 bin]$ echo $ERLANG_HOME
/home/work/erlang
[work@busi-cmdmq01 bin]$ echo $PATH
/home/work/erlang/bin:/home/local/apache-maven/bin:/home/work/java-    current/bin:/home/work/maven-current/bin:/home/work/java-    current/bin:/home/local/apache-    maven/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/work    /bin
[work@busi-cmdmq01 bin]$

OK,到现在为止我们的Erlang安装完成啦!!

安装RabbitMQ

7.下载最新版的rabbitmq,当前最新版本为3.6.10
第一个操作是切换到我要下载的目录,第二个操作是下载文件

[work@busi-cmdmq01 rabbitmq]$ cd /home/work/rabbitmq
[work@busi-cmdmq01 rabbitmq]$ wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server-generic-unix-3.6.10.tar.xz

8.查看下载的文件:

[work@busi-cmdmq01 rabbitmq]$ ll
total 94048
drwxr-xr-x 12 work work     4096 Mar 15 13:41 otp_src_20.0
-rw-rw-r--  1 work work 87346046 Jun 21  2017 otp_src_20.0.tar.gz
-rw-rw-r--  1 work work  4260951 May 25  2017 rabbitmq-server-3.5.8-1.noarch.rpm
-rw-rw-r--  1 work work  4688432 May 25  2017 rabbitmq-server-generic-unix-3.6.10.tar.xz

9.安装xz解压软件:

[work@busi-cmdmq01 rabbitmq]$ sudo yum -y install xz

10.解压RabbitMQ

[work@busi-cmdmq01 rabbitmq]$ xz -d rabbitmq-server-generic-unix-3.6.10.tar.xz
[work@busi-cmdmq01 rabbitmq]$ tar -xvf rabbitmq-server-generic-unix-3.6.10.tar

11.将解压好的文件移动到我的安装目录下去:

[work@busi-cmdmq01 rabbitmq]$ mv rabbitmq-3.6.10 /home/work/rabbit/

12.启动RabbitMQ:

[work@busi-cmdmq01 rabbitmq]$ cd /home/work/rabbit/rabbitmq-3.6.10/sbin/
[work@busi-cmdmq01 sbin]$ ./rabbitmq-server start
          RabbitMQ 3.6.10. Copyright (C) 2007-2017 Pivotal Software, Inc.
  ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
  ##  ##
  ##########  Logs: /home/work/rabbit/rabbitmq-3.6.10/var/log/rabbitmq/rabbit@busi-cmdmq01.log
  ######  ##        /home/work/rabbit/rabbitmq-3.6.10/var/log/rabbitmq/rabbit@busi-cmdmq01-sasl.log
  ##########
          Starting broker...
completed with 0 plugins.

13.创建用户 admin 密码PBmBtqDPKjsPTsHw:

[work@busi-cmdmq01 sbin]$ ./rabbitmqctl add_user admin PBmBtqDPKjsPTsHw
Creating user "admin"
[work@busi-cmdmq01 sbin]$ ./rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator]
[work@busi-cmdmq01 sbin]$ ./rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/"
[work@busi-cmdmq01 sbin]$

14.开启插件管理页面:

[work@busi-cmdmq01 sbin]$ ./rabbitmq-plugins list
[work@busi-cmdmq01 sbin]$ ./rabbitmq-plugins enable rabbitmq_management

然后在浏览器输入地址进入管理页面:

http://IP:15672/#/