赞
踩
docker安装:
docker pull rabbitmq:3.7.7-management
docker run -d --name rabbitmq3.7.7 -p 5672:5672 -p 15672:15672 -v `pwd`/data:/var/lib/rabbitmq --hostname myRabbit -e RABBITMQ_DEFAULT_VHOST=my_vhost -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin docker.io/rabbitmq:3.7.7-management
http://ip:15672
账号:admin /admin
第一、下载erlang和rabbitmq-server的rpm:
centos 7 下载:
wget --no-check-certificate https://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.centos.x86_64.rpm
wget --no-check-certificate https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.15/rabbitmq-server-3.6.15-1.el7.noarch.rpm
centos6 下载:
wget --no-check-certificate https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.15/rabbitmq-server-3.6.15-1.el6.noarch.rpm
wget --no-check-certificate https://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el6.x86_64.rpm
安装 erlang
rpm -ivh erlang-19.0.4-1.el7.centos.x86_64.rpm
安装mq:
rpm -ivh rabbitmq-server-3.6.15-1.el7.noarch.rpm
[root@bogon rabitMq]# rpm -ivh rabbitmq-server-3.6.15-1.el7.noarch.rpm
警告:rabbitmq-server-3.6.15-1.el7.noarch.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID 6026dfca: NOKEY
错误:依赖检测失败:
socat 被 rabbitmq-server-3.6.15-1.el7.noarch 需要
[root@bogon rabitMq]#
报错: 需要安装socat
- 安装 socat 参考:https://www.cnblogs.com/ray30th/p/6651800.html
-
- Step 1:
-
- wget --no-cache http://www.convirture.com/repos/definitions/rhel/6.x/convirt.repo -O /etc/yum.repos.d/convirt.repo
-
- wget --no-cache http://www.convirture.com/repos/definitions/rhel/6.x/convirt.repo -O /etc/yum.repos.d/convirt.repo
- --2017-03-31 14:57:37-- http://www.convirture.com/repos/definitions/rhel/6.x/convirt.repo
- 正在解析主机 www.convirture.com... 69.195.93.219
- 正在连接 www.convirture.com|69.195.93.219|:80... 已连接。
- 已发出 HTTP 请求,正在等待回应... 200 OK
- 长度:184 [text/plain]
- 正在保存至: “/etc/yum.repos.d/convirt.repo”
-
- Step 2:
-
- yum makecache
-
-
-
- Step 3:
-
- yum install socat
-
-
- 又报错了,这次是yum报错了
[root@bogon rabitMq]# yum makecache
已加载插件:fastestmirror
File contains no section headers.
file: file:///etc/yum.repos.d/convirt.repo, line: 1
解决:https://blog.csdn.net/qq_38860828/article/details/82797592
- 在Linux正常更新过程中 有可能会突然出现某些加速插件启动,但是下面却又一些莫名其妙的内容,内容并非是错误提示. 比如:
-
- File contains no section headers. file: file:///etc/yum.repos.d/convirt.repo, line: 1 ‘\n’
-
- 解决办法:
-
- 把/etc/yum.repos.d下的文件全部删除,再重新下载对应操作系统版本的即可
-
- 1)centos5.*的下载连接: [root@bastion-IDC yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
-
- 2)centos6.*的下载连接: [root@bastion-IDC yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
-
- 3)centos7.*的下载连接: [root@bastion-IDC yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
-
再次安装socat yum install socat ,ok 成功
然后再次安装rabbitmq
- [root@bogon rabitMq]# rpm -ivh rabbitmq-server-3.6.15-1.el7.noarch.rpm
- 警告:rabbitmq-server-3.6.15-1.el7.noarch.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID 6026dfca: NOKEY
- 准备中... ################################# [100%]
- 正在升级/安装...
- 1:rabbitmq-server-3.6.15-1.el7 ################################# [100%]
第四、启动和关闭:
/sbin/service rabbitmq-server stop #关闭
/sbin/service rabbitmq-server start #启动
/sbin/service rabbitmq-server status #状态
先启动,启动时间比较长,得等会
- [root@bogon rabitMq]# /sbin/service rabbitmq-server status
- Redirecting to /bin/systemctl status rabbitmq-server.service
- ● rabbitmq-server.service - RabbitMQ broker
- Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled)
- Active: active (running) since 二 2019-07-02 23:11:37 CST; 7min ago
- Main PID: 1762 (beam.smp)
- Status: "Initialized"
- CGroup: /system.slice/rabbitmq-server.service
- ├─1762 /usr/lib64/erlang/erts-8.0.3/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -- -root /usr/lib64/erlang -progname erl -- -home /var/lib/rabbitm...
- ├─1903 /usr/lib64/erlang/erts-8.0.3/bin/epmd -daemon
- ├─2019 erl_child_setup 1024
- ├─2031 inet_gethost 4
- └─2040 inet_gethost 4
-
- 7月 02 23:11:02 bogon rabbitmq-server[1762]: RabbitMQ 3.6.15. Copyright (C) 2007-2018 Pivotal Software, Inc.
- 7月 02 23:11:02 bogon rabbitmq-server[1762]: ## ## Licensed under the MPL. See http://www.rabbitmq.com/
- 7月 02 23:11:02 bogon rabbitmq-server[1762]: ## ##
- 7月 02 23:11:02 bogon rabbitmq-server[1762]: ########## Logs: /var/log/rabbitmq/rabbit@bogon.log
- 7月 02 23:11:02 bogon rabbitmq-server[1762]: ###### ## /var/log/rabbitmq/rabbit@bogon-sasl.log
- 7月 02 23:11:02 bogon rabbitmq-server[1762]: ##########
- 7月 02 23:11:02 bogon rabbitmq-server[1762]: Starting broker...
- 7月 02 23:11:37 bogon rabbitmq-server[1762]: systemd unit for activation check: "rabbitmq-server.service"
- 7月 02 23:11:37 bogon systemd[1]: Started RabbitMQ broker.
- 7月 02 23:11:37 bogon rabbitmq-server[1762]: completed with 0 plugins
ok了
cd 到 /sbin
./rabbitmq-plugins list
./rabbitmqctl status
第六、其他
运行如下的命令,增加用户admin,密码admin
[root@localhost sbin]# ./rabbitmqctl add_user admin admin
Creating user "admin" ...
...done.
[root@localhost sbin]# ./rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administraotr] ...
...done.
[root@localhost sbin]# ./rabbitmqctl list_users
Listing users ...
admin [administraotr]
guest [administrator]
...done.
第七、扩展参考
[Erlang 0086] RabbitMQ 集群: 从零开始
继续 ,成功启动后,通过网页 :http://********:15672 访问失败
首先创建目录,否则可能报错:
mkdir /etc/rabbitmq
rabbitmq-plugins enable rabbitmq_management
配置linux 端口 15672 网页管理 5672 AMQP端口:
firewall-cmd --permanent --add-port=15672/tcp
firewall-cmd --permanent --add-port=5672/tcp
systemctl restart firewalld.service
浏览器中输入服务器IP:15672 就可以看到RabbitMQ的WEB管理页面了,登录
报错,发现之前的 ./rabbitmqctl set_user_tags admin administrator给弄错了, 这个问题不大,重新set下ok
登录后:
新建 virtual_hosts
授权
- //最普通的连接代码
- public class ConnectionUtils{
-
- public static Connection getConnection() throws IOException, TimeoutException {
-
- ConnectionFactory factory = new ConnectionFactory();
-
- //设置服务地址
- factory.setHost("127.0.0.1");
-
- factory.setPort(5672);
-
- factory.setVirtualHost("virtual_hosts_test");
-
-
- factory.setUsername("admin");
-
- factory.setPassword("admin");
-
- return factory.newConnection();
-
-
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。