RabbitMQ安装遇到的问题(转载)

来源:互联网 发布:搜狗删除 云计算 编辑:程序博客网 时间:2024/05/16 04:40

转载 引自:RabbitMQ(二)CentOS6.7 下的 HelloWorld

前一篇写了在Windows下的安装使用,这次记录下CentOS6.7下的安装使用.

其实在CentOS下和Windows下过程是一样的,都是 先安装Erlang环境,再安装RabbitMQ Server.

只不过CentOS下经常遇到各种问题,所以感觉上麻烦点.


版本是 CentOS6.7+RabbitMQ3.6.5,官方文档地址 http://www.rabbitmq.com/install-rpm.html


主要分以下部分

1) 安装Erlang环境

2)安装RabbitMQ Server

3)启动server,并启用管理台插件

4)新增用户并设置权限

5)外网登录管理台

6)代码连接CentOS下的MQ

7)遇到的问题及解决办法



1)安装Erlang环境

官网提供了3种安装方法,我这里用第一种.

按官网指引,来到 https://www.erlang-solutions.com/resources/download.html 页面, 这里可以选择Linux的版本进行对应的下载.

我最开始 选择了centos,然后下载19.1.5这个版本, 然后进行安装发现少一堆包.

最后还是安装网页下发的 说明进行在线安装



首先

[html] view plain copy
 print?
  1. wget https://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm  
  2. rpm -Uvh erlang-solutions-1.0-1.noarch.rpm  


这2句一般不会遇到问题,然后

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. sudo yum install erlang  

遇到问题1

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. http://packages.erlang-solutions.com/rpm/centos/6/x86_64/repodata/primary.xml.gz: [Errno -1] Metadata file does not match checksum  
  2. Trying other mirror.  
  3. erlang-solutions/primary                                                                                                                                                   | 869 kB     00:00       
  4. http://packages.erlang-solutions.com/rpm/centos/6/x86_64/repodata/primary.xml.gz: [Errno -1] Metadata file does not match checksum  
  5. Trying other mirror.  
  6. Error: failure: repodata/primary.xml.gz from erlang-solutions: [Errno 256] No more mirrors to try.  


解决方法见7)中的问题1.解决后继续


因为网速慢,遇到问题2

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. [Errno 12] Timeout on  

解决方法见7)中的问题2.解决后继续

Erlang安装完成.



2)安装RabbitMQ Server

需要先下载 rpm文件 , (上面给的官网安装地址 最上面就有下载的地方)

然后执行下面命令

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc  
  2. yum install rabbitmq-server-3.6.5-1.noarch.rpm  
注:上面yum命令  要在 下载的rpm文件的目录下进行


遇到问题3

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. Error: Package: rabbitmq-server-3.6.5-1.noarch (/rabbitmq-server-3.6.5-1.noarch)  
  2.            Requires: socat  


解决方法见7)中的问题3.解决后继续

完成安装


3)启动server,并启用管理台插件

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. 执行  whereis rabbitmq  
  2. 结果  rabbitmq: /etc/rabbitmq /usr/lib/rabbitmq  
  3. 执行  cd /usr/lib/rabbitmq/bin  
  4. 执行  rabbitmq-server start  

结果如下

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1.             RabbitMQ 3.6.5. Copyright (C) 2007-2016 Pivotal Software, Inc.  
  2. ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/  
  3. ##  ##  
  4. ##########  Logs: /var/log/rabbitmq/rabbit@localhost.log  
  5. ######  ##        /var/log/rabbitmq/rabbit@localhost-sasl.log  
  6. ##########  
  7.             Starting broker...  
  8. ompleted with 0 plugins.  


可以看到默认没有插件,然后我们去启动管理台的插件

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. [root@localhost bin]# rabbitmq-plugins enable rabbitmq_management  
  2. The following plugins have been enabled:  
  3.   mochiweb  
  4.   webmachine  
  5.   rabbitmq_web_dispatch  
  6.   amqp_client  
  7.   rabbitmq_management_agent  
  8.   rabbitmq_management  
  9.   
  10. Applying plugin configuration to rabbit@localhost... failed.  
  11.  * Could not contact node rabbit@localhost.  
  12.    Changes will take effect at broker restart.  
  13.  * Options: --online  - fail if broker cannot be contacted.  
  14.             --offline - do not try to contact broker.  


这里出现了 contact node rabbit@localhost 的提示,但是当时没注意,就继续往下了

执行启动命令. 启动完成

整体如下图


启动完成.



4)新增用户并设置权限

因为假想中这是服务器,我们平时访问肯定都是在外网,所以默认的guest只能在本机使用肯定不行了.(官方推荐删掉guest或者修改密码)

所以我们需要新增一个可以外网访问的用户.

可以在页面新增(更简单一点),也可以用命令新增. 我们这里用命令

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. rabbitmqctl  add_user  admin  123456  


遇到问题4,和启动插件时候有点类似 Error: unable to connect to node rabbit@localhost: nodedown



解决方法见7)中的问题4.解决后继续

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. rabbitmqctl set_user_tags admin administrator  
  2. rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"  

上面2句分别是设置角色(非官方说法),设置外网登录权限

OK.新增用户授权完成.


5)外网登录管理台

在本地浏览器输入CentOS的管理台地址 http://192.168.1.100:15672/

这里要注意下centos的防火墙状态,我测试就直接把防火墙关了

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. 关闭防火墙  
  2. /etc/init.d/iptables stop  

使用刚才创建的admin登录后,如下图



如果登录失败,返回状态是401的话,就是权限设置的有问题.



6)代码连接CentOS下的MQ

代码和上一篇Windows下的基本一样,只是需要指定下IP,用户名,密码

[java] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. import com.rabbitmq.client.Channel;  
  2. import com.rabbitmq.client.Connection;  
  3. import com.rabbitmq.client.ConnectionFactory;  
  4.   
  5.   
  6. public class Send {  
  7.   private final static String QUEUE_NAME = "hello";  
  8.   
  9.   
  10.   public static void main(String[] argv) throws Exception {  
  11.     ConnectionFactory factory = new ConnectionFactory();  
  12.     factory.setHost("192.168.1.100");  
  13.     factory.setUsername("admin");  
  14.     factory.setPassword("123456");  
  15.     Connection connection = factory.newConnection();  
  16.     Channel channel = connection.createChannel();  
  17.   
  18.   
  19.     channel.queueDeclare(QUEUE_NAME, falsefalsefalsenull);  
  20.     String message = "Hello World!";  
  21.     channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));  
  22.     System.out.println(" [x] Sent '" + message + "'");  
  23.   
  24.   
  25.     channel.close();  
  26.     connection.close();  
  27.   }  
  28. }  


[java] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1.   

接收的类也一样

[java] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. import com.rabbitmq.client.*;  
  2.   
  3.   
  4. import java.io.IOException;  
  5.   
  6.   
  7. public class Recv {  
  8.   
  9.   private final static String QUEUE_NAME = "hello";  
  10.   
  11.   public static void main(String[] argv) throws Exception {  
  12.     ConnectionFactory factory = new ConnectionFactory();  
  13.     factory.setHost("192.168.1.100");  
  14.     factory.setUsername("admin");  
  15.     factory.setPassword("123456");  
  16.     Connection connection = factory.newConnection();  
  17.     Channel channel = connection.createChannel();  
  18.   
  19.     channel.queueDeclare(QUEUE_NAME, falsefalsefalsenull);  
  20.     System.out.println(" [*] Waiting for messages. To exit press CTRL+C");  
  21.   
  22.     Consumer consumer = new DefaultConsumer(channel) {  
  23.       @Override  
  24.       public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)  
  25.           throws IOException {  
  26.           System.out.println("consumerTag"+consumerTag);  
  27.           System.out.println("properties"+properties.getMessageId());  
  28.         String message = new String(body, "UTF-8");  
  29.         System.out.println(" [x] Received '" + message + "'");  
  30.       }  
  31.     };  
  32.     channel.basicConsume(QUEUE_NAME, true, consumer);  
  33.   }  
  34. }  


端口号因为是默认的,指定不指定无所谓了.

运行代码,成功执行.






7)遇到的问题及解决办法


问题1

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. http://packages.erlang-solutions.com/rpm/centos/6/x86_64/repodata/primary.xml.gz: [Errno -1] Metadata file does not match checksum  
  2. Trying other mirror.  


解决1

先安装网上的  yum clean all 发现没解决.

继续深入

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. wget --no-cache http://packages.erlang-solutions.com/rpm/centos/6/x86_64/repodata/primary.xml.gz  
  2. sha1sum primary.xml.gz  
  3.   
  4. 得到下面的  
  5. 1572f7949d751054a14e0b24ea3f2592633d06c4  primary.xml.gz  


然后找到本地的

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. cd /var/cache/yum/x86_64/6/erlang-solutions  
  2. vim repomd.xml  


发现里面的数值和我们计算的不一致,则修改成上面计算的.(下面是我修改后的)

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. <data type="primary">  
  2.   <location href="repodata/primary.xml.gz"/>  
  3.   <checksum type="sha">1572f7949d751054a14e0b24ea3f2592633d06c4</checksum>  
  4.   <timestamp>1478542719</timestamp>  
  5.   <open-checksum type="sha">61989f5a64efd4daecd0d719457a47a2290b7126</open-checksum>  
  6. </data>  

保存,退出.继续执行 sudo yum install erlang, 我这还有个这种提示,但是继续往下运行了. 问题解决

参考 http://tilt.lib.tsinghua.edu.cn/node/385

搞定!


问题2

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. [Errno 12] Timeout on  


解决2

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. vim /etc/yum.conf     
设置超时时间 加上 timeout=1200
网速慢可以设置更长点.
搞定!

问题3

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. Error: Package: rabbitmq-server-3.6.5-1.noarch (/rabbitmq-server-3.6.5-1.noarch)  
  2.            Requires: socat  


解决3
看提示就是需要socat的包,
去下载socat
[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. yum install socat  

结果出现
[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. Loaded plugins: fastestmirror, refresh-packagekit, security  
  2. Setting up Install Process  
  3. Loading mirror speeds from cached hostfile  
  4.  * base: mirrors.btte.net  
  5.  * extras: mirrors.btte.net  
  6.  * updates: mirror.bit.edu.cn  
  7. No package socat available.  
  8. Error: Nothing to do  

继续解决,更新源
[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. wget --no-cache http://www.convirture.com/repos/definitions/rhel/6.x/convirt.repo -O /etc/yum.repos.d/convirt.repo  
  2. yum install socat  
  3. yum install rabbitmq-server-3.6.5-1.noarch.rpm  

搞定!


问题4
[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. Error: unable to connect to node rabbit@localhost: nodedown  

解决4
这个问题官网也提到过,说是cookie不一致之类的问题.
网上搜了好多,其实在我们 开启管理台插件的时候,就已经看到提示了. 那就是重启解决.
最后执行
[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. service rabbitmq-server restart  
然后再执行命令, 果然OK.

搞定!


总结下.在centos下安装,不同的机器可能遇到不同的问题.我安装了3次就分别遇到不同的问题.都记录在里面了.
一般通过网上搜索都可以解决!

0 0