Installing rabbitMQ under liunx and its extension

Posted by rocketsprocket on Wed, 08 May 2019 12:20:03 +0200

Install RabbitMQ

Install Erlang

Erlang dependency libraries:

GCC Compile and use
Ncurses Can be in Linux A Library for Writing Character User Interface in Terminals
OpenSSL It is a powerful secure socket layer cryptographic library, including the main cryptographic algorithms, commonly used key and certificate encapsulation management functions, and SSL Protocols and rich applications for testing or other purposes.
yum -y install make gcc gcc-c++ kernel-devel ncurses-devel openssl openssl-devel

Compile and install Erlang:

    cd /usr/local/src
    wget -c http://www.erlang.org/download/otp_src_R16B03.tar.gz
    tar -xzvf ./otp_src_R16B03.tar.gz
    cd ./otp_src_R16B03
    ./configure --prefix=/usr/local/erlang --with-ssl -enable-threads -enable-smmp-support -enable-kernel-poll --enable-hipe --without-javac
    make && make install
 Configuring environment variables
vim /etc/profile
 # Add the following:
export PATH=$PATH:/usr/local/erlang/bin
 Make it effective
source /etc/profile

Install RabbitMQ

* Have you ever encountered the need to synchronize certain data between two (or more) systems through timing tasks? Are you struggling with the problem of calling and communicating between different processes in heterogeneous systems? If so, congratulations. Message service makes it easy for you to solve these problems. Message service is good at solving the problem of data exchange (message notification/communication) between multi-system and heterogeneous systems. You can also use it for the mutual invocation of services between systems (RPC). RabitMQ, which will be introduced in this article, is one of the most popular message middleware. 
AMQP, Advanced Message Queuing Protocol, advanced message queuing protocol, is an open standard of application layer protocol, designed for message-oriented middleware. Message middleware is mainly used for decoupling between components. The sender of the message does not need to know the existence of the message user, and vice versa. 
The main features of AMQP are message-oriented, queue-oriented, routing (including point-to-point and publish/subscribe), reliability and security. 
RabbitMQ is an open source AMQP implementation. The server side is written in Erlang language. It supports a variety of clients, such as Python, Ruby,. NET, Java, JMS, C, PHP, ActionScript, XMPP, STOMP and so on. It supports AJAX. Used for storing and forwarding messages in distributed systems, it has good performance in ease of use, scalability, high availability and so on. The website has various language tutorials and sample codes at http://www.rabbitmq.com/. 
Installation dependency 
The xmlto package is an XSL tool chain at the front end. It chooses the appropriate style sheet for the transformation you need and applies it using an external XSLT processor. It also performs any necessary post-processing. *
yum -y install xmlto
cd /usr/local/src
wget -c http://www.rabbitmq.com/releases/rabbitmq-server/v3.4.3/rabbitmq-server-3.4.3.tar.gz
tar -xzvf ./rabbitmq-server-3.4.3.tar.gz``
cd rabbitmq-server-3.4.3``
make
make install TARGET_DIR=/usr/local/rabbitmq SBIN_DIR=/usr/local/rabbitmq/sbin MAN_DIR=/usr/local/rabbitmq/man DOC_INSTALL_DIR=/usr/local/rabbitmq/doc

Setting up log and message persistence directories

mkdir /var/log/rabbitmq
mkdir /var/lib/rabbitmq
ln -s /usr/local/rabbitmq/sbin/rabbitmq-server /usr/bin/rabbitmq-server
ln -s /usr/local/rabbitmq/sbin/rabbitmq-env /usr/bin/rabbitmq-env
ln -s /usr/local/rabbitmq/sbin/rabbitmqctl /usr/bin/rabbitmqctl

Operation command

Rabbitmq-server start & start rabbitmq 
rabbitmqctl status view status 
rabbitmqctl stop closes rabbitmq 

Add daemon scripts

vi /etc/init.d/rabbitmq-server

Add the following

