安装 RabbitMQ – centos 6

 

1.安装Erlang环境

cd /usr/local/src/  
mkdir rabbitmq  
cd rabbitmq  
  
wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm  
rpm -Uvh erlang-solutions-1.0-1.noarch.rpm  
  
rpm --import http://packages.erlang-solutions.com/rpm/erlang_solutions.asc  
  
sudo yum install erlang

2.安装RabbitMQ

上面都成功后 安装RabbitMQ

wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.1/rabbitmq-server-3.6.1-1.noarch.rpm
rpm --import https://www.rabbitmq.com/rabbitmq-signing-key-public.asc
yum install rabbitmq-server-3.6.1-1.noarch.rpm

安装输出log如下:

Loaded plugins: security
Setting up Install Process
Examining rabbitmq-server-3.6.1-1.noarch.rpm: rabbitmq-server-3.6.1-1.noarch
Marking rabbitmq-server-3.6.1-1.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package rabbitmq-server.noarch 0:3.6.1-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================
 Package                    Arch              Version             Repository                                  Size
===================================================================================================================
Installing:
 rabbitmq-server            noarch            3.6.1-1             /rabbitmq-server-3.6.1-1.noarch            5.5 M

Transaction Summary
===================================================================================================================
Install       1 Package(s)

Total size: 5.5 M
Installed size: 5.5 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : rabbitmq-server-3.6.1-1.noarch                                                                  1/1 
  Verifying  : rabbitmq-server-3.6.1-1.noarch                                                                  1/1 

Installed:
  rabbitmq-server.noarch 0:3.6.1-1                                                                                 

Complete!

run the following command to allow SELinux to enable RabbitMQ service:

setsebool -P nis_enabled 1

开启端口,如果是本地测试,关掉iptables也可以

4369 (epmd), 25672 (Erlang distribution)
 5672, 5671 (AMQP 0-9-1 without and with TLS)
 15672 (if management plugin is enabled)
 61613, 61614 (if STOMP is enabled)
 1883, 8883 (if MQTT is enabled)

启动:

/etc/init.d/rabbitmq-server start

log如下:

[root@iZ942k2d5ezZ tools]# /etc/init.d/rabbitmq-server start
Starting rabbitmq-server: SUCCESS
rabbitmq-server.

加入浏览器界面:

rabbitmq-plugins enable rabbitmq_management
chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/

然后访问:

http://120.24.37.249:15672

就可以看到界面了:

RabbitMQ Management - Google Chrome_005

增加账户:

rabbitmqctl add_user mqadmin 123456
rabbitmqctl set_user_tags mqadmin administrator
rabbitmqctl set_permissions -p / mqadmin ".*" ".*" ".*"

 

上面的命令中

mqadmin就是登陆的账户

123456就是登陆的密码

然后就可以看到界面了,如下:

RabbitMQ Management

rabbitmq php 安装amqp扩展

一:安装rabbitmq-c-0.7.1

没有安装就会提示上面的错误
下载地址:https://github.com/alanxz/rabbitmq-c
我选择的是最新版本0.7.1

wget https://github.com/alanxz/rabbitmq-c/releases/download/v0.7.1/rabbitmq-c-0.7.1.tar.gz
tar zxf rabbitmq-c-0.7.1.tar.gz
 
cd rabbitmq-c-0.7.1
./configure --prefix=/usr/local/rabbitmq-c-0.7.1
make && make install

备注:如果下面的下载比较慢,您可以到百度云盘下载我下载下来的文件,云盘地址:http://pan.baidu.com/s/1kVwRD2Z#list/path=%2F,打开这个链接,找到文件rabbitmq-c-0.7.1.tar下载下来即可。

二:安装amqp

下载地址https://pecl.php.net/package/amqp
我选择的是1.6.1

!!!对于php7.1,需要下载高版本:

wget https://pecl.php.net/get/amqp-1.9.3.tgz   //php 7.1
wget https://pecl.php.net/get/amqp-1.6.1.tgz   // php 5.6
tar zxf amqp-1.6.1.tgz
cd amqp-1.6.1
 
/usr/local/php/bin/phpize
 
./configure --with-php-config=/usr/local/php/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c-0.7.1

注意:这里的/usr/local/rabbitmq-c-0.7.1要跟上面rabbitmq-c安装的地址一样

make && make install

然后打开/etc/php.ini

添加配置:

extension=amqp.so

重启php,phpinfo就可以看到配置了

到这里就完成了,之前找了很多资料就会报错,唯有这个方式没有问题,我的linux是centos6,php版本5.4和7都安装通过了。

参考资料:https://www.phpsong.com/2223.html