[一日30分 인생승리의 학습법] Ubuntu 24.04에 Mosquitto MQTT 서버를 설치하는 방법

Mosquitto MQTT는 MQTT 프로토콜을 구현하는 오픈 소스 메시지 브로커입니다. 저대역폭, 고지연 네트워크를 위해 설계된 경량의 게시-구독 네트워크 프로토콜입니다. 기기 간의 효율적인 통신을 지원하여 사물 인터넷(IoT) 애플리케이션 및 최소한의 오버헤드로 안정적인 메시지 전달이 필요한 기타 시나리오에 이상적입니다. Mosquitto는 TLS 암호화 및 인증과 같은 다양한 보안 기능을 지원하여 안전한 데이터 전송을 보장합니다. 또한 수천 개의 동시 연결을 처리할 수 있어 대규모 배포에 적합합니다.

이 튜토리얼에서는 Ubuntu 24.04에 Mosquitto MQTT 서버를 설치하는 과정을 안내해드리겠습니다.

1단계 – 필수 패키지 설치

먼저, 패키지 목록을 업데이트하고 설치 과정에 필요한 필수 패키지를 설치해야 합니다. 터미널을 열고 다음 명령을 실행하여 필요한 패키지가 있는지 확인하세요. 대부분의 패키지는 기본적으로 설치되어 있을 수 있습니다.

apt-get update
apt-get install curl gnupg2 wget git apt-transport-https ca-certificates -y

2단계 – Mosquitto PPA 추가

다음으로, Mosquitto PPA(Personal Package Archive)를 시스템에 추가해야 합니다. PPA는 최신 버전의 Mosquitto를 제공합니다. 다음 명령을 실행하세요.

add-apt-repository ppa:mosquitto-dev/mosquitto-ppa -y

이 명령은 Mosquitto PPA를 시스템의 소프트웨어 소스에 추가합니다.

3단계 – Mosquitto 및 Mosquitto 클라이언트 설치

이제 PPA가 추가되었으므로 Mosquitto와 클라이언트를 설치할 수 있습니다. 다음 명령을 실행하세요.

apt install mosquitto mosquitto-clients -y

이 명령은 Mosquitto 서버와 Mosquitto 클라이언트 유틸리티(mosquitto_sub 및 mosquitto_pub)를 설치합니다.

Mosquitto가 올바르게 설치되고 실행 중인지 확인하려면 systemctl 명령을 사용하여 상태를 확인하세요.

systemctl status mosquitto

다음과 비슷한 출력이 표시됩니다.

● mosquitto.service - Mosquitto MQTT Broker
     Loaded: loaded (/usr/lib/systemd/system/mosquitto.service; enabled; preset: enabled)
     Active: active (running) since Mon 2025-05-12 06:23:36 UTC; 9s ago
       Docs: man:mosquitto.conf(5)
             man:mosquitto(8)
    Process: 49200 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS)
    Process: 49202 ExecStartPre=/bin/chown mosquitto:mosquitto /var/log/mosquitto (code=exited, status=0/SUCCESS)
    Process: 49204 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
    Process: 49206 ExecStartPre=/bin/chown mosquitto:mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
   Main PID: 49208 (mosquitto)
      Tasks: 1 (limit: 4609)
     Memory: 1.0M (peak: 1.5M)
        CPU: 25ms
     CGroup: /system.slice/mosquitto.service
             └─49208 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

May 12 06:23:36 ubuntu systemd[1]: Starting mosquitto.service - Mosquitto MQTT Broker...
May 12 06:23:36 ubuntu systemd[1]: Started mosquitto.service - Mosquitto MQTT Broker.

출력은 Mosquitto 서비스가 활성화되어 실행 중임을 나타냅니다.

4단계 – Mosquitto 구성

기본적으로 Mosquitto는 익명 연결을 허용하도록 구성되어 있습니다. 보안상의 이유로 Mosquitto 브로커에 비밀번호를 설정하는 것이 좋습니다.

다음 명령을 실행하여 암호 파일을 만들고 사용자를 추가하세요.

mosquitto_passwd -c /etc/mosquitto/passwd hjethva

방금 생성한 사용자( hjethva )에 대한 비밀번호를 입력하고 확인하라는 메시지가 표시됩니다.

Password: 
Reenter password: 

비밀번호 파일에 대한 올바른 소유권을 설정하세요:

chown mosquitto:mosquitto /etc/mosquitto/passwd

다음으로, 리스너와 비밀번호 파일을 지정하는 구성 파일을 만듭니다. nano로 구성 파일을 엽니다.

nano /etc/mosquitto/conf.d/default.conf

다음 줄을 추가합니다.

listener 1883
password_file /etc/mosquitto/passwd

이러한 줄은 Mosquitto가 포트 1883에서 수신하고 인증을 위해 지정된 암호 파일을 사용하도록 구성합니다.

이러한 변경 사항을 적용한 후 Mosquitto 서비스를 다시 시작하여 새 구성을 적용합니다.

systemctl restart mosquitto

5단계 – Mosquitto 테스트

