보안 도구 사용방법

Cent OS에서 Mosquitto Broker 셋업

Security_Info 2019. 12. 22. 19:30

그동안 IoT와 관련 보안 논문을 리딩하며 관련 공부를 하던 중,  IoT 보안 관련 박사 논문 실험에 개발담당으로 참여하게 되었습니다..

 

그래서 실험을 위해 Cent OS에서의 Mosquitto를 셋팅해야 했습니다.

Mosquitto는 MQTT 프로토콜에 사용되는 브로커 입니다.

'중간자'이기 때문에 서버가 아니라 각 이해 관계 단말기들을 topic기반으로 정보를 연결해주는 중계자라고 생각하면

될듯합니다.

 

MQTT는 기본적으로 구독자(Subscribe), 발행자(Publish), 중간자(Broker)가 존재합니다.

발행자(Pub)는 topic을 통해 정보를 발행하여 중간자(Broker)에 전달하고, 구독자(Sub)는 해당 topic을 통해

중간자(Broker)에서 데이터를 받을 수 있습니다.

 

여기서 중요한점은 다수의 단말기가 동일한 topic을 Subscribe하고 있다면?

그렇습니다. 다수의 단말기는 동일한 데이터를 제공받을 수 있습니다.

 

즉, 1 : 1 , 1 : N 등 다양하게 유연성있는 데이터를 주고 받을 수있게 됩니다.

또한 저전력이기에 IoT에 적용할 수 있습니다.

더불어 TLS/SSL을 지원하므로 전송 간 암호화를 통해 안전한 데이터 전송이 가능할 것으로 보입니다.

 

그외 다양한 장점들이 있는데 일단 Cent OS에서 Mosquitto라는 Broker를 설치하여 Local host에서 MQTT 통신을 해야

하기 때문에 Mosquitto 셋업 방법을 작성해보겠습니다.

 

 

 

 

CentOS의 Mosquitto 셋업

1. Mosquitto에 필요한 의존성 패키지 설치 진행

yum install openssl openssl-devel

yum install pcre pcre-devel

yum install zlib zlib-devel

yum install glibc glibc-devel

yum install libuuid libuuid-devel

yum install libxslt

yum -y install docbook-style-xsl

 

2. Mosquitto를 다운로드

yum -y install wget

cd /usr/local/src

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

 

Eclipse Mosquitto

Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1. Mosquitto is lightweight and is suitable for use on all devices

mosquitto.org

tar zxvf mosquitto-1.6.2.tar.gz

cp -Rf mosquitto-1.6.2 /usr/src/mosquitto

cd /usr/src/mosquitto

make

make install

 

 

3. 방화벽 설정

Broker는 기본 '1883' 포트이기 때문에 포트를 열어줄 필요가 있습니다.

그러나 TLS/SSL 통신을 위해서는 추후 '8883'포트도 열어줘야 합니다.

 

systemctl stop firewalld

systemctl mask firewalld

yum install iptables-services

iptables -I INPUT -m tcp -p tcp --dport 1883 -j ACCEPT //iptables 셋업

service iptables save

systemctl enable iptables

systemctl restart iptables

 

4. 환경설정

useradd mosquitto

groupadd mosquitto

vi /etc/ld.so.conf

 include /usr/src/mosquitto/lib

 include /usr/local/lib

 

ldconfig

ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1

 

5. Mosquitto_home 설정

vi /etc/profile

 MOSQUITTO_HOME=/usr/src/mosquitto

 export MOSQUITTO_HOME

 PATH=$PATH:$MOSQUITTO_HOME/src

 export PATH

 

source /etc/profile

 

6. 브로커 실행

mosquitto

 

7. 발행자와 구독자 실행 (Local에서 실행)

mosquitto_sub -h localhost -p 1883 -t test

mosquitto_pub -h localhost -p 1883 -t test -m "test"

 

Mosquitto 셋업완료 및 통신확인

 

그 결과 중계인(Broker)를 통하여 Pub와 Sub가 통신 가능하게 되었습니다.