반응형
출처 - http://blog.naver.com/cyk7890?Redirect=Log&logNo=40205033723
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
==================================================================================================
- Broker 실행! (http://mosquitto.org/man/mosquitto-8.html)
# 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
[출처] MQTT - Mosquitto Broker 설치|작성자 Cheon Brave
반응형
'개발 > 기타' 카테고리의 다른 글
[리눅스]crontab 사용법 (0) | 2014.03.26 |
---|---|
아파치 톰캣 mod_jk 설치 (0) | 2014.02.27 |
MariaDB(마리아DB) 설치 (0) | 2014.02.24 |
Subversion 서버 IP 변경되었을 때 TortoiseSVN와 Eclipse 설정 바꾸기 Relocate (0) | 2012.06.04 |
티스토리 Syntax highlighter 적용하기 (0) | 2011.05.03 |
댓글