본문 바로가기
  • 👩🏻‍💻 🌮 💬
🍔 database

[MQTT] mqtt client에 connect 안되는 문제

by 바쿄리 2024. 3. 6.

 

ec2 instance를 생성하고 mosquitto를 실행시켰다.

그리고 mqtt connection tool를 사용하여 연결을 시도하니,

 

연결이 불가능했다

 

 

Starting in local only mode. Connections will only possible from clients running on this machine.

로컬 모드에서만 가능하며

Create a configuration file which defines a listener to allow remote access.

원격 엑세스를 config를 create 하라고 하는 것 같다

 

 

첫번째, mosquitto config를 수정한다.

linux라면 /etc/mosquitto/mosquitto.conf 에 위치한다.

 

이렇게 설정되어있는데, 

아래에 두줄만 추가하면 된다.

allow_anonymous true
listener 1883 0.0.0.0

 

두번째, ec2 instance에 1883 포트를 열어주자

instance의 security group에서 inbound rules에 추가해주면 된다. 아주 간단함

 

끝이다. 이제 mosquitto 재실행만 시켜주면

systemctl stop mosquitto
systemctl start mosquitto

 

 

연결 완료

 


오늘의 뻘짓 : 바보같이 example conf파일 수정하고 연결안된다고 2시간동안 구글링했다 ㅎㅎ

/etc/mosquitto/mosquitto.conf 수정해야하는데, /usr/share/doc/mosquitto/examples/mosquitto.conf 수정한 나

반성하자 ㅎㅎ