Linux 下 RabbitMQ安装与配置

一、安装RABBITMQ SERVER
1、安装erlang ,源码安装,或者 yum installl erlang
https://packages.erlang-solutions.com/erlang/
https://packages.erlang-solutions.com/erlang/esl-erlang-src/otp_src_17.0.tar.gz

2、下载rabbitmq并解压安装,或者直接 yum install rabbitmq
http://www.rabbitmq.com/releases/rabbitmq-server

wget http://www.rabbitmq.com/releases/rabbitmq-server/current/rabbitmq-server-3.6.15-1.el6.noarch.rpm
rpm -ivh rabbitmq-server-3.6.15-1.el6.noarch.rpm

二、安装依赖、扩展
3、安装依赖rabbitmq-c
https://github.com/alanxz/rabbitmq-c
下载最新安装包
https://github.com/alanxz/rabbitmq-c/releases/latest

shell> wget https://github.com/alanxz/rabbitmq-c/archive/v0.9.0.tar.gz
shell> tar zxvf v0.9.0.tar.gz && cd rabbitmq-c-0.9.0
# 这一步是在rabbitmq-c的根目录下创建一个build子目录
shell> mkdir build && cd build
# 这一步是让cmake根据../CMakeList.txt,即rabbitmq-c的根目录下的CMakeList.txt创建Makefile文件,Makefile文件会被创建到build目录中
shell> cmake -DCMAKE_INSTALL_PREFIX=/usr/local/librabbitmq ..
# 这一步是真正的build rabbitmq-c库的,注意,不要漏掉结尾的点 '.'
shell> cmake --build .
shell> make && make install

4、PHP安装AMQP扩展
https://pecl.php.net/package/amqp
下载、解压、安装

shell> wget http://pecl.php.net/get/amqp-1.9.3.tgz
shell> tar zxvf amqp-1.9.3.tgz
shell> cd amqp-1.9.3
shell> /usr/local/php/bin/phpize
shell> ./configure --with-php-config=/usr/local/php/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/librabbitmq
shell> make && make install

5、开启web监控

shell> rabbitmq-plugins enable rabbitmq_management

6、添加用户

shell> rabbitmqctl add_user kendo 123456
shell> rabbitmqctl list_users
shell> rabbitmqctl set_user_tags kendo administrator
shell> rabbitmqctl set_permissions -p / kendo ".*" ".*" ".*"

Errors:
1、/usr/bin/ld: cannot find -lrabbitmq
#解决办法:
cd /usr/local/librabbitmq
ln -s ./lib64 ./lib
#查看扩展情况
php -m

2、Error: unable to perform an operation on node ‘rabbit@localhost’. Please see diagnostics information and suggestions below
rabbitmq服务未启动

shell> rabbitmq-server &

3、User can only log in via localhost
rabbitmq从3.3.0开始禁止使用guest/guest权限通过除localhost外的访问,我的版本是3.7.5
解决办法:新增一个user用于访问

4、 AMQPQueueException : Server channel error: 404, message: NOT_FOUND – no exchange ‘sx_ex’ in vhost ‘/’
原因:交换机没有找到,可能程序在创建交换机的时候没有设置持久化/没有声明

5、ErrorException : AMQPQueue::consume() expects parameter 1 to be a valid callback, function ‘processMessage’ not found or invalid function name
原因:processMessage 回掉函数不能写在类里面,必须是一个独立的外部函数;如果是laravel框架的下,执行命令行报该错误的话,需要引入辅助函数
解决:
vim app/Helpers/functions.php
#将函数放到上述文件
vim composer.json
#在autoload里加入
“files”:[
“app/Helpers/functions.php”
]

6、错误:依赖检测失败:
socat 被 rabbitmq-server-3.6.15-1.el6.noarch 需要

shell> yum install socat

7、checking for amqp files in default path… not found
configure: error: Please reinstall the librabbitmq distribution itself or (re)install librabbitmq development package if it available in your system
原因:没有安装amqp的依赖包rabbitmq-c,需要先安装rabbitmq-c

8、Could not open socket to \”0.0.0.0:9502\”: Connection refused (111)

Leave Comment