모든 것이 올바르게 작동하는지 확인하기 위해 mosquitto_pub 및 mosquitto_sub 명령을 사용하여 Mosquitto를 테스트합니다.

터미널 창을 열고 주제를 구독하세요. YOUR_PASSWORD 값을 변경하는 것을 잊지 마세요.

mosquitto_sub -u hjethva -P YOUR_PASSWORD -v -t "hello/topic"

다른 터미널 창에서 같은 주제에 대한 메시지를 게시합니다. YOUR_PASSWORD 값을 변경하는 것을 잊지 마세요.

mosquitto_pub -u hjethva -P YOUR_PASSWORD -t 'hello/topic' -m 'hello MQTT'

구독자 터미널에서 다음 출력을 볼 수 있습니다.

hello/topic hello MQTT

이는 Mosquitto 서버가 올바르게 작동하고 있음을 확인합니다.

결론

이 튜토리얼에서는 Ubuntu 24.04에 Mosquitto MQTT 서버를 설치하고 구성하는 방법을 다루었습니다. 또한 비밀번호를 사용하여 서버를 보호하는 방법을 시연하고 Mosquitto 클라이언트 도구를 사용하여 설정을 테스트했습니다. Mosquitto는 IoT 및 메시징 애플리케이션에서 널리 사용되는 강력하고 가벼운 MQTT 브로커입니다. 이 설정을 통해 이제 직접 MQTT 기반 솔루션을 구축할 수 있습니다.

 

How to Install Mosquitto MQTT Server on Ubuntu 24.04

 

Mosquitto MQTT is an open-source message broker that implements the MQTT protocol. It is a lightweight, publish-subscribe network protocol designed for low-bandwidth, high-latency networks. It facilitates efficient communication between devices, making it ideal for Internet of Things (IoT) applications and other scenarios requiring reliable message delivery with minimal overhead. Mosquitto supports various security features, such as TLS encryption and authentication, ensuring secure data transmission. Its ability to handle thousands of concurrent connections makes it suitable for large-scale deployments.

In this tutorial, we will walk you through the process of installing the Mosquitto MQTT Server on Ubuntu 24.04.

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

Step 1 – Installing Required Packages

First, we need to update our package list and install some essential packages required for the installation process. Open your terminal and run the following command to make sure the packages you need are available – please note, most of these may already be installed by default:

apt-get update
apt-get install curl gnupg2 wget git apt-transport-https ca-certificates -y

Step 2 – Adding the Mosquitto PPA

Next, we need to add the Mosquitto PPA (Personal Package Archive) to our system. The PPA provides the latest version of Mosquitto. Run the following command:

add-apt-repository ppa:mosquitto-dev/mosquitto-ppa -y

This command adds the Mosquitto PPA to your system’s software sources.

Step 3 – Installing Mosquitto and Mosquitto Clients

Now that the PPA has been added, we can install Mosquitto and its clients. Execute the following command:

apt install mosquitto mosquitto-clients -y

This command installs the Mosquitto server and the Mosquitto client utilities (mosquitto_sub and mosquitto_pub).

To verify that Mosquitto has been installed correctly and is running, use the systemctl command to check its status:

systemctl status mosquitto

You should see an output similar to this:

● mosquitto.service - Mosquitto MQTT Broker
     Loaded: loaded (/usr/lib/systemd/system/mosquitto.service; enabled; preset: enabled)
     Active: active (running) since Mon 2025-05-12 06:23:36 UTC; 9s ago
       Docs: man:mosquitto.conf(5)
             man:mosquitto(8)
    Process: 49200 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS)
    Process: 49202 ExecStartPre=/bin/chown mosquitto:mosquitto /var/log/mosquitto (code=exited, status=0/SUCCESS)
    Process: 49204 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
    Process: 49206 ExecStartPre=/bin/chown mosquitto:mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
   Main PID: 49208 (mosquitto)
      Tasks: 1 (limit: 4609)
     Memory: 1.0M (peak: 1.5M)
        CPU: 25ms
     CGroup: /system.slice/mosquitto.service
             └─49208 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

May 12 06:23:36 ubuntu systemd[1]: Starting mosquitto.service - Mosquitto MQTT Broker...
May 12 06:23:36 ubuntu systemd[1]: Started mosquitto.service - Mosquitto MQTT Broker.

The output indicates that the Mosquitto service is active and running.

Step 4 – Configuring Mosquitto

By default, Mosquitto is configured to allow anonymous connections. For security reasons, it is recommended to set up a password for your Mosquitto broker.

Run the following command to create a password file and add a user:

mosquitto_passwd -c /etc/mosquitto/passwd hjethva

You will be prompted to enter and confirm a password for the user you just created (hjethva).

Password: 
Reenter password: 

Set the correct ownership for the password file:

chown mosquitto:mosquitto /etc/mosquitto/passwd

Next, create a configuration file to specify the listener and password file. Open the configuration file with nano:

nano /etc/mosquitto/conf.d/default.conf

Add the following lines:

listener 1883
password_file /etc/mosquitto/passwd

