CentOS7安装RabbitMQ

安装erlang

由于rabbitmq是基于erlang语言开发的,所以必须先安装erlang。

yum -y install gcc glibc-devel make ncurses-devel openssl-devel xmlto perl wget gtk2-devel binutils-devel

erlang官网:

https://www.erlang.org/downloads

下载(会比较慢,请耐心等待)

wget http://erlang.org/download/otp_src_22.0.tar.gz

解压

tar -zxvf otp_src_22.0.tar.gz

移走

mv otp_src_22.0 /usr/local/

切换目录

cd /usr/local/otp_src_22.0/

创建即将安装的目录

mkdir ../erlang

配置安装路径

./configure --prefix=/usr/local/erlang

如果遇到这个错 你就假装没看到

CentOS7安装RabbitMQ_第1张图片

安装

make install

查看一下是否安装成功

ll /usr/local/erlang/bin

添加环境变量

echo 'export PATH=$PATH:/usr/local/erlang/bin' >> /etc/profile

刷新环境变量

source /etc/profile

甩一条命令

erl

瞬间进入了一个未知的世界

在里面输入halt().命令退出来(那个点号别忘记)

CentOS7安装RabbitMQ_第2张图片

安装RabbitMQ

rabbitmq下载地址:

https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.7.15

下载

wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.15/rabbitmq-server-generic-unix-3.7.15.tar.xz

解压

tar xvJf rabbitmq-server-generic-unix-3.7.15.tar.xz

移走

mv rabbitmq_server-3.7.15/ /usr/local/

改名

mv /usr/local/rabbitmq_server-3.7.15  rabbitmq

配置环境变量

echo 'export PATH=$PATH:/usr/local/rabbitmq/sbin' >> /etc/profile

刷新环境变量

source /etc/profile

创建配置目录

mkdir /etc/rabbitmq

启动命令

启动:

rabbitmq-server -detached

停止:

rabbitmqctl stop

状态:

rabbitmqctl status

防火墙之类的请自行处理(5672和15672端口),反正我是从来不开防火墙。

WEB管理

开启web插件

rabbitmq-plugins enable rabbitmq_management

访问:http://127.0.0.1:15672/

CentOS7安装RabbitMQ_第3张图片

默认账号密码:guest guest(这个账号只允许本机访问)

用户管理

查看所有用户

rabbitmqctl list_users

添加一个用户

rabbitmqctl add_user zhaobl 123456

配置权限

rabbitmqctl set_permissions -p "/" zhaobl ".*" ".*" ".*"

查看用户权限

rabbitmqctl list_user_permissions zhaobl

设置tag

rabbitmqctl set_user_tags zhaobl administrator

删除用户(安全起见,删除默认用户)

rabbitmqctl delete_user guest

登陆

配置好用户之后重启一下rabbit

然后就可以用新账号进行登陆

CentOS7安装RabbitMQ_第4张图片

安装php扩展

安装rabbitmq客户端

[root@guangzhou src] wget https://github.com/alanxz/rabbitmq-c/archive/v0.9.0.tar.gz
[root@guangzhou src] mv v0.9.0.tar.gz rabbitmq-c-v0.9.0.tar.gz
[root@guangzhou src] tar -zxvf rabbitmq-c-v0.9.0.tar.gz
[root@guangzhou src] cd rabbitmq-c-0.9.0/
[root@guangzhou rabbitmq-c-0.9.0] mkdir build && cd build
#当cmake根据rabbitmq-c的根目录下的CMakeList.txt创建Makefile文件时,会将Makefile文件放进build目录
[root@guangzhou build] yum install cmake
[root@guangzhou build] cmake .. 
[root@guangzhou build] cd .. 
[root@guangzhou rabbitmq-c-0.9.0] cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rabbitmq-c-0.9.0
[root@guangzhou rabbitmq-c-0.9.0] cmake --build . --target install

安装rabbitmq的php扩展

[root@guangzhou src] wget http://pecl.php.net/get/amqp-1.9.4.tgz
[root@guangzhou src] tar -zxvf amqp-1.9.4.tgz
[root@guangzhou src] cd amqp-1.9.4/
[root@guangzhou amqp-1.9.4] /usr/bin/phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
[root@guangzhou amqp-1.9.4] ./configure --with-php-config=/usr/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c-0.9.0
[root@guangzhou amqp-1.9.4] make
/bin/sh /usr/local/src/amqp-1.9.4/libtool --mode=link cc -DPHP_ATOM_INC -I/usr/local/src/amqp-1.9.4/include -I/usr/local/src/amqp-1.9.4/main -I/usr/local/src/amqp-1.9.4 -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/usr/local/rabbitmq-c-0.9.0/include  -DHAVE_CONFIG_H  -g -O2    -o amqp.la -export-dynamic -avoid-version -prefer-pic -module -rpath /usr/local/src/amqp-1.9.4/modules  amqp.lo amqp_type.lo amqp_exchange.lo amqp_queue.lo amqp_connection.lo amqp_connection_resource.lo amqp_channel.lo amqp_envelope.lo amqp_basic_properties.lo amqp_methods_handling.lo amqp_timestamp.lo amqp_decimal.lo -Wl,-rpath,/usr/local/rabbitmq-c-0.9.0/lib -L/usr/local/rabbitmq-c-0.9.0/lib -lrabbitmq
cc -shared  .libs/amqp.o .libs/amqp_type.o .libs/amqp_exchange.o .libs/amqp_queue.o .libs/amqp_connection.o .libs/amqp_connection_resource.o .libs/amqp_channel.o .libs/amqp_envelope.o .libs/amqp_basic_properties.o .libs/amqp_methods_handling.o .libs/amqp_timestamp.o .libs/amqp_decimal.o  -L/usr/local/rabbitmq-c-0.9.0/lib -lrabbitmq  -Wl,-rpath -Wl,/usr/local/rabbitmq-c-0.9.0/lib -Wl,-soname -Wl,amqp.so -o .libs/amqp.so
/usr/bin/ld: cannot find -lrabbitmq
collect2: error: ld returned 1 exit status
make: *** [amqp.la] 错误 1

#这里使用make命令时会报错,对rabbitmq-c-0.9.0目录创建软链指向
[root@guangzhou amqp-1.9.4]# ln -s /usr/local/rabbitmq-c-0.9.0/lib64 /usr/local/rabbitmq-c-0.9.0/lib

#再次执行make命令
[root@guangzhou amqp-1.9.4] make
[root@guangzhou amqp-1.9.4] make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/

#更改php.ini,加上extension=amqp.so
root@guangzhou etc]# vim php.ini
[root@guangzhou etc]# php --ri amqp

amqp

Version => 1.9.4
Revision => release
Compiled => Jan 30 2020 @ 17:31:44
AMQP protocol version => 0-9-1
librabbitmq version => 0.9.0
Default max channels per connection => 256
Default max frame size => 131072
Default heartbeats interval => 0

Directive => Local Value => Master Value
amqp.auto_ack => 0 => 0
amqp.cacert => no value => no value
amqp.cert => no value => no value
amqp.channel_max => 256 => 256
amqp.connect_timeout => 0 => 0
amqp.frame_max => 131072 => 131072
amqp.heartbeat => 0 => 0
amqp.host => localhost => localhost
amqp.key => no value => no value
amqp.login => guest => guest
amqp.password => guest => guest
amqp.port => 5672 => 5672
amqp.prefetch_count => 3 => 3
amqp.read_timeout => 0 => 0
amqp.sasl_method => 0 => 0
amqp.timeout => no value => no value
amqp.verify => 1 => 1
amqp.vhost => / => /
amqp.write_timeout => 0 => 0
[root@guangzhou etc]# systemctl restart php-fpm.service

至此安装完成,最开始使用yum安装erlang,走了很多坑,包括涉及和rabbitmq版本兼容的问题,一直没解决好,这里就不列出来其中艰辛过程了。后yum卸载erlang重新用rpm二进制包安装进展顺利。

你可能感兴趣的:(php)