-
Add
.env
fileBUILD_ENV=dev SQLALCHEMY_DATABASE_URI=postgresql://root:password@postgres/emqx API_KEY=Token 123456789 DD_API_KEY=DD_API_KEY DD_ENV=dev DD_HOSTNAME=local-mqtt1
-
Add
certs
folder with empty filecerts/
└── chain.pem
└── private-key.pem
-
Add
mqtt/default_api_key.conf
username:password
-
Run web, emqx
docker-compose up
-
Open another tab, run migration
docker compose exec app poetry run flask db upgrade
-
Done, test MQTT backend api http://localhost:8001/
-
Testing MQTT broker
- Create user
$ curl --location 'http://localhost:8001/api/user' --header 'Content-Type: application/json' --header 'Authorization: Basic OlRva2VuIDEyMzQ1Njc4OQ==' --data '{"username": "admin", "password": "canopi#1"}'
- Create acl
$ curl --location 'http://localhost:8001/api/acl' --header 'Content-Type: application/json' --header 'Authorization: Basic OlRva2VuIDEyMzQ1Njc4OQ==' --data '{"username": "admin", "pattern": "#", "read": true, "write": true}'
- Connect mqtt
Note: The setup almost the same locally, the difference is run on an EC2 instance.
Go to AWS Console, create EC2 ubuntu
instance
- CPU: t2.medium
- Storage: 40Gb
- SSH into EC2
- Go to AWS console, connect into EC2 and
add your ssh key
. - Go to local computer, ssh into your EC2,
ssh [email protected]
- Clone project
git clone [email protected]:canopi-jsc/canopi-mqtt.git
cd canopi-mqtt
- Adding
.env
file
BUILD_ENV=production
SQLALCHEMY_DATABASE_URI=postgresql://root:password@postgres/emqx
API_KEY=Token 123456789
DD_API_KEY=DD_API_KEY
DD_ENV=production
DD_HOSTNAME=mqtt1
-
API_KEY: a random string. Format:
Token random_string
is used for backend when calling api to create user/acl mqtt
-
DD_API_KEY: create one from datadog
is used for collecting request and send to datadog
https://docs.datadoghq.com/account_management/api-app-keys/#add-an-api-key-or-client-token
-
Buying SSL and add to
certs
folder -
Running web, emqx
docker-compose up
-
Opening another cli tab, ssh into EC2, run migration
docker-compose run app poetry run flask db upgrade
-
Creating cloudflare
record
API: https://mqtt1.eraiot.online
MQTT: mqtt1.eraiot.online:1883
WSS: mqtt1.eraiot.online:8084
Release version (main).
Not include Deploy production
, means 1m30s
flask db init
flask db migrate -m "Initial migration."
flask db upgrade
When install new package, must making docker-copmpose up --build again