Raspberry Pi
En esta guía, desplegará MyEMS en una Raspberry Pi.
Requisitos previos
- Raspberry Pi 5 o Raspberry Pi 4 Modelo B
- Raspberry Pi OS (64 bits), un port de Debian Bookworm con el escritorio de Raspberry Pi. Lanzado: 2024-07-04
Clonar el código fuente
sudo apt install git
sudo apt install pip
sudo apt install ufw
cd ~ && git clone https://github.com/myems/myems
Step 1 Database
- Setup MySQL Server
sudo apt update
sudo apt upgrade
sudo apt install mariadb-server
Por defecto, MySQL se instala sin ninguna contraseña configurada, lo que significa que puede acceder al servidor MySQL sin autenticación. Ejecute el siguiente comando para iniciar el proceso de aseguramiento de MySQL.
sudo mysql_secure_installation
Enter current password for root (enter for none): [Enter key or return key]
Switch to unix_socket authentication [Y/n] Y
Change the root password? [Y/n] Y
New password: !MyEMS1
Re-enter new password: !MyEMS1
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
- Instale el esquema de base de datos y los scripts para MyEMS.
Consulte Base de datos
Step 2 myems-api
- Install myems-api service:
sudo cp -r ~/myems/myems-api /myems-api
cd /myems-api
Para evitar el 'error: externally-managed-environment', cree una carpeta de entorno virtual de configuración:
sudo python -m venv venv
Comience a usar el entorno virtual
source venv/bin/activate
Instale los requisitos
sudo venv/bin/pip install -r requirements.txt
Desactive el entorno virtual
deactivate
Cree el archivo .env basado en example.env y edite el archivo .env si es necesario:
sudo cp /myems-api/example.env /myems-api/.env
sudo nano /myems-api/.env
Cambie la ruta de gunicorn en myems-api.service:
sudo nano /myems-api/myems-api.service
[Unit]
Description=myems-api daemon
Requires=myems-api.socket
After=network.target
[Service]
PIDFile=/run/myems-api/pid
User=root
Group=root
WorkingDirectory=/myems-api
ExecStart=/myems-api/venv/bin/gunicorn -b 0.0.0.0:8000 --pid /run/myems-api/pid --timeout 600 --workers=4 app:api
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Agregue el puerto al firewall:
sudo ufw allow 8000
Setup systemd configure files:
sudo cp /myems-api/myems-api.service /lib/systemd/system/
sudo cp /myems-api/myems-api.socket /lib/systemd/system/
sudo cp /myems-api/myems-api.conf /usr/lib/tmpfiles.d/
Luego habilite los servicios para que se inicien automáticamente al arrancar:
sudo systemctl enable myems-api.socket
sudo systemctl enable myems-api.service
Inicie los servicios:
sudo systemctl start myems-api.socket
sudo systemctl start myems-api.service
Step 3 myems-admin
- Instale el servidor NGINX
Consulte http://nginx.org/en/linux_packages.html#Debian
sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx
sudo apt update
sudo apt install nginx
- Configure NGINX
sudo nano /etc/nginx/nginx.conf
En la sección 'http', agregue algunas directivas:
http {
client_header_timeout 600;
client_max_body_size 512M;
gzip on;
gzip_min_length 512;
gzip_proxied any;
gzip_types *;
gzip_vary on;
proxy_buffering off;
...
}
En la sección 'http', agregue una nueva sección 'server' con las siguientes directivas:
server {
listen 8001;
server_name myems-admin;
location / {
root /var/www/myems-admin;
index index.html index.htm;
}
## To avoid CORS issue, use Nginx to proxy myems-api to path /api
## Add another location /api in 'server' and replace demo address http://127.0.0.1:8000/ with actual url
location /api {
proxy_pass http://127.0.0.1:8000/;
proxy_connect_timeout 75;
proxy_read_timeout 600;
send_timeout 600;
}
}
- Install myems-admin :
sudo mkdir /var/www
sudo cp -r ~/myems/myems-admin /var/www/myems-admin
sudo chmod 0755 -R /var/www/myems-admin
Verifique el archivo de configuración y cámbielo si es necesario:
sudo nano /var/www/myems-admin/app/api.js
La carpeta 'upload' es para archivos subidos por el usuario. NO elimine/mueva/sobrescriba la carpeta 'upload' cuando actualice myems-admin.
/var/www/myems-admin/upload
Inicie Nginx:
sudo systemctl start nginx
Agregue el puerto al firewall:
sudo ufw allow 8001
Step 4 myems-modbus-tcp
En este paso, instalará el servicio myems-modbus-tcp.
sudo cp -r ~/myems/myems-modbus-tcp /myems-modbus-tcp
cd /myems-modbus-tcp
Para evitar el 'error: externally-managed-environment', cree una carpeta de entorno virtual de configuración:
sudo python -m venv venv
Comience a usar el entorno virtual
source venv/bin/activate
Instale los requisitos
sudo venv/bin/pip install -r requirements.txt
Desactive el entorno virtual
deactivate
Copie el archivo example.env a .env y modifique el archivo .env:
sudo cp /myems-modbus-tcp/example.env /myems-modbus-tcp/.env
sudo nano /myems-modbus-tcp/.env
Cambie la ruta de python en myems-modbus-tcp.service
sudo nano myems-modbus-tcp.service
[Unit]
Description=myems-modbus-tcp daemon
After=network.target
[Service]
User=root
Group=root
ExecStart=/myems-modbus-tcp/venv/bin/python3 /myems-modbus-tcp/main.py
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
Restart=always
[Install]
WantedBy=multi-user.target
Configure el servicio systemd:
sudo cp myems-modbus-tcp.service /lib/systemd/system/
Habilite el servicio:
sudo systemctl enable myems-modbus-tcp.service
Inicie el servicio:
sudo systemctl start myems-modbus-tcp.service
Monitoree el servicio:
sudo systemctl status myems-modbus-tcp.service
Vea el registro:
cat /myems-modbus-tcp.log
Step 5 myems-cleaning
En este paso, instalará el servicio myems-cleaning.
sudo cp -r ~/myems/myems-cleaning /myems-cleaning
cd /myems-cleaning
Para evitar el 'error: externally-managed-environment', cree una carpeta de entorno virtual de configuración:
sudo python -m venv venv
Comience a usar el entorno virtual
source venv/bin/activate
Instale los requisitos
sudo venv/bin/pip install -r requirements.txt
Desactive el entorno virtual
deactivate
Copie el archivo example.env a .env y modifique el archivo .env:
sudo cp /myems-cleaning/example.env /myems-cleaning/.env
nano /myems-cleaning/.env
Cambie la ruta de python en myems-cleaning.service
sudo nano myems-cleaning.service
[Unit]
Description=myems-cleaning daemon
After=network.target
[Service]
User=root
Group=root
ExecStart=/myems-cleaning/venv/bin/python3 /myems-cleaning/main.py
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
Restart=always
[Install]
WantedBy=multi-user.target
Configure el servicio systemd:
sudo cp /myems-cleaning/myems-cleaning.service /lib/systemd/system/
Habilite el servicio:
sudo systemctl enable myems-cleaning.service
Inicie el servicio:
sudo systemctl start myems-cleaning.service
Monitoree el servicio:
sudo systemctl status myems-cleaning.service
Vea el registro:
cat /myems-cleaning.log
Step 6 myems-normalization
En este paso, instalará el servicio myems-normalization.
sudo cp -r ~/myems/myems-normalization /myems-normalization
cd /myems-normalization
Para evitar el 'error: externally-managed-environment', cree una carpeta de entorno virtual de configuración:
sudo python -m venv venv
Comience a usar el entorno virtual
source venv/bin/activate
Instale los requisitos
sudo venv/bin/pip install -r requirements.txt
Desactive el entorno virtual
deactivate
Copie el archivo example.env a .env y modifique el archivo .env:
sudo cp /myems-normalization/example.env /myems-normalization/.env
sudo nano /myems-normalization/.env
Cambie la ruta de python en myems-normalization.service
sudo nano myems-normalization.service
[Unit]
Description=myems-normalization daemon
After=network.target
[Service]
User=root
Group=root
ExecStart=/myems-normalization/venv/bin/python3 /myems-normalization/main.py
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
Restart=always
[Install]
WantedBy=multi-user.target
Configure el servicio systemd:
sudo cp /myems-normalization/myems-normalization.service /lib/systemd/system/
Habilite el servicio:
sudo systemctl enable myems-normalization.service
Inicie el servicio:
sudo systemctl start myems-normalization.service
Monitoree el servicio:
sudo systemctl status myems-normalization.service
Vea el registro:
cat /myems-normalization.log
Step 7 myems-aggregation
En este paso, instalará el servicio myems-aggregation.
sudo cp -r ~/myems/myems-aggregation /myems-aggregation
cd /myems-aggregation
Para evitar el 'error: externally-managed-environment', cree una carpeta de entorno virtual de configuración:
sudo python -m venv venv
Comience a usar el entorno virtual
source venv/bin/activate
Instale los requisitos
sudo venv/bin/pip install -r requirements.txt
Desactive el entorno virtual
deactivate
Copie el archivo example.env a .env y modifique el archivo .env:
sudo cp /myems-aggregation/example.env /myems-aggregation/.env
sudo nano /myems-aggregation/.env
Cambie la ruta de python en myems-aggregation.service
sudo nano myems-aggregation.service
[Unit]
Description=myems-aggregation daemon
After=network.target
[Service]
User=root
Group=root
ExecStart=/myems-aggregation/venv/bin/python3 /myems-aggregation/main.py
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
Restart=always
[Install]
WantedBy=multi-user.target
Configure el servicio systemd:
sudo cp /myems-aggregation/myems-aggregation.service /lib/systemd/system/
Habilite el servicio:
sudo systemctl enable myems-aggregation.service
Inicie el servicio:
sudo systemctl start myems-aggregation.service
Monitoree el servicio:
sudo systemctl status myems-aggregation.service
Vea el registro:
cat /myems-aggregation.log
Step 8 myems-web
En este paso, instalará el servicio de interfaz web de myems-web.
-
Instale el servidor NGINX (si ya está instalado en myems-admin, puede ignorarlo) Consulte http://nginx.org/en/docs/install.html
-
Configure NGINX
Elimine los archivos predeterminados
sudo rm /etc/nginx/sites-enabled/default
sudo rm /etc/nginx/conf.d/default.conf
Agregue un nuevo archivo en /etc/nginx/conf.d/
sudo nano /etc/nginx/conf.d/myems-web.conf
Agregue una nueva sección 'server' con las siguientes directivas:
server {
listen 80;
server_name myems-web;
location / {
root /var/www/myems-web;
index index.html index.htm;
# add try_files directive to avoid 404 error while refreshing pages
try_files $uri /index.html;
}
## To avoid CORS issue, use Nginx to proxy myems-api to path /api
## Add another location /api in 'server'
## NOTE: replace dafault address http://127.0.0.1:8000/ with actual IP or URL
location /api {
proxy_pass http://127.0.0.1:8000/;
proxy_connect_timeout 75;
proxy_read_timeout 600;
send_timeout 600;
}
}
- Install MyEMS Web UI:
Install NodeJS:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -
sudo apt-get install -y nodejs
Modifique el archivo config.js:
Obtenga el mapboxToken en https://mapbox.com y luego establezca showOnlineMap en true. Si desea desactivar la función de mapa en línea, establezca showOnlineMap en false
cd ~/myems/myems-web
sudo nano src/config.js
Compile y comprima:
sudo npm i --unsafe-perm=true --allow-root --legacy-peer-deps
sudo npm run build
Instale
sudo mv build /var/www/myems-web
Reinicie NGINX:
sudo systemctl restart nginx
Agregue el puerto al firewall:
sudo ufw allow 80
Post-instalación
¡Felicidades! Ahora puede iniciar sesión en la interfaz de administración y la interfaz web de MyEMS.
Puertos predeterminados
MyEMS Web UI: 80
MyEMS API: 8000
MyEMS Admin UI: 8001
Suponiendo que la dirección del servidor sea 192.168.1.8 (reemplace con la dirección real del servidor) Acceda a MyEMS Web UI en http://192.168.1.8 (el 80 se puede omitir) Acceda a MyEMS Admin UI en http://192.168.1.8:8001
Contraseñas predeterminadas
MyEMS Admin UI
Nombre de usuario:
administrator
Contraseña:
!MyEMS1
MyEMS Web UI
Nombre de usuario:
administrator@myems.io
Contraseña:
!MyEMS1