개발자의 노트
반응형

오픈소스 MQTT Broker Mosquitto를 설치하자.

 

의존성 패키지 설치

# yum install gcc*

# yum install openssl openssl-devel

# yum install pcre pcre-devel

# yum install zlib zlib-devel

# yum install glibc glibc-devel

 

CentOS는 기본적으로 OpenSSL을 탑재하고 있다.

# openssl version

OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008

 

하지만 최신 OpenSSL로 재설치하자.

# cd /usr/local/src

# wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz

# 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

# openssl lib 폴더 경로 추가

include /usr/local/openssl/lib

# /sbin/ldconfig

 

OpenSSL 버전확인

# openssl version

OpenSSL 1.0.1c 10 May 2012

 

 

자. Mosquitto를 설치하자.


우선 mosquito 계정을 만들자

# useradd  mosquitto

# groupadd mosquitto

 

소스를 다운받아 설치하자.

# cd /usr/local/src

# wget http://mosquitto.org/files/source/mosquitto-1.1.2.tar.gz

# 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 /usr/local/mosquitto/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

# source /etc/profile

 

mosquitto 포트 개방 (1883)

# iptables -I INPUT -m tcp -p tcp --dport 1883 -j ACCEPT

# /sbin/service iptables save

# /sbin/service iptables restart

 

구동하기 (http://mosquitto.org/man/mosquitto-8.html)

# 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 192.168.0.201 -t /test/1

다른쪽에는 pub를 보내면

# mosquitto_pub -h 192.168.0.201 -t /test/1 -m "testtest"

sub쪽에 메시지가 잘 도착할 것이다.

profile

개발자의 노트

@곽코딩

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!