These lines configure Mosquitto to listen on port 1883 and use the specified password file for authentication.

After making these changes, restart the Mosquitto service to apply the new configuration:

systemctl restart mosquitto

Step 5 – Testing Mosquitto

To ensure everything is working correctly, we will test Mosquitto using the mosquitto_pub and mosquitto_sub commands.

Open a terminal window and subscribe to a topic – remember to change the YOUR_PASSWORD value.

mosquitto_sub -u hjethva -P YOUR_PASSWORD -v -t "hello/topic"

In another terminal window, publish a message on the same topic – – remember to change the YOUR_PASSWORD value.

mosquitto_pub -u hjethva -P YOUR_PASSWORD -t 'hello/topic' -m 'hello MQTT'

You should see the following output in the subscriber terminal:

hello/topic hello MQTT

This confirms that the Mosquitto server is working correctly.

Conclusion

In this tutorial, we have covered the installation and configuration of the Mosquitto MQTT server on Ubuntu 24.04. We also demonstrated how to secure the server with a password and tested the setup using Mosquitto client tools. Mosquitto is a powerful and lightweight MQTT broker that is widely used in IoT and messaging applications. With this setup, you can now start building your own MQTT-based solutions. 

 

[출처] https://www.atlantic.net/dedicated-server-hosting/how-to-install-mosquitto-mqtt-server-on-ubuntu-24-04/

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
1232 [一日30分 인생승리의 학습법] 어떤 종류의 앱이 가장 많은 돈을 벌까요? file 졸리운_곰 2026.03.08 23
1231 [一日30分 인생승리의 학습법] [알아봅시다] 50대 시니어 개발팀장이 읽으면 좋은 추천도서 [두번째] 졸리운_곰 2025.12.28 76
1230 [一日30分 인생승리의 학습법] [알아봅시다] 50대 시니어 개발팀장이 읽으면 좋은 추천도서 [첫번째] 졸리운_곰 2025.12.28 83
1229 [一日30分 인생승리의 학습법] [알아봅시다] Google에서 14년간 얻은 21가지 교훈  졸리운_곰 2025.12.15 58
1228 [一日30分 인생승리의 학습법] 바이브코딩보다 훨씬 중요함 | 바이브코딩 직전까지의 기획 계획 과정 졸리운_곰 2025.12.06 74
1227 [一日30分 인생승리의 학습법] 크몽에서 업무의뢰 제안받으면 어떻게 견적내야 할까? 졸리운_곰 2025.11.21 110
1226 [一日30分 인생승리의 학습법] Vrew 워터마크 제거 브루 로고 없애기 무료로 쓰는 법 file 졸리운_곰 2025.11.06 82
1225 [一日30分 인생승리의 학습법] 명령형 vs 선언형 프로그래밍 졸리운_곰 2025.10.16 130
1224 [一日30分 인생승리의 학습법] ▲ 2025년 가장 인기 있는 프로그래밍 언어 (spectrum.ieee.org) 졸리운_곰 2025.10.09 124
1223 [一日30分 인생승리의 학습법] [Jenkins] 젠킨스(Jenkins) 설치 하기 / 젠킨스 설치 방법 / 젠킨스 설정 하기 졸리운_곰 2025.09.10 112
1222 [一日30分 인생승리의 학습법] 유능한 리더들은 어떤 능력으로 불확실성을 헤쳐나가는가 file 졸리운_곰 2025.08.26 119
» [一日30分 인생승리의 학습법] Ubuntu 24.04에 Mosquitto MQTT 서버를 설치하는 방법 졸리운_곰 2025.08.25 137
1220 [一日30分 인생승리의 학습법] Qiskit 시작하기 (Getting Started with Qiskit) file 졸리운_곰 2025.06.03 126
1219 [一日30分 인생승리의 학습법] 양자컴퓨팅 프로그래밍 file 졸리운_곰 2025.06.03 108
1218 [一日30分 인생승리의 학습법] [Git] 다중 리모트를 사용하여 여러 Git 연동하기(Gitea, GitHub) file 졸리운_곰 2025.05.25 122
1217 [一日30分 인생승리의 학습법] [GitHub][terminal] 비밀번호 인증 에러를 토큰으로 해결하고 로그인 하기 file 졸리운_곰 2025.05.24 132
1216 [一日30分 인생승리의 학습법] [알아봅시다] 블록체인 게임들의 가능성과 미래 file 졸리운_곰 2025.04.08 141
1215 이 어지러운시대의 극복법 만화보기 file unmask 2025.04.08 204
1214 [ 一日30分 인생승리의 학습법] IT 국비교육, 쓰레기 속에서 그나마 덜 쓰레기인 곳 찾는 팁 file 졸리운_곰 2025.03.08 122
1213 [ 一日30分 인생승리의 학습법] 소프트웨어 개발하다보면 "connection reset" 등, 소프트웨어 버그 적인 문제가아닌 하드웨어나 네트워크 오류 메시지의 예 file 졸리운_곰 2025.03.01 121
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED