Cov txheej txheem:

Yuav Ua Li Cas Teeb Mosquitto MQTT ntawm AWS: 8 Kauj Ruam
Yuav Ua Li Cas Teeb Mosquitto MQTT ntawm AWS: 8 Kauj Ruam

Video: Yuav Ua Li Cas Teeb Mosquitto MQTT ntawm AWS: 8 Kauj Ruam

Video: Yuav Ua Li Cas Teeb Mosquitto MQTT ntawm AWS: 8 Kauj Ruam
Video: Yuav ua li cas By Nhia Lor [full version] 2024, Kaum ib hlis
Anonim
Yuav Ua Li Cas Teeb Mosquitto MQTT ntawm AWS
Yuav Ua Li Cas Teeb Mosquitto MQTT ntawm AWS

Nyob zoo! Kuv yuav teeb tsa tus tswv lag luam MQTT ntiag tug nrog tus password ntawm kuv AWS (amazon web service) tus lej rau kuv cov haujlwm IOT. Txhawm rau ua qhov no, Kuv tau ua tus lej pub dawb ntawm AWS uas yog qhov zoo rau 1 xyoos los ntawm kev mus ntawm no:

Khoom siv

Sofware siv:

Putty

MQTT LENS

Kauj ruam 1: Tsim tus AWS Account

Tsim AWS Account
Tsim AWS Account

Ua ntej, koj yuav xav tau AWS tus lej nyiaj.. Kuv twb tau tsim tus as khauj dawb uas zoo rau 1 xyoos thiab siv nws los nkag rau hauv. Koj tuaj yeem tsim koj li los ntawm kev mus rau qhov txuas no, nyem "Tsim Tus Account pub dawb" thiab muab qhov tsim nyog ntaub ntawv:

aws.amazon.com/free/?all-free-tier.s

Kauj Ruam 2: Tsim Lub Tshuab Virtual

Tsim Lub Tshuab Virtual
Tsim Lub Tshuab Virtual

Lub tswv yim:

Internet yog tsim los ntawm ob hom tshuab: tus neeg rau zaub mov lossis tus neeg siv khoom. Tus neeg rau zaub mov muab kev pabcuam rau koj thaum tus neeg thov kev pabcuam. Thaum koj qhib nplooj ntawv web no, koj lub tshuab thov luam daim ntawv ntawm nplooj ntawv web no uas tau khaws cia rau hauv server. Thaum tau txais koj qhov kev thov, tus neeg rau zaub mov xa koj daim ntawv tso cai rau koj pom nws. Txhawm rau kom ntseeg tau tias peb tus broker MQTT (cov kev pabcuam) tuaj yeem nkag mus siv lwm lub khoos phis tawj lossis khoom siv hluav taws xob txhua lub sijhawm, peb yuav tsum teeb tsa tus broker mus rau lub tshuab server uas ib txwm qhib thiab txuas nrog internet. Txhawm rau ua qhov no, peb xauj lub tshuab virtual, uas tseem hu ua duab, ntawm AWS uas ua haujlwm zoo li lub khoos phis tawj.

Cov lus qhia:

Ntawm Tus Tswj Kev Tswj

  1. Thaum nkag mus, koj yuav raug coj mus rau AWS Management Console.
  2. Hauv qab qhov kev daws teeb meem nyem rau "Launch a virtual Machine" raws li qhia hauv daim duab.

VIA LUB AMAZON EC2 console

  1. Koj tseem tuaj yeem tsim qhov piv txwv los ntawm kev mus rau qhov txuas no
  2. Nyob rau sab xis saum toj ntawm kab lus taw qhia, xaiv koj thaj tsam tam sim no. Hauv kuv qhov xwm txheej, nws yog Singapore.
  3. Hauv qab qhov Launch instance, nyem rau ntawm "Launch instance" khawm

Kauj Ruam 3: Xaiv Amazon Tshuab Duab (AMI)

Xaiv Amazon Tshuab Duab (AMI)
Xaiv Amazon Tshuab Duab (AMI)

Hauv theem no, koj yuav xaiv hom kev ua haujlwm (linux, windows, redhat thiab ntau yam ntxiv) thiab nco (64 ntsis /86 lossis caj npab) rau peb lub tshuab virtual.

  • Xaiv los ntawm "Pib Pib" hom AMI nyob rau sab laug pane "Ubuntu Server 18.04 LTS (HVM), SSD Volume Type-ami-0f7719e8b7ba25c61 (64-ntsis x86) / ami-02b6622eae4966dfd (64-ntsis Caj Npab) nrog qib dawb ntawm nws lub logo.
  • Ua kom ntseeg tau tias lub hauv paus ntaus ntawv hom: ebs thiab hom virtualization yog HVm txij li nws tau txuas sai dua raws li qhov no

