OpenSource

RabbitMQ Multi Intance on Single Machine

아르비스 2015. 6. 15. 14:59

하나의 Machine에서 RabbitMq Multi Instance로 띄우기


Multi Node 아님



[rabbitmq 설치]

1. proxy 설정 (사내망 서버일 경우)

2. yum daum 사이트 추가 (ftp.daum.net : 117.52.11.181)

/etc/yum.repos.d/Daum.repo

[daum_base]

name=CentOS-$releasever - Base

baseurl=http://ftp.daum.net/centos/$releasever/os/$basearch/

gpgcheck=0

enabled=1

[daum_updates]

name=CentOS-$releasever - Updates

baseurl=http://ftp.daum.net/centos/$releasever/updates/$basearch/

gpgcheck=0

enabled=1

[daum_extras]

name=CentOS-$releasever - Extras

baseurl=http://ftp.daum.net/centos/$releasever/extras/$basearch/

gpgcheck=0

enabled=1

3. erlang 설치 (pacakges.erlang-solutions.com : 31.172.186.53)

/etc/yum.repos.d/erlang_solutions.repo

[erlang]

name=Centos $releasever - $basearch - Erlang Solutions

baseurl=http://packages.erlang-solutions.com/rpm/centos/$releasever/$basearch

gpgcheck=0

gpgkey=http://packages.erlang-solutions.com/debian/erlang_solutions.asc

enabled=1

4. rabbitmq 설치

yum install erlang

yum install rabbitmq-server-3.3.4-1.noarch.rpm

5. rabbitmq 설정

vi /etc/rabbitmq/rabbitmq-env.conf

#rabbitmq-env.conf

#Host Name

HOSTNAME=cl-EFSS-linux20

#Node Name

NODENAME=rabbit@cl-EFSS-linux20

RABBITMQ_NODE_PORT=5672

RABBITMQ_MNESIA_BASE=/block/dbfiles

RABBITMQ_LOG_BASE=/block/logs/rabbitmq

 

5-1. folder 생성

 $ mkdir /block/dbfiles

 $ chown –R rabbitmq.rabbitmq /block/dbfiles

 

 $ mkdir /block/logs/rabbitmq

 $ chown –R rabbitmq.rabbitmq /block/logs/rabbitmq

 

6. 기동 : service rabbitmq-server start

7. management plugin 설치

  rabbitmq-plugins list

  rabbitmq-plugins enable rabbitmq_management

8. 계정 생성 (Script로 대체)

rabbitmqctl add_user rabbitmq rabbit123

rabbitmqctl set_user_tags rabbitmq administrator

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

 

--- efss 계정은 아래 script에서 추가 가능함

rabbitmqctl add_user efss efss00

rabbitmqctl set_user_tags efss monitoring

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

 

9. rabbitmq clustering

 - /etc/host server, host 등록

 - cookie 복제 (1번 서버 .erlang.cookie 내용을 2 서버에 복제)

 - 2 서버에서 실행

rabbitmqctl stop_app

rabbitmqctl join_cluster rabbit@cl-EFSS-linux20

rabbitmqctl start_app

 

10. mirrored queue 설정 (script로 대체)

 - rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all"}'

 

 

 

<RabbitMQ multi Instance>

 

1.  Verify configuration

config file(s) : /etc/rabbitmq/rabbitmq.config

 

/etc/rabbitmq/ * /etc/rabbitmq2/  (3) 로 복사

>vi rabbitmq-env.conf

#rabbitmq-env.conf

RABBITMQ_NODE_PORT=5672   (6672, 7672)

RABBITMQ_DIST_PORT=25672

 

RABBITMQ_MNESIA_BASE=/block/dbfiles  (/block/rabbitmq/dbfiles2,  /block/rabbitmq/dbfiles3 )

RABBITMQ_LOG_BASE=/block/logs/rabbitmq  (/block/logs/rabbitmq2, /block/logs/rabbitmq3)

 

RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,16672}]"

 

 

 

- block 추가

Mkdir /block/rabbitmq/dbfile2  (3)

Mkdir /block/logs/rabbitmq2  (3)

 

 

Cd /usr/lib/rabbitmq/lib/rabbitmq_server-3.4.4/

Cp –rf sbin/* sbin2

Cd sbin2

vi rabbitmq-defaults

#/etc/rabbitmq/  à /etc/rabbtmq2/ 로변경

 

CONFIG_FILE=${SYS_PREFIX}/etc/rabbitmq2/rabbitmq

LOG_BASE=${SYS_PREFIX}/block/log/rabbitmq2

MNESIA_BASE=${SYS_PREFIX}/var/lib/rabbitmq/mnesia

ENABLED_PLUGINS_FILE=${SYS_PREFIX}/etc/rabbitmq2/enabled_plugins

 

PLUGINS_DIR="${RABBITMQ_HOME}/plugins"

 

CONF_ENV_FILE=${SYS_PREFIX}/etc/rabbitmq2/rabbitmq-env.conf

 

 

Cd /usr/local/bin 에 아래 파일 추가

Vi start_rabbitmq_6672.sh  (5672/6672/7672)

#!/bin/sh

 

#set -xv

 

export NA=rabbit2

export PT=6672

PID=`ps -eaf | grep $NA | grep $PT | grep -v grep | awk '{print $2}'`

 

if [[ $PID != '' ]]; then

    echo

    echo "$NA $PT is running as $PID"

    echo

    exit

fi

 

/usr/lib/rabbitmq/lib/rabbitmq_server-3.4.4/sbin2/rabbitmq-server –detached

 

 

Vi stop_rabbitmq_6672.sh  (5672/6672/7672)

#!/bin/sh

export NA=rabbit2

export PT=6672

if [ -z "`ps -eaf | grep $NA | grep $PT | grep -v grep`" ]; then

       echo "RabbitMQ was not started."

else

       ps -eaf | grep $NA | grep $PT | grep -v grep | awk '{print $2}' |

       while read PID

               do

               echo "Killing $PID ..."

               kill -9 $PID

               echo

               echo "RabbitMQ is shutdowned."

               done

fi

 

 

 

<rabbitmqadmin 설치>

$cd /usr/local/bin/

# Get the cli and make it available to use.

wget http://127.0.0.1:15672/cli/rabbitmqadmin

$chmod 775 rabbitmqadmin

$mv rabbitmqadmin /usr/local/bin

 

<script 생성>

$ vi rabbitmq_init.sh

#!/bin/sh

 

./rabbitmqadmin declare exchange name=DRM.Processing type=direct

./rabbitmqadmin declare exchange name=Event.Processing type=fanout

./rabbitmqadmin declare exchange name=File.ConvertProcessing type=direct

./rabbitmqadmin declare exchange name=File.Logging type=direct

./rabbitmqadmin declare exchange name=File.Processing type=fanout

./rabbitmqadmin declare exchange name=File.SearchProcessing type=direct

./rabbitmqadmin declare exchange name=File.TypeProcessing type=direct

./rabbitmqadmin declare exchange name=Post.ErrorProcessing type=direct

./rabbitmqadmin declare exchange name=Post.RetryProcessing type=direct

 

./rabbitmqadmin declare queue name=DRM.DecryptQueue durable=true

./rabbitmqadmin declare queue name=Event.FeedQueue durable=true

./rabbitmqadmin declare queue name=Event.NotiQueue durable=true

./rabbitmqadmin declare queue name=File.ConvertQueue durable=true

./rabbitmqadmin declare queue name=File.LogQueue durable=true

./rabbitmqadmin declare queue name=File.SearchQueue durable=true

./rabbitmqadmin declare queue name=File.TypeCheckingQueue durable=true

./rabbitmqadmin declare queue name=Post.ErrorQueue durable=true

./rabbitmqadmin declare queue name=Post.RetryQueue durable=true

 

./rabbitmqadmin declare binding source="DRM.Processing" destination_type="queue" destination="DRM.DecryptQueue"

./rabbitmqadmin declare binding source="Event.Processing" destination_type="queue" destination="Event.FeedQueue"

./rabbitmqadmin declare binding source="Event.Processing" destination_type="queue" destination="Event.NotiQueue"

./rabbitmqadmin declare binding source="File.ConvertProcessing" destination_type="queue" destination="File.ConvertQueue"

./rabbitmqadmin declare binding source="File.Logging" destination_type="queue" destination="File.LogQueue"

./rabbitmqadmin declare binding source="File.Processing" destination_type="queue" destination="File.ConvertQueue"

./rabbitmqadmin declare binding source="File.Processing" destination_type="queue" destination="File.SearchQueue"

./rabbitmqadmin declare binding source="File.SearchProcessing" destination_type="queue" destination="File.SearchQueue"

./rabbitmqadmin declare binding source="File.TypeProcessing" destination_type="queue" destination="File.TypeCheckingQueue"

./rabbitmqadmin declare binding source="Post.ErrorProcessing" destination_type="queue" destination="Post.ErrorQueue"

./rabbitmqadmin declare binding source="Post.RetryProcessing" destination_type="queue" destination="Post.RetryQueue"

 

./rabbitmqadmin -u efss -p simon list vhosts

 

rabbitmqctl add_user rabbitmq rabbit123

rabbitmqctl set_user_tags rabbitmq administrator

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

 

 

rabbitmqctl add_user efss efss00

rabbitmqctl set_user_tags efss monitoring

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

 

rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all"}'

 

 

 

<삭제 :>

yum remove rabbitmq-server

yum remove erlang