#!/bin/sh
 #
 # rabbitmq-server RabbitMQ broker
 #
 # chkconfig: - 80 05
 # description: Enable AMQP service provided by RabbitMQ
 #
 ### BEGIN INIT INFO
 # Provides:          rabbitmq-server
 # Required-Start:    $remote_fs $network
 # Required-Stop:     $remote_fs $network
 # Description:       RabbitMQ broker
 # Short-Description: Enable AMQP service provided by RabbitMQ broker
 ### END INIT INFO
 # Source function library.
 . /etc/rc.d/init.d/functions

 export HOME=/root
 PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/erlang/bin
 NAME=rabbitmq-server
 DAEMON=/usr/local/rabbitmq/sbin/${NAME}
 CONTROL=/usr/local/rabbitmq/sbin/rabbitmqctl
 DESC=rabbitmq-server
 USER=root
 INIT_LOG_DIR=/var/log/rabbitmq
 PID_FILE=/var/run/rabbitmq/pid

 START_PROG="daemon"
 LOCK_FILE=/var/lock/subsys/$NAME

 test -x $DAEMON || exit 0
 test -x $CONTROL || exit 0

 RETVAL=0
 set -e

 [ -f /etc/default/${NAME} ] && . /etc/default/${NAME}

 ensure_pid_dir () {
     PID_DIR=`dirname ${PID_FILE}`
     if [ ! -d ${PID_DIR} ] ; then
         mkdir -p ${PID_DIR}
         chown -R ${USER}:${USER} ${PID_DIR}
         chmod 755 ${PID_DIR}
     fi
 }

 remove_pid () {
     rm -f ${PID_FILE}
     rmdir `dirname ${PID_FILE}` || :
 }

 start_rabbitmq () {
     status_rabbitmq quiet
     if [ $RETVAL = 0 ] ; then
         echo RabbitMQ is currently running
     else
         RETVAL=0
         ensure_pid_dir
         set +e
         RABBITMQ_PID_FILE=$PID_FILE $START_PROG $DAEMON \
             > "${INIT_LOG_DIR}/startup_log" \
             2> "${INIT_LOG_DIR}/startup_err" \
             0<&- &
         $CONTROL wait $PID_FILE >/dev/null 2>&1
         RETVAL=$?
         set -e
         case "$RETVAL" in
             0)
                 echo SUCCESS
                 if [ -n "$LOCK_FILE" ] ; then
                     touch $LOCK_FILE
                 fi
                 ;;
             *)
                 remove_pid
                 echo FAILED - check ${INIT_LOG_DIR}/startup_\{log, _err\}
                 RETVAL=1
                 ;;
         esac
     fi
 }

 stop_rabbitmq () {
     status_rabbitmq quiet
     if [ $RETVAL = 0 ] ; then
         set +e
         $CONTROL stop ${PID_FILE} > ${INIT_LOG_DIR}/shutdown_log 2> ${INIT_LOG_DIR}/shutdown_err
         RETVAL=$?
         set -e
         if [ $RETVAL = 0 ] ; then
             remove_pid
             if [ -n "$LOCK_FILE" ] ; then
                 rm -f $LOCK_FILE
             fi
         else
             echo FAILED - check ${INIT_LOG_DIR}/shutdown_log, _err
         fi
     else
         echo RabbitMQ is not running
         RETVAL=0
     fi
 }

 status_rabbitmq() {
     set +e
     if [ "$1" != "quiet" ] ; then
         $CONTROL status 2>&1
     else
         $CONTROL status > /dev/null 2>&1
     fi
     if [ $? != 0 ] ; then
         RETVAL=3
     fi
     set -e
 }

 rotate_logs_rabbitmq() {
     set +e
     $CONTROL rotate_logs ${ROTATE_SUFFIX}
     if [ $? != 0 ] ; then
         RETVAL=1
     fi
     set -e
 }

 restart_running_rabbitmq () {
     status_rabbitmq quiet
     if [ $RETVAL = 0 ] ; then
         restart_rabbitmq
     else
         echo RabbitMQ is not runnning
         RETVAL=0
     fi
 }

 restart_rabbitmq() {
     stop_rabbitmq
     start_rabbitmq
 }

 if  [ ! -d $INIT_LOG_DIR ]; then   
     mkdir $INIT_LOG_DIR
 fi

 case "$1" in
     start)
         echo -n "Starting $DESC: "
         start_rabbitmq
         echo "$NAME."
         ;;
     stop)
         echo -n "Stopping $DESC: "
         stop_rabbitmq
         echo "$NAME."
         ;;
     status)
         status_rabbitmq
         ;;
     rotate-logs)
         echo -n "Rotating log files for $DESC: "
         rotate_logs_rabbitmq
         ;;
     force-reload|reload|restart)
         echo -n "Restarting $DESC: "
         restart_rabbitmq
         echo "$NAME."
         ;;
     try-restart)
         echo -n "Restarting $DESC: "
         restart_running_rabbitmq
         echo "$NAME."
         ;;
     *)
         echo "Usage: $0 {start|stop|status|rotate-logs|restart|condrestart|try-restart|reload|force-reload}" >&2
         RETVAL=1
         ;;
 esac

 exit $RETVAL

