# Ubuntu 설치 후 초기 환경 세팅

------------------------------------


1. vi 사용시 방향키 동작시 이상한 문자열이 출력된다

$ sudo apt-get update

$ sudo apt-get install vim

$ vim ~/.vimrc

                set number            # 줄 번호 표시

set tabstop=4         # tab을 4칸으로

set ignorecase      # 검색시 대소문자 구별하지 않음

set hlsearch         # 검색시 하이라이트

set fileencodings=utf-8,euc-kr    # 파일인코딩 형식

set bs=indent,eol,start    # backspace 키 사용

set ruler              # 상태표시줄 커서 위치 표시

set title               # 제목 표시

set showmatch    # 매칭되는 괄호 표시

set nowrap         # 자동 줄바꿈 해제

set wmnu           # tab 자동완성시 가능한 목록 표시


syntax on        # 문법 하이라이트

 

2. apt-get proxy 설정

$ cd /etc/apt

$ sudo vi /apt.conf

    Acquire::http::proxy "http://192.168.1.1:8080/";

$ sudo apt-get update


3. 계정 생성 및 권한 추가

- 생성

$ adduser 계정명 # 홈디렉토리를 자동으로 생성해주고 password 를 입력하게끔 command 가 나온다

- sudo 권한 부여

$ cd /etc

$ vi sudoers

  계정명 ALL=(ALL) ALL


4. 인증키 없이 password 로 ssh 접속 가능하게 설정 변경

- sshd 설치/실행

$ sudo apt-get install openssh-server

- sshd 설정

$ cd /etc/ssh/

$ sudo vi sshd_config

   ...

   PasswordAuthentication yes

   ... 


'개발' 카테고리의 다른 글

iOS custom framework 만들기  (0) 2016.11.04
Ubuntu 머신에서 다른 머신 제어하기  (0) 2016.09.09
RabbitMQ 사용하기-2  (0) 2016.09.06
RabbitMQ 사용하기-1  (0) 2016.09.05
API 모델링 및 개발 - 2  (0) 2016.09.01
Posted by 감각적신사
,

RabbitMQ 사용하기-2

개발 2016. 9. 6. 23:48

# RabbitMQ 설치하기

--------------------------------------

