FreeBSD
在本指南中,您将在FreeBSD服务器上部署MyEMS。
Prerequisites
本指南介绍如何在FreeBSD 13.2上安装MyEMS。硬件需求取决于所选数据库和连接到系统的设备数量。要在一台机器上运行MyEMS和MySQL,您至少需要4GB的RAM。
更新系统并安装工具:
pkg install git
pkg install python3
pkg install py39-pip-22.3.1
pkg install nginx
pkg install monit
克隆源代码:
cd ~
git clone https://gitee.com/myems/myems
第1步 数据库
参考 Database
第2步 myems-api
- 安装 myems-api 服务:
cp -r ~/myems/myems-api /myems-api
cd /myems-api
pip install -r requirements.txt
提示
如果您遇到'Failed building wheel for pillow'错误, 您需要 安装 Pillow
根据example.env创建.env文件,并根据需要编辑.env:
cp /myems-api/example.env /myems-api/.env
nano /myems-api/.env
安装 monit 配置文件:
nano /etc/monit.d/myems-api
check process mymes-api with pidfile /var/run/myems-api/pid
start program = "/usr/local/bin/gunicorn -b 0.0.0.0:8000 --pid /var/run/myems-api/pid --timeout 600 --workers=4 app:api &"
stop program = "/bin/kill -s TERM $MAINPID"
if 3 restarts within 5 cycles then unmonitor
接下来启用这些服务,以便它们在启动时自动启动:
monit restart
第3步 myems-admin
- 安装 NGINX 服务器
参考 http://nginx.org/en/docs/install.html 启用nginx服务:
service nginx enable
- 配置 NGINX
nano /etc/nginx/nginx.conf
In the 'http' section, add some directives:
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;
...
}
在目录 /etc/nginx/conf.d/ 下新建 一个文件:
nano /etc/nginx/conf.d/myems-admin.conf
编写如下指令, 如果myems-api服务运行在其它服务器上则用实际的地址替换 myems-api 默认地址 http://127.0.0.1:8000/
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'
## Replace the default myems-api url http://127.0.0.1:8000/ with actual url if the myems-api servcie hosted on different server
location /api {
proxy_pass http://127.0.0.1:8000/;
proxy_connect_timeout 75;
proxy_read_timeout 600;
send_timeout 600;
}
}
- 安装 myems-admin : 如果服务器无法连接到internet,请压缩myems/myems-admin文件夹并将其上传到服务器,然后将其解压缩到~/myems/myems-admin
mkdir /var/www
cp -r ~/myems/myems-admin /var/www/myems-admin
chmod 0755 /var/www/myems-admin
检查配置文件,必要时进行更改:
nano /var/www/myems-admin/app/api.js
警告
“upload”文件夹用于用户上传的文件。升级myems-admin时,请勿删除/移动/覆盖“upload”文件夹。
/var/www/myems-admin/upload
重启nginx服务:
service nginx restart
第4步 myems-modbus-tcp
在此步骤中,您将安装myems-modbus-tcp服务。
cp -r ~/myems/myems-modbus-tcp /myems-modbus-tcp
cd /myems-modbus-tcp
pip install -r requirements.txt
将exmaple.ev文件复制到.env并修改.env文件:
cp /myems-modbus-tcp/example.env /myems-modbus-tcp/.env
nano /myems-modbus-tcp/.env
安装 monit 服务:
nano /etc/monit.d/myems-modbus-tcp
check file myems-modbus-tcp path /myems-modbus-tcp/main.py
start program = "/usr/local/bin/python3 /myems-modbus-tcp/main.py"
stop program = "/bin/kill -s TERM $MAINPID"
if 3 restarts within 5 cycles then unmonitor
启动服务:
monit restart
第5步 myems-cleaning
在此步骤中,您将安装myems-cleaning服务。
cp -r ~/myems/myems-cleaning /myems-cleaning
cd /myems-cleaning
pip install -r requirements.txt
将exmaple.ev文件复制到.env并修改.env文件:
cp /myems-cleaning/example.env /myems-cleaning/.env
nano /myems-cleaning/.env
安装monit服务:
nano /etc/monit.d/myems-cleaning
check file myems-cleaning path /myems-cleaning/main.py
start program = "/usr/local/bin/python3 /myems-cleaning/main.py"
stop program = "/bin/kill -s TERM $MAINPID"
if 3 restarts within 5 cycles then unmonitor
启动服务:
monit restart