MQTT: install di Ubuntu 22.04 dengan cedalo docker

From OnnoWiki
Jump to navigation Jump to search

sumber: https://linux.how2shout.com/how-to-install-mosquitto-in-ubuntu-22-04-or-20-04-lts/


Mosquitto MQTT Server adalah message broker yang bekerja di atas protokol MQTT. MQTT adalah protokol messaging ringan yang standar ISO untuk digunakan di atas protokol TCP/IP. Hal ini banyak digunakan untuk berkomunikasi dengan perangkat Internet of Things. Kami akan menginstal Mosquitto di server Ubuntu 22.04 dan kami akan mengirim pesan dari perangkat lunak MQTT-spy. Mosquitto adalah proyek Eclipse dan didistribusikan dengan lisensi EDL. Jadi mari kita mulai.



Install Web Manajemen UI

  • Install docker sesuai petunjuk untuk Ubuntu 22.04 - Docker: Instalasi di Ubuntu 22.04
  • sebagai user biasa,
  • Install free dan open-source Management UI untuk MQTT Cedalo
sudo docker run -it -v ~/cedalo_platform:/cedalo cedalo/installer:2-linux

Start

cd ~/cedalo_platform
sudo sh start.sh


Jika berhasil

Creating cedalo_platform_mosquitto_1 ... done
Creating cedalo_platform_management-center_1 ... done
Creating cedalo_platform_streamsheets_1      ... done
Attaching to cedalo_platform_mosquitto_1, cedalo_platform_management-center_1, 
cedalo_platform_streamsheets_1
management-center_1  | Starting Management Center for Eclipse Mosquitto
mosquitto_1          | 1688422966: mosquitto version 2.0.15 starting
mosquitto_1          | 1688422966: Config loaded from /mosquitto/config/mosquitto.conf.
mosquitto_1          | 1688422966: Loading plugin: /usr/lib/mosquitto_dynamic_security.so
mosquitto_1          | 1688422966: Opening ipv4 listen socket on port 1883.
mosquitto_1          | 1688422966: Opening ipv6 listen socket on port 1883.
mosquitto_1          | 1688422966: mosquitto version 2.0.15 running
streamsheets_1       | Password for default Mosquitto does not exist, will create one.
streamsheets_1       | sed: cannot rename streamsheets/packages/gateway/config/sedVhHFnO: Device or resource busy
streamsheets_1       | -e Password for default Mosquitto created successfully.
streamsheets_1       | -e Hashed password for Mosquitto broker is located inside the installation directory in the file settings/mosquitto/pw.txt.
streamsheets_1       | -e Clear text password for Mosquitto broker is located inside the installation directory in the file settings/mosquitto/pw_clear.txt.
streamsheets_1       | -e Warning: for security reasons please copy the password from settings/mosquitto/pw_clear.txt and delete that file afterwards.
streamsheets_1       | 2023-07-03 22:22:57,196 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
streamsheets_1       | 2023-07-03 22:22:57,233 INFO supervisord started with pid 16
streamsheets_1       | 2023-07-03 22:22:58,240 INFO spawned: 'mongod' with pid 19
streamsheets_1       | 2023-07-03 22:22:58,253 INFO spawned: 'redis' with pid 20
streamsheets_1       | 2023-07-03 22:22:58,263 INFO spawned: 'mosquitto-default' with pid 21
streamsheets_1       | 2023-07-03 22:22:58,287 INFO spawned: 'nginx' with pid 22
streamsheets_1       | 2023-07-03 22:22:58,298 INFO spawned: 'mosquitto' with pid 23
streamsheets_1       | 2023-07-03 22:22:58,302 INFO spawned: 'gateway' with pid 24
streamsheets_1       | 2023-07-03 22:22:58,306 INFO spawned: 'service-graphs' with pid 25
streamsheets_1       | 2023-07-03 22:22:58,310 INFO spawned: 'service-machines' with pid 26
streamsheets_1       | 2023-07-03 22:22:58,324 INFO spawned: 'service-streams' with pid 27
streamsheets_1       | 2023-07-03 22:22:59,504 INFO success: mongod entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
streamsheets_1       | 2023-07-03 22:22:59,505 INFO success: redis entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
streamsheets_1       | 2023-07-03 22:22:59,505 INFO success: mosquitto-default entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
streamsheets_1       | 2023-07-03 22:22:59,505 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
streamsheets_1       | 2023-07-03 22:22:59,505 INFO success: mosquitto entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
streamsheets_1       | 2023-07-03 22:22:59,506 INFO success: gateway entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
streamsheets_1       | 2023-07-03 22:22:59,506 INFO success: service-graphs entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
streamsheets_1       | 2023-07-03 22:22:59,506 INFO success: service-machines entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
streamsheets_1       | 2023-07-03 22:22:59,506 INFO success: service-streams entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
management-center_1  | [Error: ENOENT: no such file or directory, access '/management-center/src/license/utils/config/license.lic'] {
management-center_1  |   errno: -2,
management-center_1  |   code: 'ENOENT',
management-center_1  |   syscall: 'access',
management-center_1  |   path: '/management-center/src/license/utils/config/license.lic'
management-center_1  | }
management-center_1  | /management-center/src/license/utils
management-center_1  | undefined
management-center_1  | Mon, 03 Jul 2023 22:23:01 GMT express-session deprecated undefined resave option; provide resave option at start.js:179:10
management-center_1  | Mon, 03 Jul 2023 22:23:01 GMT express-session deprecated undefined saveUninitialized option; provide saveUninitialized option at start.js:179:10
management-center_1  | Connecting to "Mosquitto 2.0" on mqtt://mosquitto:1883
management-center_1  | Started Mosquitto proxy at http://localhost:8088
management-center_1  | "CEDALO_MC_PLUGIN_DIR" is not set. Skipping loading of plugins
management-center_1  | Mosquitto proxy server started on port 8088
mosquitto_1          | 1688422981: New connection from 172.18.0.4:34320 on port 1883.
mosquitto_1          | 1688422981: New client connected from 172.18.0.4:34320 as mqttjs_8909d2c4 (p2, c1, k60, u'cedalo').
management-center_1  | Connected to 'Mosquitto 2.0' at mqtt://mosquitto:1883

Akses web

http://ip-address:8088
http://192.168.0.62:8088
username cedalo
password mmcisawesome
Cedalo-web-ui.png


Konfigurasi

cd /home/onno/cedalo_platform/mosquitto/config
vi mosquitto.conf

Tambahkan


allow_anonymous true
listener 1883 0.0.0.0

persistence true
persistence_location /mosquitto/data/
persistence_file mosquitto.db
log_dest syslog
log_dest stdout
log_dest topic
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true
password_file /etc/mosquitto/pwfile
 
plugin /usr/lib/mosquitto_dynamic_security.so
plugin_opt_config_file /mosquitto/data/dynamic-security.json

Restart

sudo docker restart cedalo_platform_mosquitto_1
sudo docker restart cedalo_platform_management-center_1
sudo docker restart cedalo_platform_streamsheets_1

Test MQTT

Install mosquitto client

locale-gen id_ID.UTF-8
sudo add-apt-repository ppa:mosquitto-dev/mosquitto-ppa
apt update
sudo apt -y install mosquitto-clients


Tambahkan User mqtt-spy via cedalo

Test

Subscribe

mosquitto_sub -v -t 'test' -u mqtt-spy -P 123456

Posting

mosquitto_pub -t 'test' -u mqtt-spy -P 123456 -m "lampu ON"

Referensi