프로그램 사용/mosquitto
mosquitto service for windows
구차니
2025. 2. 18. 11:36
공식 다운로드는 아래인데
[링크 : https://mosquitto.org/download/]
받아도 방화벽 설정은 하나도 안되고 내부에서만 허용되는 설정으로 설치가 된다.
그러니 외부 접속이 필요하면 아래 내용을 참고하여 인바운드 1883/tcp를 허용해주어야 한다.
[링크 : https://velog.io/@foxiq/MQTT-사용]
윈도우 64bit로 설치했을 경우 C:\Program Files\mosquitto\mosquitto.conf 에 설정 파일이 저장된다.
굳이 listener 1883 0.0.0.0 으로 해주진 않아도 외부 접속을 허용하게 되는 것으로 보인다.
# ================================================================= # Listeners # ================================================================= # Listen on a port/ip address combination. By using this variable # multiple times, mosquitto can listen on more than one port. If # this variable is used and neither bind_address nor port given, # then the default listener will not be started. # The port number to listen on must be given. Optionally, an ip # address or host name may be supplied as a second argument. In # this case, mosquitto will attempt to bind the listener to that # address and so restrict access to the associated network and # interface. By default, mosquitto will listen on all interfaces. # Note that for a websockets listener it is not possible to bind to a host # name. # # On systems that support Unix Domain Sockets, it is also possible # to create a # Unix socket rather than opening a TCP socket. In # this case, the port number should be set to 0 and a unix socket # path must be provided, e.g. # listener 0 /tmp/mosquitto.sock # # listener port-number [ip address/host name/unix socket path] #listener listener 1883 allow_anonymous true |
+
2025.02.21
포트를 바꿀 경우 -p 로 바꾸어 주고
다른 서버일 경우 -h ip를 추가해주면 된다.
C:\Program Files\mosquitto>mosquitto_sub -p 27839 -t topic -u username -P password |
C:\Program Files\mosquitto>mosquitto_pub -p 27839 -t MY -u username -P password -m asdf |
+
allow_anonymous true가 없으면 아래 에러가 발생한다.
Connection error: Connection Refused: not authorised. |
전체 테스트 과정은 아래와 같다.
윈도우 (서버) | 다른 PC/linux (클라이언트) |
1. 프로그램 설치 | |
2. 방화벽 설정 | |
3. conf 파일 수정 및 서비스 재기동 | |
4. client 접속 C:\Program Files\mosquitto>mosquitto_sub.exe -t MY_TOPIC |
4. client 접속 $ mosquitto_sub -v -h 192.168.0.11 -t MY_TOPIC |
5. publish C:\Program Files\mosquitto>mosquitto_pub.exe -t MY_TOPIC -m HELLO |
|
6. 메시지 확인 HELLO -v 시에는 MY_TOPIC HELLO |
---
Just edit Mosquitto configuration file ( /etc/mosquitto/conf.d/mosquitto.conf ) adding these lines... allow_anonymous true listener 1883 0.0.0.0 |
[링크 : https://stackoverflow.com/questions/24556160/mosquitto-client-obtain-refused-connection]
[링크 : https://iotmaker.kr/2021/08/23/mosquitto-remote-access-for-windows/]