聊天功能系列(一) 安装 RabbitMQ

amqp安装
wget https://github.com/alanxz/rabbitmq-c/releases/download/v0.8.0/rabbitmq-c-0.8.0.tar.gz
wget https://pecl.php.net/get/amqp-1.9.3.tgz

yum install m4 autoconf

tar xf rabbitmq-c-0.8.0.tar.gz
cd rabbitmq-c-0.8.0
./configure –prefix=/data/env/rabbitmq-c-0.8.0 && echo ok
make && echo ok
make install && echo ok
ln -sf /data/env/rabbitmq-c-0.8.0 /data/soft/rabbitmq-c

tar xf amqp-1.9.3.tgz
cd amqp-1.9.3
phpize
./configure –with-php-config=/data/soft/php/bin/php-config –with-amqp –with-librabbitmq-dir=/data/soft/rabbitmq-c/ && echo ok
make && echo ok
make install && echo ok
#在php.ini 或者扩展的配置文件里增加下面内容
; rabbitmq扩展支持
extension=amqp.so
/etc/init.d/php-fpm restart

安装rabbitmq之前需要安装erlang环境,可以用rpm包安装
从官网下载
http://www.rabbitmq.com/releases/erlang/

rabbitmq安装:
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.14/rabbitmq-server-generic-unix-3.6.14.tar.xz
tar xf rabbitmq-server-generic-unix-3.6.14.tar.xz
mv rabbitmq_server-3.6.14/ /data/env/
ln -s /data/env/rabbitmq_server-3.6.14/ /data/soft/rabbitmq
vim /etc/profile.d/path.sh # 将 /data/soft/rabbitmq/sbin 加入PATH变量
source /etc/profile.d/path.sh
rabbitmq-server -detached # 启动rabbitmq,并运行在后台
rabbitmq-plugins enable rabbitmq_management # 开启远程访问
rabbitmqctl status # 查看状态

# 添加管理员
rabbitmqctl add_user admin 123456
rabbitmqctl set_user admin administrator
rabbitmqctl set_user_tags admin administrator

# 添加监控用户
rabbitmqctl add_user monitor monitor
rabbitmqctl set_user_tags monitor monitoring

# 添加专有项目用户
rabbitmqctl add_user php php
rabbitmqctl set_user_tags php management
rabbitmqctl add_vhost phptest # 添加 vhost
rabbitmqctl set_permissions -p phptest php “.*” “.*” “.*” # 设置php用户可以在phptest上的权限

 

 

 

 

首先需要安装Erlang,因为RabbitMQ依赖Erlang

1、源码安装Erlang  (注意安装Erlang版本要与rabbitMQ 对应,能兼容 )

具体他们之间版本对应关系见:http://www.rabbitmq.com/which-erlang.html

安装依赖
yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel unixODBC-devel socat

下载 Erlang 源码包

官网地址:http://www.erlang.org/downloads  我这里下载的是 OTP 20.1 这个版本

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

解压 编译 安装到 /usr/lib/erlang 目录下。一般也可以安装 /usr/local/erlang/
tar zxf otp_src_20.1.tar.gz
cd otp_src_20.1
./configure –prefix=/usr/lib/erlang –without-javac

安装:
make
make install

配置环境变量
# vi /etc/profile

#末尾添加
#set erlang environment
ERLAND_HOME=/usr/lib/erlang
export PATH=$PATH:$ERLAND_HOME/bin

#set rabbitmq environment
export PATH=$PATH:/usr/lib/rabbitmq/bin

立即生效:source /etc/profile 或  ./etc/profile

查看版本

cd /usr/lib/erlang/bin
#erl -version
# ./erl -version
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 9.1

2、安装 rabbitMQ 3.6.14

官网下载  rabbitmq-server-3.6.14-1.el7.noarch.rpm

wget https://github.com/rabbitmq/rabbitmq-server/releases/download/rabbitmq_v3_6_14/rabbitmq-server-3.6.14-1.el7.noarch.rpm

安装:

rpm –import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
rpm -ivh –nodeps rabbitmq-server-3.6.14-1.el7.noarch.rpm

chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/mnesia/

#开启rabbitmq
# cd /usr/lib/rabbitmq/bin
# rabbitmq-server start &
# rabbitmq-plugins enable rabbitmq_management      启用管理插件
# sudo rabbitmqctl add_user dev02 WHOU0VYcTBr4PTC5J7Y0bQ==                 添加用户
# sudo rabbitmqctl set_user_tags dev02 administrator     设置管理员权限
# sudo rabbitmqctl set_permissions -p / dev02 “.*” “.*” “.*”

打开防火墙:
firewall-cmd –zone=public –add-port=4369/tcp –permanent
firewall-cmd –zone=public –add-port=5672/tcp –permanent
firewall-cmd –zone=public –add-port=15672/tcp –permanent
firewall-cmd –zone=public –add-port=25672/tcp –permanent

firewall-cmd –reload

systemctl start rabbitmq-server

管理界面查看: http://ip:15672/#/

Leave a Comment

电子邮件地址不会被公开。 必填项已用*标注