[참고자료](http://killins.egloos.com/3025514)


1. windows 에 RabbitMQ 설치하기

- erlang 설치

- [다운로드](http://www.erlang.org/downloads)

- 설치

                  


- 시스템 환경변수 등록

   

    - RabbitMQ 설치

    - [다운로드](http://www.rabbitmq.com/download.html)

    - 설치

         


2. RabbitMQ 설정

- management plugin 설치

- 명령어 실행

```

        cd {RabbitMQ_PATH}\sbin

        .\rabbitmq-plugins.bat enable rabbitmq_management

```

    - management admin 계정 등록

    - default 로 guest / guest 를 제공한다

    - service 재시작

    - 명령어 실행

       


3. RabbitMQ mgmt 실행 확인

- default PORT : 15672

  

4. maven dependency 설정

  

5. java client 를 이용한 queue 등록 및 획득

- QueueClient.java

- QueueClient.send();

- QueueClient.receive();

- Message.java // 메시지 큐

- RabbitmqClient.java // 큐 접속 클라이언트

        import java.io.IOException;

        import java.util.ArrayList;

        import java.util.List;

        import java.util.concurrent.TimeoutException;


        import com.rabbitmq.client.Channel;

        import com.rabbitmq.client.Connection;

        import com.rabbitmq.client.ConnectionFactory;

        import com.rabbitmq.client.ConsumerCancelledException;

        import com.rabbitmq.client.QueueingConsumer;

        import com.rabbitmq.client.ShutdownSignalException;


        public class QueueClient {


        public final static String QUEUE_NAME = "hello";


        public static void send() throws IOException, TimeoutException{

            RabbitmqClient client = new RabbitmqClient();

            Channel channel = client.getChannel();


            channel.queueDeclare(QUEUE_NAME, false, false, false, null);


            // create messages.

            List<Message> messages = new ArrayList<Message>();

            for (int i = 0; i < 10; i++) {

                messages.add(new Message(QUEUE_NAME, "Hello World! " + i));

            }


            System.out.println("ready to send.");

            for (Message m : messages) {

                channel.basicPublish(m.exchange, m.routingKey, null,

                        m.body.getBytes());

                System.out.println(" [x] Sent " + m.toString());

            }


            client.close();

        }


        public static void receive() throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException, TimeoutException{

            RabbitmqClient client = new RabbitmqClient();

            Channel channel = client.getChannel();


            channel.queueDeclare(QUEUE_NAME, false, false, false, null);

            System.out.println(" [*] Waiting for messages. To exit press CTRL+C");


            QueueingConsumer consumer = new QueueingConsumer(channel);

            channel.basicConsume(QUEUE_NAME, true, consumer);


            System.out.println("ready to receive.");

            while (true) {

                QueueingConsumer.Delivery delivery = consumer.nextDelivery();

                String message = new String(delivery.getBody());

                System.out.println(" [x] Received '" + message + "'");

            }

        }


        public static void main(String[]args) throws IOException, TimeoutException, InterruptedException{


            // QueueClient.send();


            QueueClient.receive();


            }


        }


        class RabbitmqClient {

            public static String HOST = "127.0.0.1";// RabbitMQ Server.

            private Connection connection = null;

            private Channel channel = null;


            public Channel getChannel() throws IOException, TimeoutException {

                ConnectionFactory factory = new ConnectionFactory();

                factory.setHost(RabbitmqClient.HOST);

                this.connection = factory.newConnection();

                this.channel = connection.createChannel();


                return this.channel;

            }


            public void close() throws IOException, TimeoutException {

                this.channel.close();

                this.connection.close();

            }

        }


        class Message {

            public String exchange = "";

            public String routingKey = "";

            public String body = "";


            public Message(String routingKey, String body) {

                this.routingKey = routingKey;

                this.body = body;

            }


            public Message(String exchange, String routingKey, String body) {

                this.exchange = exchange;

                this.routingKey = routingKey;

                this.body = body;

            }


            public String toString() {

                if (exchange.length() > 0) {

                    return String.format("Exchange='%s', Key='%s', '%s'", exchange,

                            routingKey, body);

                } else {

                    return String.format("Key='%s', '%s'", routingKey, body);

                }

            }

        } 


'개발' 카테고리의 다른 글

Ubuntu 머신에서 다른 머신 제어하기  (0) 2016.09.09
Ubuntu 설치 후 초기 환경 세팅  (0) 2016.09.07
RabbitMQ 사용하기-1  (0) 2016.09.05
API 모델링 및 개발 - 2  (0) 2016.09.01
API 모델링 및 개발  (0) 2016.08.31
Posted by 감각적신사
,

RabbitMQ 사용하기-1

개발 2016. 9. 5. 23:06

# RabbitMQ

--------------------------------------

[참고자료](http://killins.egloos.com/3025514)


1. 소개

- 표준 AMQP (Advanced Message Queueing Protocol) 메세지 브로커 소프트웨어(message broker software) 오픈소스이다

- erlang 언어로 만들어졌을 뿐만 아니라, clustering과 failover를 위한 OTP framework로 서버가 만들어져 있다

- MQ (Message Queuing) 란

- 서로 다른 프로세스나 프로그램 사이에 메시지를 교환할때 AMQP(Advanced Message Queueing Protocol)을 이용

- AMQP는 메세지 지향 미들웨어를 위한 open standard application layer protocol 이다

- AMQP를 이용하면 다른 벤더 사이에 메세지를 전송하는 것이 가능한데 JMS (Java Message Service)가 API를 제공하는것과 달리 AMQP는 wire-protocol을 제공하는데 이는 octet stream을 이용해서 다른 네트워크 사이에 데이터를 전송할 수 있는 포멧인데 이를 사용한다

- 용도 

- 대용량 데이터를 처리하기 위한 배치 작업이나, 체팅 서비스, 비동기 데이터를 처리할때 사용한다


2. 동작

- Producer: 메시지를 보내는 Application

- Consumer: 메시지를 받는 User Application

- Publish: Producer 가 메시지를 보냄

- Subscribe: Consumer가 메시지를 수신하기 위해 Queue를 실시간으로 리스닝 하기로 만든다

- Exchange:

- Producer가 전달한 메시지를 Queue에 전달하는 역할

- 메시지가 Queue에 직접 전달되는 것이 아니라 Exchange Type이라는 속성에 정의한데로 동작

- RoutingKey: Exchange를 생성하거나 메시지를 Publish할 때 사용하는 Key, Exchange가 Queue에 메시지를 전달할지 결정하는 Key

- Queue: 메시지를 저장하는 버퍼(Queue는 Exchange에 Binding된다)

- durable 속성: 메세지를 디스크에 저장. memory에 저장하는 것은 transient라고 한다

- auto-delete 속성: 모든 consumer가 unsubscribe 하면, 해당 queue는 자동으로 없어진다

- 동일한 queue 가 들어오면 추가하지 않는다?

- Bindings: Exchange와 Queue를 연결

- Virtual Host : 웹서버의 virtual host concept과 같이, 하나의 물리적인 서버에 여러 개의 가상 서버를 만들 수 있다

- Channel : 하나의 물리적인 connection 내에 생성되는 가상 논리적인 connection들. Consumer의 process나 thread는 각자 이 channel을 통해서 queue에 연결 될 수 있다.

- Connection : 물리적인 TCP Connection, 보안이 필요할 경우 TLS(SSL) Connection을 사용할 수 있음


3. Exchange 타입

   

'개발' 카테고리의 다른 글

Ubuntu 머신에서 다른 머신 제어하기  (0) 2016.09.09
Ubuntu 설치 후 초기 환경 세팅  (0) 2016.09.07
RabbitMQ 사용하기-2  (0) 2016.09.06
API 모델링 및 개발 - 2  (0) 2016.09.01
API 모델링 및 개발  (0) 2016.08.31
Posted by 감각적신사
,