Add to the service and set boot start

chmod +x /etc/init.d/rabbitmq-server
chkconfig --add rabbitmq-server
chkconfig rabbitmq-server on

Install Web Plug-in Management Interface

cd /usr/local/rabbitmq/sbin 
mkdir /etc/rabbitmq 
./rabbitmq-plugins enable rabbitmq_management

View Plug-in List

./rabbitmq-plugins list

Use browser access on the server http://127.0.0.1:15672
Login, default username and password are guest, login success!
Browser access http://192.168.0.28:15672 In case of inaccessibility.
Open Firewall Port:

iptables -I INPUT -p tcp -m tcp --dport 15672 -j ACCEPT 
iptables -I INPUT -p tcp -m tcp --dport 5672 -j ACCEPT 
service iptables save 
service iptables restart 

Enter username password guest/guest found unable to log in
You can't log in as guest/guest after rabbitmq 3.3.0.
Two Solutions
- Change file configuration
- Copy the default configuration: cp/usr/local/rabbitmq/doc/rabbitmq.config.example/etc/rabbitmq/
- Modify the configuration file name: cd/etc/rabbitmq; MV rabbitmq.config.example rabbitmq.config
- Edit the configuration file to open remote user access: vim rabbitmq.config
- In line 64, the default sentence is:%{loopback_users,[<"guest"]], note that there is a comma at the end of the statement, and we need to change it to {loopback_users,[]} to remove it later.

- rabbitmqctl stop 
- rabbitmq-server start

To add users and privileges:

rabbitmqctl add_user test test 
rabbitmqctl set_user_tags test administrator 
rabbitmqctl set_permissions -p / test ".*" ".*" ".*" 

Username / password created: test/test
Finally successfully logged in

Use of Web Plug-ins

Adding new authorized users

Add Host (as shown below)

Set permissions for the added Host (as shown in the figure below)

Switch binding queues (as shown in the figure below)

Install the RabbitMQ extension

Install PHP Extension amqp
cd /usr/local/src 
wget http://pecl.php.net/get/amqp-1.9.1.tgz 
tar zxvf amqp-1.9.1.tgz 
cd amqp-1.9.1 
/usr/local/php/bin/phpize 

Error messages may occur

FATAL ERROR: Autoconf version 2.59 or higher is required for this script

Delete the old rpm-e-nodeps autoconf version autoconf

cd /usr/local/src 
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz 
tar -xzf autoconf-2.69.tar.gz 
cd autoconf-2.69 
./configure 
make && make install

Installing rabbitmq-c dependency packages

yum install autoconf automake libtool 
cd /usr/local/src 
wget https://codeload.github.com/alanxz/rabbitmq-c/tar.gz/master -O rabbitmq-c.tar.gz 
tar zxvf rabbitmq-c.tar.gz 
cd rabbitmq-c-master 
autoreconf -i 
#If there is a problem at this point, the rabbitmq-c above has a problem.
//Go to https://github.com/alanxz/rabbitmq-c Download here
./configure --prefix=/usr/local/rabbitmq-c

The results are as follows:
rabbitmq-c build options:
Host: x86_64-unknown-linux-gnu
Version: 0.8.1
SSL/TLS: openssl
Tools: no
Documentation: no
Examples: yes

make && make install

Install amqp extensions

cd /usr/local/src 
wget https://pecl.php.net/get/amqp-1.8.0.tgz 
tar zxvf amqp-1.8.0.tgz 
cd amqp-1.8.0 
/usr/local/php/bin/phpize
cd /usr/local/src/amqp-1.8.0 
/usr/local/php/bin/phpize 
./configure --with-php-config=/usr/local/php/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c/      
#php-configAccording to their actual situation can be used find Command to find the location of this file
make && make install 

Increase php configuration

vim /usr/local/php/etc/php.ini 

increase
[rabbitmq]

extension=amqp.so 

If you can't add extensions above, please refer to the following methods to add extensions:
After making install above, there should be an amqp.so file under / usr/lib64/php/modules /.

cd /etc/php.d/

New file amqp.ini, as follows:

;amqp extension module
extension=amqp.so

restart

service httpd restart 

perhaps

service php-fpm restart

php -m View Extensions

amqp #amqp extension
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
json
ldap
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
swoole
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

Topics: RabbitMQ PHP Erlang OpenSSL