CentOS Installation RABBITMQ
1, RABBITMQ is the Erlang language development, before installing the first need to install Erlang
# yum Install erlang-y//Direct installation may be an error,
# yum Install Ncurses-devel//installation dependent
Official Download Erlang Package
# wget http://erlang.org/download/otp_src_19.0.tar.gz
Unzip and install Erlang
# tar XZVF otp_src_19.0.tar.gz
# CD otp_src_19.0
#./configure
# Make && make install
After the installation is complete, test run:
#erl
1>1+2.
3
2>halt (). Exit
2, install Rabbitmq,yum installation
# RPM-UVH http://mirrors.sohu.com/fedora-epel/5/x86_64/epel-release-5-4.noarch.rpm
# RPM--import HTTP://WWW.RABBITMQ.COM/RABBITMQ-SIGNING-KEY-PUBLIC.ASC
# yum Install rabbitmq-server-y
Official Download: wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.5/rabbitmq-server-3.6.5.zip
Unzip the installation
# tar XZVF rabbitmq-server-3.6.5.zip
# CD rabbitmq-server-3.6.5
# make
# make TARGET_DIR=/USR/LOCAL/RABBITMQ sbin_dir=/usr/local/rabbitmq/sbin man_dir=/usr/rabbitmq/man DOC_INSTALL_DIR=/ Usr/local/rabbitmq/doc Install
3. After the installation is complete, the configuration is required:
/usr/local/rabbitmq/sbin Directory File Description:
RABBITMQ-ENV//Environment configuration
Rabbitmq-defaults//default parameter settings
RABBITMQCTL//Management tools
Rabbitmq-plugins//plug-in management tools
Rabbitmq-server//RABBITMQ Service
3.1. Add a custom configuration file
rabbitmq_node_ip_address=192.168.2.2//Custom address
rabbitmq_node_port=3333//Custom port number
3.2. Start:
# rabbitmq-server-detached
Error: ERROR:EPMD error for Host ' Bogon ': timeout (timed out)
Modify/etc/hosts
127.0.0.1 Bogon
Reboot.
3.3. Enable the RABBITMQ Web management plug-in and install the Sbin directory:
./rabbitmq-plugins Enable Rabbitmq_management
Then restart Rabbitmq-server
Sign in to the Web Administration page
http://192.168.2.2:15672
Login User: Guest/guest
3.4. List all plugins
#./rabbitmq-plugins List
3.5, install PHP RABBITMQ extension:
# yum Install Librabbitmq-devel.x86_64-y
# wget Http://pecl.php.net/get/amqp-1.7.1.tgz
# tar ZXVF amqp-1.7.1.tgz
# CD amqp-1.7.1
#/usr/local/php/bin/phpize
#./configure--with-php-config=/usr/local/php/bin/php-config--WITH-AMQP
# make
# make Install
# Vim/usr/local/php/etc/php.ini
Extension=amqp.so
Restart PHP-FPM
#/usr/local/php/sbin/php-fpm-y/usr/local/php/etc/php-fpm.conf
PHP Operation Demo
1. Create a queue
<?php
Connection RABBITMQ
$conn _args = Array (' host ' = ' 192.168.2.2 ', ' port ' = ' 3333 ', ' login ' = ' guest ', ' password ' = ' guest ', ' Vhost ' = '/');
$conn = new \amqpconnection ($conn _args);
$conn->settimeout (1);
$conn->connect ();
Create Exchange name and type
$channel = new \amqpchannel ($conn);
$ex = new \amqpexchange ($channel);
$ex->setname (' Ttlsa_exchange ');
$ex->settype (Amqp_ex_type_direct);
$ex->setflags (amqp_durable | Amqp_autodelete);
$ex->declare ();
Create a queue name, use Exchange, bind Routingkey
$q = new \amqpqueue ($channel);
$q->setname (' Ttlsa_queue ');
$q->setflags (amqp_durable | Amqp_autodelete);
$q->declare ();
$q->bind (' Ttlsa_exchange ', ' Ttlsa_routingkey ');
Message Publishing
$channel->starttransaction ();
$message = Json_encode (Array (' Hello world! ', ' DIRECT '));
$ex->publish ($message, ' Ttlsa_routingkey ');
$channel->committransaction ();
$conn->disconnect ();
?>
2. Get Queue information:
<?php
Connection RABBITMQ
$conn _args = Array (' host ' = ' 192.168.2.2 ', ' port ' = ' 3333 ', ' login ' = ' guest ', ' password ' = ' guest ', ' Vhost ' = '/');
$conn = new \amqpconnection ($conn _args);
$conn->connect ();
Set the queue name, use Exchange, bind Routingkey
$channel = new \amqpchannel ($conn);
$q = new \amqpqueue ($channel);
$q->setname (' Ttlsa_queue ');
$q->setflags (amqp_durable | Amqp_autodelete);
$q->declare ();
$q->bind (' Ttlsa_exchange ', ' Ttlsa_routingkey ');
Message acquisition
$messages = $q->get (amqp_autoack);
if ($messages) {
Var_dump (Json_decode ($messages->getbody (), true));
}
$conn->disconnect ();
?>
CentOS Installation and Configuration RABBITMQ