ubuntu 16.04 LTS RabbitMQ 3.6.10 安装配置

RabbitMQ 安装配置

RabbitMQ_.png
RabbitMQ 已经经历了10 来个春夏秋冬,全球超过35000生产部署RabbitMQ,RabbitMQ是最受欢迎的开源消息队列,
正如官网的介绍:

RabbitMQ is the most widely deployed open source message broker

With more than 35,000 production deployments of RabbitMQ world-wide at small startups and large enterprises, RabbitMQ is the most popular open source message broker.

RabbitMQ 安装

  1. 访问RabbitMQ官网 下载对应系统版本,这里我们下载Debian Ubuntu 对应的版本。
  2. 将下载的rabbitmq-server_3.6.10-1_all.deb 安装包放于用户家目录下work目录。
    alex@ubuntu:~$ cd work/
    alex@ubuntu:~/work$ ls -l
    total 4772
    -rwxrw-rw- 1 alex alex 4885200 Jun 21 01:29 rabbitmq-server_3.6.10-1_all.deb
    alex@ubuntu:~/work$ 
    
  3. 使用 dpkg 命令安装 rabbitmq
    dpkg 参见:Ubuntu下deb包的安装方法
    ` bash
    alex@ubuntu:~/work$ sudo dpkg -i rabbitmq-server_3.6.10-1_all.deb
    [sudo] password for alex:
    Selecting previously unselected package rabbitmq-server.
    (Reading database … 208585 files and directories currently installed.)
    Preparing to unpack rabbitmq-server_3.6.10-1_all.deb …
    Unpacking rabbitmq-server (3.6.10-1) …
    dpkg: dependency problems prevent configuration of rabbitmq-server:
    rabbitmq-server depends on erlang-nox (>= 1:16.b.3) | esl-erlang; however:
    Package erlang-nox is not installed.
    Package esl-erlang is not installed.
    rabbitmq-server depends on socat; however:
    Package socat is not installed.

dpkg: error processing package rabbitmq-server (–install):
dependency problems - leaving unconfigured
Processing triggers for man-db (2.7.5-1) …
Processing triggers for systemd (229-4ubuntu10) …
Processing triggers for ureadahead (0.100.0-19) …
Errors were encountered while processing:
rabbitmq-server

如上rabbitmq-server依赖于erlang-nox,下面安装输入:sudo apt-get install erlang-nox
but 依然报错
``` bash
alex@ubuntu:~/work$ sudo apt-get install erlang-nox
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 erlang-nox : Depends: erlang-base but it is not going to be installed or
                       erlang-base-hipe but it is not going to be installed
              Depends: erlang-asn1 but it is not going to be installed
              Depends: erlang-corba but it is not going to be installed
              Depends: erlang-crypto but it is not going to be installed
              Depends: erlang-diameter but it is not going to be installed
              Depends: erlang-edoc but it is not going to be installed
              Depends: erlang-eldap but it is not going to be installed
              Depends: erlang-erl-docgen but it is not going to be installed
              Depends: erlang-eunit but it is not going to be installed
              Depends: erlang-ic but it is not going to be installed
              Depends: erlang-inets but it is not going to be installed
              Depends: erlang-mnesia but it is not going to be installed
              Depends: erlang-odbc but it is not going to be installed
              Depends: erlang-os-mon but it is not going to be installed
              Depends: erlang-parsetools but it is not going to be installed
              Depends: erlang-percept but it is not going to be installed
              Depends: erlang-public-key but it is not going to be installed
              Depends: erlang-runtime-tools but it is not going to be installed
              Depends: erlang-snmp but it is not going to be installed
              Depends: erlang-ssh but it is not going to be installed
              Depends: erlang-ssl but it is not going to be installed
              Depends: erlang-syntax-tools but it is not going to be installed
              Depends: erlang-tools but it is not going to be installed
              Depends: erlang-webtool but it is not going to be installed
              Depends: erlang-xmerl but it is not going to be installed
 rabbitmq-server : Depends: socat but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

根据提示,执行 apt-get -f install
中途提示:Do you want to continue? [Y/n] 输入 Y