Kauj Ruam 4: Xaiv thiab Kho Kom Zoo Dua Hom

Xaiv thiab Kho Tus Txheej Txheem Hom
Xaiv thiab Kho Tus Txheej Txheem Hom
Xaiv thiab Kho Tus Txheej Txheem Hom
Xaiv thiab Kho Tus Txheej Txheem Hom

Hauv theem kawg, peb teeb tsa lub khoos phis tawj. Ntawm no, peb teeb tsa nws ua server nrog cov cim xeeb hauv qab no thiab txuas nrog rau hauv internet (IPV6 kev txhawb nqa yuav tsum hais tias yog)

  1. Nyem rau ntawm Qib dawb tsim nyog ntawm hom t2.micro.
  2. Koj tuaj yeem nyem "Txheeb xyuas thiab tshaj tawm" tam sim lossis xaiv tau, nyem rau "Tom ntej: Txheeb Xyuas Cov Lus Qhia Ncaj Ncees" nyob rau hauv qab txoj cai kaum
  3. Nyem rau ntawm "Tom ntej: Ntxiv cov cim npe"
  4. Nyem "Mus rau Configure Security tabs". Ntawm no, Nyem ntxiv txoj cai Kom txog thaum koj muaj cov chaw nres nkoj hauv qab no qhib:
  • 1883: MQTT, tsis nkag siab
  • 8883: MQTT, encrypted
  • 8080: MQTT hla WebSockets, tsis nkag siab
  • 8081: MQTT hla WebSockets, encrypted

5. Nyem rau "Txheeb xyuas thiab tso tawm" nyob rau hauv qab txoj cai kaum

Kauj Ruam 5: Txheeb Xyuas Lub Sijhawm Pib

Txheeb Xyuas Kev Tua Hluav Taws Xob
Txheeb Xyuas Kev Tua Hluav Taws Xob
Txheeb Xyuas Kev Tua Hluav Taws Xob
Txheeb Xyuas Kev Tua Hluav Taws Xob

Txheeb xyuas cov ntsiab lus ntawm koj lub tshuab virtual. Hauv AWS, lawv hu nws ua piv txwv.

Kev ceeb toom kev nyab xeeb tuaj yeem tshwm nyob rau hauv qab qhov kev tshuaj xyuas qhov pib

Txhawm rau tshem nws, mus rau "teeb tsa pab pawg ruaj ntseg" thiab xaiv paub IP chaw nyob siv kev cai, lossis siv koj tus IP chaw nyob rau hom "SSH". Hloov qhov peev txheej no txwv cov khoom siv uas tuaj yeem txuas rau koj lub tshuab virtual. Hauv qhov no, peb yuav siv txhua qhov chaw.

  1. Nyem "Launch" ntawm qhov Review tab.
  2. Koj yuav raug nug kom xaiv tus khub tseem ceeb. Xaiv "Tsim tus yuam sij tshiab" ntawm qhov nco thiab nws lub npe. Txuag cov ntawv no txij li koj yuav siv nkag mus rau koj lub tshuab virtual tom qab.
  3. Nyem "Launch Instance"

Kauj Ruam 6: Tau Txais IP Chaw Nyob

Tau txais IP Chaw Nyob
Tau txais IP Chaw Nyob
Tau txais IP Chaw Nyob
Tau txais IP Chaw Nyob
Tau txais IP Chaw Nyob
Tau txais IP Chaw Nyob

Lub tswv yim:

Raws li tau hais ua ntej, muaj server thiab tus neeg siv khoom. Peb tuaj yeem xav txog cov neeg rau zaub mov raws li kev tsim khoom noj khoom haus, internet yog kev pabcuam xa zaub mov thiab peb yog cov neeg siv khoom. Ua ntej peb "thov" khoom noj los ntawm cov chaw tsim khoom noj tshwj xeeb los ntawm kev qhia nws "chaw nyob". Qhov kev pabcuam xa zaub mov mus rau qhov "chaw nyob" ntawd. Kev tsim khoom noj khoom haus "ua haujlwm" cov zaub mov rau cov zaub mov xa khoom uas yog tom qab ntawd xa tuaj rau koj. Ib yam li ntawd, peb cov neeg rau zaub mov xav tau IP Chaw Nyob Pej Xeem kom mus cuag tau hauv internet. Ua li ntawd,

  1. Mus rau Network & Security tab nyob ntawm sab laug pane
  2. Nyem Elastic IPs
  3. Nyem Allocate Elastic IP chaw nyob.
  4. Nias lub "Allocate" khawm thiab tos kom txog thaum nws xa koj mus rau nplooj ntawv nrog tus chij hais tias "Elastic OP Address Allocated"

