[입 개발] RabbitMQ 설치하기 for CentOS 6.5

1. OS: Centos 6.5
2. 설치
– erlang(EPEL)
-> wget -O /etc/yum.repos.d/epel-erlang.repo http://repos.fedorapeople.org/repos/peter/erlang/epel-erlang.repo
-> yum install erlang

– rabbitmq
-> http://www.rabbitmq.com/install-rpm.html
-> http://www.rabbitmq.com/releases/rabbitmq-server/v3.3.4/rabbitmq-server-3.3.4-1.noarch.rpm
-> sudo rpm -Uvh rabbitmq-server-3.3.4-1.noarch.rpm

3. 설정
– /etc/hosts 호스트를 등록한다.
– /etc/rabbitmq/rabbitmq.config

[
   {mnesia, [{dump_log_write_threshold, 1000}]},
   {rabbit, [
       {tcp_listeners, [5672]},
        {log_levels, [{connection, info}]}
   ]},
   {rabbitmq_management, [
       {listener,[{port, 55672}]},
       {redirect_old_port, false}
   ]}
 ].

– .erlang.cookie 설정(/var/lib/rabbitmq/.erlang.cookie)
-> 동일하게 맞춘다.

4. rabbitmq 설정(rabbit1, rabbit2 서버 두대인 경우)
– rabbit1> sudo service rabbitmq-server start
– rabbit2> sudo service rabbitmq-server start
– rabbit2> sudo rabbitctl stop_app
– rabbit2> sudo rabbitmqctl join_cluster –ram rabbit@indigo117
– rabbit2> sudo rabbitmqctl change_cluster_node_type disc
– rabbit2> sudo rabbitmqctl start_app
– rabbit1> sudo rabbitmqctl cluster_status
– rabbit2> sudo rabbitmqctl cluster_status
– rabbit1> sudo rabbitmqctl set_policy ha-all “^\.” ‘{“ha-mode”:”all”}’

5. web plugin(all node)
– rabbitmq-plugins enable rabbitmq_management
– sudo service rabbitmq-server restart

6. 유저 설정
– sudo rabbitmqctl delete_user guest
– sudo rabbitmqctl add_user test 1234
– sudo rabbitmqctl set_user_tags test administrator

7. http://servername:55672/

8. example
– pip install pika

#!/usr/bin/env python
import pika

#Very Important!!!
credentials = pika.PlainCredentials("id", "password")
connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='localhost', credentials=credentials))

channel = connection.channel()
channel.queue_declare(queue='hello')

channel.basic_publish(exchange='',
                      routing_key='hello',
                      body='Hello World!')
print " [x] Sent 'Hello World!'"
connection.close()
Advertisements