alex@ubuntu:~/work$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  erlang-asn1 erlang-base erlang-corba erlang-crypto erlang-diameter
  erlang-edoc erlang-eldap erlang-erl-docgen erlang-eunit erlang-ic
  erlang-inets erlang-mnesia erlang-nox erlang-odbc erlang-os-mon
  erlang-parsetools erlang-percept erlang-public-key erlang-runtime-tools
  erlang-snmp erlang-ssh erlang-ssl erlang-syntax-tools erlang-tools
  erlang-webtool erlang-xmerl libodbc1 libsctp1 socat
Suggested packages:
  erlang erlang-manpages erlang-doc xsltproc fop erlang-ic-java
  erlang-observer libmyodbc odbc-postgresql tdsodbc unixodbc-bin lksctp-tools
The following NEW packages will be installed:
  erlang-asn1 erlang-base erlang-corba erlang-crypto erlang-diameter
  erlang-edoc erlang-eldap erlang-erl-docgen erlang-eunit erlang-ic
  erlang-inets erlang-mnesia erlang-nox erlang-odbc erlang-os-mon
  erlang-parsetools erlang-percept erlang-public-key erlang-runtime-tools
  erlang-snmp erlang-ssh erlang-ssl erlang-syntax-tools erlang-tools
  erlang-webtool erlang-xmerl libodbc1 libsctp1 socat
0 upgraded, 29 newly installed, 0 to remove and 326 not upgraded.
1 not fully installed or removed.
Need to get 19.6 MB of archives.
After this operation, 36.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
....
Adding system user `rabbitmq' (UID 124) ...
Adding new user `rabbitmq' (UID 124) with group `rabbitmq' ...
Not creating home directory `/var/lib/rabbitmq'.
Setting up libsctp1:amd64 (1.0.16+dfsg-3) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
Processing triggers for systemd (229-4ubuntu10) ...
Processing triggers for ureadahead (0.100.0-19) ...

再次输入:sudo dpkg -i rabbitmq-server_3.6.10-1_all.deb

alex@ubuntu:~/work$ sudo dpkg -i rabbitmq-server_3.6.10-1_all.deb 
(Reading database ... 210659 files and directories currently installed.)
Preparing to unpack rabbitmq-server_3.6.10-1_all.deb ...
Unpacking rabbitmq-server (3.6.10-1) over (3.6.10-1) ...
Setting up rabbitmq-server (3.6.10-1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu10) ...
Processing triggers for ureadahead (0.100.0-19) ...

显然如上结果,表示 rabbitmq-server 安装完成,启动rabbitmq-server 服务

// 启动 rabbitmq-server
alex@ubuntu:~/work$ sudo service rabbitmq-server start
// 停止 rabbitmq-server
alex@ubuntu:~/work$ sudo service rabbitmq-server stop
// 重启 rabbitmq-server
alex@ubuntu:~/work$ sudo service rabbitmq-server restart
  1. 若通过终端安装程序sudo apt-get install xxx时出错:
    sudo apt-get install erlang-nox
    E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
    E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it 
    
    通过如下强制解锁,命令
    $ sudo rm /var/lib/dpkg/lock
    
    再次输入安装命令,可能会会提示 “E: dpkg 被中断,您必须手工运行 sudo dpkg –configure -a 解决此问题”
    按照提示执行:sudo dpkg –configure -a

RabbitMQ 管理插件 management plugin

RabbitMQ 默认已经集成了management plugin,通过命令enable即可

$ cd /usr/lib/rabbitmq/bin/
$ sudo rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  amqp_client
  cowlib
  cowboy
  rabbitmq_web_dispatch
  rabbitmq_management_agent
  rabbitmq_management

Applying plugin configuration to rabbit@ubuntu... started 6 plugins.
.....

当显示如上信息,打开浏览器访问:http://localhost:15672
输入默认用户名/密码:guest/guest 登陆Web管理页:
RabbitMQ_Web.png

guest用户只能从localhost地址登录,如果要配置远程登录,必须创建用户

  1. 通过Web管理页面添加用户并设置权限,点击用户进入授权页面,默认直接点击”set permission”即可
  2. 通过命令添加用户,并分配权限:
    $ sudo rabbitmqctl add_user admin admin
    Creating user "admin"
    $ sudo rabbitmqctl set_user_tags admin administrator
    Setting tags for user "admin" to [administrator]
    $ sudo rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
    Setting permissions for user "admin" in vhost "/"
    
    设置完成后,RabbitMQ就可以远程通过 http://rabbitmq_ip:15672 访问了。
Alex.Yao wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!