欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ubuntu:RabbitMq安装与踩雷

程序员文章站 2022-05-27 14:41:12
...

使用rabbitmq的库安装erlang,脚本如下:

#!/bin/sh

sudo apt-get install curl gnupg debian-keyring debian-archive-keyring apt-transport-https -y

## Team RabbitMQ's main signing key
sudo apt-key adv --keyserver "hkps://keys.openpgp.org" --recv-keys "0x0A9AF2115F4687BD29803A206B73A36E6026DFCA"
## Cloudsmith: modern Erlang repository
curl -1sLf https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key | sudo apt-key add -
## Cloudsmith: RabbitMQ repository
curl -1sLf https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/gpg.9F4587F226208342.key | sudo apt-key add -

## Add apt repositories maintained by Team RabbitMQ
sudo tee /etc/apt/sources.list.d/rabbitmq.list <<EOF
## Provides modern Erlang/OTP releases
##
deb https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/deb/ubuntu bionic main
deb-src https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/deb/ubuntu bionic main

## Provides RabbitMQ
##
deb https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/deb/ubuntu bionic main
deb-src https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/deb/ubuntu bionic main
EOF

## Update package indices
sudo apt-get update -y

## Install Erlang packages
sudo apt-get install -y erlang-base \
                        erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \
                        erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \
                        erlang-runtime-tools erlang-snmp erlang-ssl \
                        erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl

安装完erl,一定要测试一下erl好不好用,如报以下错误

$ erl
/usr/lib/erlang/erts-12.0.2/bin/beam.smp: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

安装 $ sudo apt-get install libncurses5

$ erl                             
Erlang/OTP 24 [erts-12.0.2] [source] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:1] [jit]

Eshell V12.0.2  (abort with ^G)
1>

然后安装rabbitmq

## Install rabbitmq-server and its dependencies
sudo apt-get install rabbitmq-server -y --fix-missing

查询rabbitmq状态

$ service rabbitmq-server status
● rabbitmq-server.service - RabbitMQ broker
     Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-06-24 12:15:56 CST; 4min 5s ago
   Main PID: 97279 (beam.smp)
     Status: "Initialized"
      Tasks: 31 (limit: 19074)
     Memory: 99.4M
     CGroup: /system.slice/rabbitmq-server.service
             ├─97279 /usr/lib/erlang/erts-12.0.2/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -sbwt none -sbwtdcpu none -sbwtdi>
             ├─97290 erl_child_setup 32768
             ├─97357 inet_gethost 4
             └─97358 inet_gethost 4

关闭rabbitmq $ service rabbitmq-server stop

安装rabbitmq管理界面

$ sudo rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node [email protected]:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to [email protected]...
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.

$ service rabbitmq-server start

然后访问15672端口,就可以看到rabbitmq的后台界面啦
http://localhost:15672/
初始账户、密码 都是guest

远程服务器

如果访问不了,可能是你的服务器开启了防火墙,可以选择开放端口,或者关闭防火墙

systemctl stop firewalld

远程服务器也不能使用默认的账户密码登陆后台,需要在控制台新创建用户

##创建账号,admin,密码123
rabbitmqctl add_user admin 123
##设置用户角色
rabbitmqctl set_user_tags admin administrator
##设置用户权限
##rabbitmqctl set_permissions [-p <vhostpath>] <user> <conf> <write> <read>
rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
##当前用户和角色
rabbitmqctl list_users