RabbitMQ 的安装配置

环境:Ubuntu16 linux系统,ERlang语言的源码包 :otp_src_22.0.tar.gz,rabbitMQ安装包:rabbitmq-server-generic-unix-3.7.16.tar ,jdk1.8(ERLang的编译需要系统有jdk的支持)

想要安装rabbitMQ服务组件,需要配置ERlang语言环境的依赖。

一:ERLang语言的安装与配置

1.更新系统软件包,想要安装ERlang语言环境,需要先配置支持库

1.apt-get update
2.apt-get -y install libncurses5-dev   //2或者2.1依赖库选择一个即可
2.1 apt-get -y install make g++ gcc libpcre3 libpcrecpp* libpcre3-dev libssl-dev autoconf automake libtool nfs-kernel-server libncurses5-dev libaio.dev ruby-dev rubygems vim    

2.把已经上传的ERlang语言环境包上传服务器解压缩

tar xzvf /srv/ftp/otp_src_22.0.tar.gz -C /usr/local/src/

3.ERLang编译完成后需要设置一个编译后的程序的存储目录

mkdir -p /usr/local/erlang

4.进入ERLang源码目录

cd /usr/local/src/otp_src_22.0/

5.指定编译后的内容保存到指定目录,

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

6.对源码进行编译

make && make install

7.编译完成后,所有内容会自动保存在之前指定的“usr/local/erlang”目录,为了方便使用,修改profile配置文件,把内容设置到系统环境中

vim /etc/profile      
export ERLANG_HOME=/usr/local/erlang
export PATH=:$ERLANG_HOME/bin:
source /etc/profile     //添加后配置后进行激活

注:如果之后出现 Command 'ls' is available in '/bin/ls' 类似错误, 请参照我的环境变量位置添加,

/usr/bin/vim  /etc/profile 命令可以使用vim对profile文件进行修改,参考:https://www.cnblogs.com/austinspark-jessylu/p/6737877.html

export JAVA_HOME=/usr/local/jdk1.8
export MYSQL_HOME=/usr/local/mysql
export M2_HOME=/usr/local/maven
export ERLANG_HOME=/usr/local/erlang
export PATH=$PATH:$JAVA_HOME/bin:$MYSQL_HOME/bin:$M2_HOME/bin:$ERLANG_HOME/bin:
           

 

8.检查环境配置是否正常,可以直接输入  “ erl ” ,命令启动erlang的交互式编程环境打印

erl

io:format("Hello World!").

退出编译环境

halt().

9.如果此时成功打印出   “Hello World!”  ,说明我们的ERL环境已经配置好了。

二:RabbitMQ的安装与配置

1.对已经上传好的rabbitmq文件  rabbitmq-server-generic-unix-3.7.16.tar.xz  进行解压缩

xz -d /srv/ftp/rabbitmq-server-generic-unix-3.7.16.tar.xz      //对“ tar.xz ”解压缩

tar xvf /srv/ftp/rabbitmq-server-generic-unix-3.7.16.tar -C /usr/local/     
 //对“ tar ”文件解压缩到指定文件夹

2.为了方便后续的配置,我们对文件目录进行更名处理

mv /usr/local/rabbitmq_server-3.7.16/ /usr/local/rabbitmq

3.启动rabbbitmq服务,如果启动后回执一只代码打印的兔子说明服务启动成功

/usr/local/rabbitmq/sbin/rabbitmq-server start

4.为了方便我们对rabbitmq的使用和后台管理,在启动命令后面追加备份配置参数:

/usr/local/rabbitmq/sbin/rabbitmq-server start > /dev/null 2>&1 &

5.为了安全与方便后台管理,我们可以创建一个用户,信息为 yu/hello

/usr/local/rabbitmq/sbin/rabbitmqctl add_user yu hello

注:我在添加用户时出现下面问题,结果是因为/etc/hosts的映射配置有错,

Error: unable to perform an operation on node 'rabbit@rabbitmq-server'. Please see diagnostics information and suggestions below.

Most common reasons for this are:

 * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)
 * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)
 * Target node is not running

In addition to the diagnostics info below:

 * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more
 * Consult server logs on node rabbit@rabbitmq-server
 * If target node is configured to use long node names, don't forget to use --longnames with CLI tools

DIAGNOSTICS
===========

attempted to contact: ['rabbit@rabbitmq-server']

rabbit@rabbitmq-server:
  * connected to epmd (port 4369) on rabbitmq-server
  * epmd reports node 'rabbit' uses port 25672 for inter-node and CLI tool traffic 
  * can't establish TCP connection to the target node, reason: timeout (timed out)
  * suggestion: check if host 'rabbitmq-server' resolves, is reachable and ports 25672, 4369 are not blocked by firewall

Current node details:
 * node name: 'rabbitmqcli-6261-rabbit@rabbitmq-server'
 * effective user's home directory: /root
 * Erlang cookie hash: 1fUlYkhJd+nIoW03NSuzOQ==

修改后可以创建用户,hosts修改后:

127.0.0.1 ubuntu                                                                                     
127.0.0.1 localhost                                      
192.168.19.138 rabbitmq-server

 

6.此时想要使用当前用户可以进行角色分配,可以把他添加到管理组

/usr/local/rabbitmq/sbin/rabbitmqctl set_user_tags yu administrator

7.RabbitMQ服务启动之后我们如想要在WEB界面进行管理,需要启动管理界面

/usr/local/rabbitmq/sbin/rabbitmq-plugins enable rabbitmq_management

8.现在我们可以查看端口使用情况判断服务是否启动成功,

netstat -nptl

浏览器页面访问

http://192.168.19.138:15672

现在,我们可以在web界面进行管理了。

 

posted @ 2019-07-12 01:02  萧余  阅读(967)  评论(0编辑  收藏  举报