Kauj Ruam 7: Txuas rau Koj Tus Kheej

Txuas rau Koj Tus Txheej Txheem
Txuas rau Koj Tus Txheej Txheem
Txuas rau Koj Tus Txheej Txheem
Txuas rau Koj Tus Txheej Txheem
Txuas rau Koj Tus Txheej Txheem
Txuas rau Koj Tus Txheej Txheem

Hauv cov xwm txheej tab ntawm sab laug, nyem rau "Cov xwm txheej". Kuv tau txiav txim siab muab kuv lub npe piv txwv li "MQTT Broker" los ntawm txhaj rau lub npov lub npe nyob ntawm thaj chaw npe. Txhawm rau txuas rau qhov piv txwv no:

  1. Txoj cai nyem rau ntawm kab ntawv ntawd thiab nyem nyem txuas.
  2. Xaiv txoj kev sib txuas. Rau tus neeg siv SSH ib leeg, ua raws AWS cov lus qhia ntawm kev txuas siv PUTTY. Saib cov duab rau cov duab txuas ntawm kuv qhov kev teeb tsa.
  3. Tom qab txuas mus rau qhov piv txwv ntaus cov lus txib hauv qab no:

    sudo apt hloov tshiab Hloov kho linux version ntawm koj lub tshuab

    • sudo apt nruab mosquitto mosquitto

      Txhim kho tus broker broker

    • sudo apt nruab mosquitto mosquitto-cov neeg siv khoom

      Nruab ib lub mositto tus thov kev pab

    • mositto -v

      Txheeb xyuas qhov mositto version kom ntseeg tau tias nws tau teeb tsa kom raug. Yuav tsum muaj cov lus hais tias "Qhib ipv4 mloog lub mloog pob ntseg ntawm chaw nres nkoj 1883" yog teeb tsa kom raug. Ib qho "yuam kev: Chaw nyob twb tau siv" txhais tau tias tus broker twb tau khiav lawm

    • mosquitto_sub -h -t "test"

      Mloog cov ncauj lus npe "xeem" ntawm tus broker ntawm qhov chaw nyob no (IPv4 Public IP)

  4. Xa Kev Tshaj Tawm uas siv lub Windows cov neeg siv khoom zoo li MQTT-LENS nrog cov lus pom zoo ib yam li daim duab txuas tom kawg. Koj yuav tsum muaj peev xwm tau txais cov lus ntawm koj li Linux console

Kauj Ruam 8: Ruaj Ntseg Nrog Tus Kheej

Ruaj Ntseg Nrog Tus Kheej
Ruaj Ntseg Nrog Tus Kheej

Ntawm linux console ntaus cov hauv qab no los tsim tus password. Hloov nrog lub npe siv uas koj xaiv.

sudo mosquitto_passwd -c/etc/mosquitto/passwd

Nws yuav teb tus password ob zaug. ceev faj vim nws yuav tsis pom cov tsiaj ntawv raug ntaus. Tom qab qhov no, tsim cov ntaub ntawv teeb tsa npe "default.conf" nyob ntawm cov ntaub ntawv txoj kev "etc/mosquitto/conf.d/" siv linux server cov ntawv sau npe hu ua "nano" raws li tus thawj coj/hauv paus siv los ntawm kev ntaus "sudo"

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

Tom qab qhib cov ntawv, muab tshuaj txhuam hauv qab no. Txuag thiab tawm los ntawm nias Ctrl + X

allow_anonymous cuav

password_file/etc/mosquitto/passwd

Txhawm rau siv qhov kev hloov pauv no rov pib dua lub mos txwv los ntawm kev ntaus "Ctrl+O", "Enter" thiab "Ctrl+X"

sudo systemctl rov pib dua Mositto

Tam sim no koj tuaj yeem sim nws dua siv koj qhov kev xaiv Windows cov neeg siv khoom thiab nkag mus siv lub npe siv thiab tus lej nkag los sib txuas.

Pom zoo: