centos7.5下安装rabbitmq服务端以及php扩展

 rabbitmq依赖erlang,centos7默认未安装erlang,erlang默认三种格式的安装源文件:

  • RabbitMQ提供的被剥离的包,只提供运行RabbitMQ所需的组件,官方称零依赖项,容易安装,如果Erlang只是用来提供运行RabbitMQ的,推荐使用。
  • Erlang官方提供的包,安装时需要安装依赖多,如果还需要Erlang做相关开发或运行环境,使用该包
  • EPEL源提供的包,但该包版本过低,不使用该方法下载安装

 

这里仅用来运行rabbitmq,选择零依赖项的rpm二进制文件包即可。

[root@guangzhou src]# wget https://bintray.com/rabbitmq-erlang/rpm/download_file?file_path=erlang%2F19%2Fel%2F7%2Fx86_64%2Ferlang-19.3.6.13-1.el7.centos.x86_64.rpm
[root@guangzhou src]# mv download_file\?file_path\=erlang%2F19%2Fel%2F7%2Fx86_64%2Ferlang-19.3.6.13-1.el7.centos.x86_64.rpm erlang-19.3.6.13-1.el7.centos.x86_64.rpm
[root@guangzhou src]# rpm -ivh erlang-19.3.6.13-1.el7.centos.x86_64.rpm
#查看erlang版本
[root@guangzhou src]# erl -version
Erlang (ASYNC_THREADS,HIPE) (BEAM) emulator version 8.3.5.7

 

erlang安装成功,再安装rabbitmq-server:

#安装rabbitmq之前需要安装socat服务,依然下载二进制安装包
[root@guangzhou src]# wget http://repo.iotti.biz/CentOS/7/x86_64/socat-1.7.3.2-5.el7.lux.x86_64.rpm
[root@guangzhou src]# rpm -ivh socat-1.7.3.2-5.el7.lux.x86_64.rpm

#开始安装rabbitmq-server
root@guangzhou src]# wget https://github.com/rabbitmq/rabbitmq-server/releases/download/rabbitmq_v3_6_16/rabbitmq-server-3.6.16-1.el6.noarch.rpm
[root@guangzhou src]# rpm -ivh rabbitmq-server-3.6.16-1.el6.noarch.rpm
#安装成功运行服务
[root@guangzhou src]# rabbitmq-server

              RabbitMQ 3.6.16. Copyright (C) 2007-2018 Pivotal Software, Inc.
  ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
  ##  ##
  ##########  Logs: /var/log/rabbitmq/rabbit@guangzhou.log
  ######  ##        /var/log/rabbitmq/rabbit@guangzhou-sasl.log
  ##########
              Starting broker...
 completed with 0 plugins.

[root@guangzhou src]# systemctl status rabbitmq-server
● rabbitmq-server.service - LSB: Enable AMQP service provided by RabbitMQ broker
   Loaded: loaded (/etc/rc.d/init.d/rabbitmq-server; bad; vendor preset: disabled)
   Active: active (running) since 四 2020-01-30 10:50:27 CST; 6s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 31677 ExecStart=/etc/rc.d/init.d/rabbitmq-server start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/rabbitmq-server.service
           ├─31894 /bin/sh /etc/rc.d/init.d/rabbitmq-server start
           ├─31912 /bin/bash -c ulimit -S -c 0 >/dev/null 2>&1 ; /usr/sbin/rabbitmq-server
           └─31913 /bin/sh /usr/sbin/rabbitmq-server

1月 30 10:50:22 guangzhou systemd[1]: Starting LSB: Enable AMQP service provided by RabbitMQ broker...
1月 30 10:50:22 guangzhou su[31763]: (to rabbitmq) root on none
1月 30 10:50:23 guangzhou su[31909]: (to rabbitmq) root on none
1月 30 10:50:23 guangzhou su[31927]: (to rabbitmq) root on none
1月 30 10:50:27 guangzhou rabbitmq-server[31677]: Starting rabbitmq-server: SUCCESS
1月 30 10:50:27 guangzhou systemd[1]: Started LSB: Enable AMQP service provided by RabbitMQ broker.
1月 30 10:50:27 guangzhou rabbitmq-server[31677]: rabbitmq-server.

 

查看rabbitmq-server运行状态

systemctl status rabbitmq-server

启动rabbitmq-server服务

systemctl start rabbitmq-server

加入开机启动

systemctl enable rabbitmq-server

停止rabbitmq-server服务

systemctl stop rabbitmq-server

禁止开机启动

systemctl disable rabbitmq-server

是否允许开机启动

systemctl is-enabled rabbitmq-server

 

开启web后台管理插件

[root@guangzhou src]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  amqp_client
  cowlib
  cowboy
  rabbitmq_web_dispatch
  rabbitmq_management_agent
  rabbitmq_management

Applying plugin configuration to rabbit@guangzhou... started 6 plugins.

#查看rabbitmq-server监听的所有插件
[root@guangzhou src]# rabbitmqctl status|grep list
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"},{http,15672,"::"}]},

#其中第三个的端口15672,这是rabbitmq_management插件监听的端口

#查看已所有开放的端口(centos7默认由firewalld控制端口)
[root@guangzhou src]# firewall-cmd --zone=public --list-ports
FirewallD is not running
[root@guangzhou src]#  systemctl start firewalld
#可见未开放任何端口
[root@guangzhou src]# firewall-cmd --zone=public --list-ports

#开放15672端口给浏览器访问用
[root@guangzhou src]# firewall-cmd --zone=public --add-port=15672/tcp --permanent
success
[root@guangzhou src]# firewall-cmd --zone=public --add-port=5672/tcp --permanent
success
[root@guangzhou src]# firewall-cmd --reload
success
[root@guangzhou src]# firewall-cmd --zone=public --list-ports
15672/tcp 5672/tcp
[root@guangzhou src]#

#浏览器中输入 http://服务器IP:15672 就可以看到RabbitMQ的WEB管理台

 

创建用户

#新增用户(用户名+密码)
[root@guangzhou src]# rabbitmqctl add_user admin freedom
Creating user "admin"
#为用户配置权限
[root@guangzhou src]# rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/"
#将用户设置为管理员
[root@guangzhou src]# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator]
#查看所有用户
[root@guangzhou src]# rabbitmqctl list_users
Listing users
admin    [administrator]
guest    [administrator]

 

 安装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]# 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/local/php/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/local/php/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二进制包安装进展顺利。

posted @ 2019-10-22 07:40  潮起潮落中看星辰大海  阅读(635)  评论(0编辑  收藏  举报