기본 콘텐츠로 건너뛰기

MQTT - Mosquitto Broker 설치

잡담 없이 내용만 쓸라니까 맘이 영 허전해서 한줄 끄적이자면.. 
ㅋㅋㅋㅋㅋㅋㅋㅋㅋ 아 이거.. MQTT 알면 알수록 대단한것 같은데 정작 구현하고 얼마만큼에 퍼포먼스를 보여줄지는 내눈으로 보기전까지 못믿겠음 
다만들고 오류만 뿜지 말자 ♥


MQTT - Push Server 개발 과정 - by.용기

( * 작업 배경 : LIVE 1 서버 / CentOS / root )

0. 리눅스 mosquitto 계정 추가 (브로커 설치시 이 계정을 자동으로 찾아서 설치가 진행된다.)
# useradd  mosquitto
# groupadd mosquitto

1. MQTT Broker 설치 (Live1 - CentOS 5.9, Live5 - CentOS 6)
 1) 의존성 패키지 설치 
==================================================================================================
# yum install gcc*
# yum install openssl openssl-devel
# yum install pcre pcre-devel
# yum install zlib zlib-devel
# yum install glibc glibc-devel
==================================================================================================
 - 최신 OpenSSL로 재설치
# cd /usr/local/src
# tar zxvf openssl-1.0.1c.tar.gz
# cp -Rf openssl-1.0.1c /usr/local/openssl
# cd ../openssl/
# export LDFLAGS=-L/usr/local/lib
# export CPPFLAGS=-I/usr/local/include
# make clean
# ./config --prefix=/usr --openssldir=/usr/local/openssl shared threads zlib
# make
# make test
# make install
# make clean
# unset LDFLAGS
# unset CPPFLAGS
# vi /etc/ld.so.conf    ->  include /usr/local/openssl/lib  추가
include ld.so.conf.d/*.conf
include /usr/local/openssl/lib
# /sbin/ldconfig
==================================================================================================
 - OpenSSL 버전확인
# openssl version
OpenSSL 1.0.1c 10 May 2012
==================================================================================================
 - mosquitto 다운로드 및 설치 
# cd /usr/local/src
# tar zxvf mosquitto-1.1.2.tar.gz
# cp -Rf mosquitto-1.1.2 /usr/local/mosquitto
# cd ../mosquitto
# make 
# make install
# vi /etc/ld.so.conf 를 아래 내용으로 덮어씌우

include ld.so.conf.d/*.conf
include /usr/local/openssl/lib
include /usr/local/mosquitto/lib
/usr/lib
/usr/local/lib

# /sbin/ldconfig
# ln -s /usr/local/mosquitto/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
==================================================================================================
 - MOSQUITTO_HOME 셋팅
# vi /etc/profile
---------- 매뉴얼에 나와있는 내용
MOSQUITTO_HOME=/usr/local/mosquitto
export MOSQUITTO_HOME
PATH=$PATH:$MOSQUITTO_HOME/src
export PATH
---------- 
---------- 내가 실제 작성한 내용
export MOSQUITTO_HOM=/usr/local/mosquitto
export PATH=$PATH:$MOSQUITTO_HOME/client
----------
# source /etc/profile
==================================================================================================
 - mosquitto 포트 개방 (1883)
# iptables -I INPUT -m tcp -p tcp --dport 1883 -j ACCEPT
# /sbin/service iptables save
# /sbin/service iptables restart
==================================================================================================
# mkdir /log
# mkdir /log/mosquitto
# touch /log/mosquitto/mosquitto.log
# mosquitto -c /usr/local/mosquitto/mosquitto.conf -d > /log/mosquitto/mosquitto.log 2>&1
==================================================================================================
 - 구동 확인
# tail -f /log/mosquitto/mosquitto.log
1361175067: mosquitto version 1.1.2 (build date 2013-02-18 16:12:55+0900) starting
1361175067: Config loaded from mosquitto.conf.
1361175067: Opening ipv6 listen socket on port 1883.
1361175067: Opening ipv4 listen socket on port 1883.

 - 테스트
  : 쉘을 두개 열고 한쪽에는 sub를 실행
# mosquitto_sub -h 000.000.000.000 -t /test/1            << 설마 000.000.000.000 에 서버 ip주소를 안쓰고 저대로 쓰진 마시길 
  : 다른쪽에는 pub를 보내면
# mosquitto_pub -h 000.000.000.000 -t /test/1 -m "Hello Mosquitto"

mosquitto_pub -h 000.000.000.000 -t "ALL" -m "{seq:1,type:TEXT,sender_nick:yongki,anal_id:1,noti_msg:helloMqtt,is_cost:N,corp:emoney}"
mosquitto_pub -h 000.000.000.000 -t "ALL" -m "{seq:1,type:IMAGE,sender_nick:yongki,anal_id:1,noti_msg:helloMqtt,is_cost:N,corp:emoney,image_url:'http://img.x1.co.kr/popup/131230/pop_131230_hi.gif'}"

==================================================================================================
[참고]
 - 유닉스 포트 용도
0번 ~ 1023번: 잘 알려진 포트 (well-known port)
1024번 ~ 49151번: 등록된 포트 (registered port)
49152번 ~ 65535번: 동적 포트 (dynamic port)

[파라미터 사용법]
mosquitto_pub is a simple mqtt client that will publish a message on a single topic and exit.
mosquitto_pub version 1.1.2 running on libmosquitto 1.1.2.

Usage: mosquitto_pub [-h host] [-p port] [-q qos] [-r] {-f file | -l | -n | -m message} -t topic
                     [-i id] [-I id_prefix]
                     [-d] [--quiet]
                     [-u username [-P password]]
                     [--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]
                     [{--cafile file | --capath dir} [--cert file] [--key file]]
                     [--psk hex-key --psk-identity identity]
       mosquitto_pub --help

 -d : enable debug messages.
 -f : send the contents of a file as the message.
 -h : mqtt host to connect to. Defaults to localhost.
 -i : id to use for this client. Defaults to mosquitto_pub_ appended with the process id.
 -I : define the client id as id_prefix appended with the process id. Useful for when the
      broker is using the clientid_prefixes option.
 -l : read messages from stdin, sending a separate message for each line.
 -m : message payload to send.
 -n : send a null (zero length) message.
 -p : network port to connect to. Defaults to 1883.
 -q : quality of service level to use for all messages. Defaults to 0.
 -r : message should be retained.
 -s : read message from stdin, sending the entire input as a message.
 -t : mqtt topic to publish to.
 -u : provide a username (requires MQTT 3.1 broker)
 -P : provide a password (requires MQTT 3.1 broker)
 --help : display this message.
 --quiet : don't print error messages.
 --will-payload : payload for the client Will, which is sent by the broker in case of
                  unexpected disconnection. If not given and will-topic is set, a zero
                  length message will be sent.
 --will-qos : QoS level for the client Will.
 --will-retain : if given, make the client Will retained.
 --will-topic : the topic on which to publish the client Will.
 --cafile : path to a file containing trusted CA certificates to enable encrypted
            communication.
 --capath : path to a directory containing trusted CA certificates to enable encrypted
            communication.
 --cert : client certificate for authentication, if required by server.
 --key : client private key for authentication, if required by server.
 --psk : pre-shared-key in hexadecimal (no leading 0x) to enable TLS-PSK mode.
 --psk-identity : client identity string for TLS-PSK mode.




댓글

이 블로그의 인기 게시물

웹 개발하면서 보안을 유지하기 위한 기본지식

몇개월전에 만들었던 웹기반 (HTML5, CSS3, Flash Player(VideoJS)) VOD플레이어에서 보안이슈가 발생했다. 웹또한 서버를통해 통신을하지만 사용자의 PC에서 실행되는만큼 클라이언트의 개념이 있으며 Javascript 야말로 클라이언트에서 작업하게 되는 영역이라는 점에서 보안상에 이슈 발생.  이유인즉슨  무료로 제공되고 있는것과 유료로 제공되고있는 서비스에 대하여  javascript 단에서 서비스 허용여부를 결정하게될경우  해킹을 통해 이부분을 우회하여 서비스이용이 가능했다는점.. 모든 인증이나, 중요데이터는 java 로 코딩해서 서버단에서 결단이 나도록 했어야했는데 이건 너무 기본적이면서도 아쉬운 실수를 저지르고 말았다..  하하..  많은 분들이 이런 부분을 간과할수도있을듯하여 작성해봅니다.  요즘 보안이슈가 많을탠데 모두들 보안 화이팅 ! 

Android 스마트폰 기본 웹브라우저(Chrome:크롬) 호출하는 스키마(URL Scheme)

신용카드결제 페이지 주소를 카톡으로 던졌을때 카톡 내부에서 결제가 이루어지다보니 결제완료까지 정상적으로 처리되지 않는 경우가 발생한다더라 그래서 생각해본게.. 1) 카카오통 채팅방  2) 링크 전송  3) 링크를 클릭하면 스마트폰애 내장된 웹브라우저를 실행하는 URL스키마 실행  4) 실행된 웹브라우저에서 결제페이지로 이동 이 절차를 거치면 카톡 외부로 나와서 독립적인 웹브라우저상에서 결제를 진행하기때문에 정상처리가 가능할것이라고 판단 찾다 찾다가.. 알아낸것이 안드로이드 (가능) - 롤리팝부터 크롬 브라우저가 기본앱이다 - 크롬을 호출방법 intent://www.naver.com#Intent;scheme=http;package=com.android.chrome;end  아이폰 (조건부 가능) - 사파리를 호출하는 앱스키마가 없으며, 사파리를 통해서 검색어를 입력한 검색기능만 가능 - 크롬브라우저 앱이 설치되어있을경우 아래와같이 호출 가능 googlechrome:////www.naver.com <사용법> < html > < body > < script >      var currentOS = "else" ;      var mobile = ( /iphone | ipad | ipod | android/ i .test(navigator.userAgent.toLowerCase()));      if (mobile) {          var userAgent = navigator.userAgent.toLowerCase();          if (userAgent.search( "android" ) > - 1 )             currentOS = "android" ;          else if

flutter showDatePicker locale 설정을 통해 한국어로 표현되게 하는방법

제목 그대로.. showDatePicker 를 사용하면 아래와같은 형태로 사용할수가 있는데 Future<Null> _selectDate(BuildContext context) async { final DateTime picked = await showDatePicker( context: context , initialDate: selectedDate , firstDate: DateTime ( 2015 , 8 ) , lastDate: DateTime ( 2101 ) , initialDatePickerMode: DatePickerMode. year , //locale : const Locale('kr') ) ; if (picked != null && picked != selectedDate) setState(() { selectedDate = picked ; debugPrint( "_selectDate" ) ; debugPrint(selectedDate.toString()) ; }) ; } 위 소스처럼 locale을 직접 할당하면 datePicker 로딩부터 실패한다 그래서 해결방법을 찾아본 결과 아래와같이 MyApp에서 locale설정을 해주면 이곳에 설정한 locale옵션을 따라서 datepicker의 언어설정이 바뀌게된다 class MyApp extends StatelessWidget { @override Widget build (BuildContext context) { return MaterialApp ( title: 'Flutter Demo