一、基础安装
1、安装 Git 2.31
2、安装 Python 3.9.10
(1) CentOS 7 编译安装 Python 3.9.10
(2) 永久设置pip3为国内镜像
3、安装 Node 14
4、安装 SQLite 3.38 或 MySQL 5.7
CentOS 7 安装SQLite 3.38 【不管SQLite了,我们使用MySQL】
5、安装 前端资源
# 升级npm npm install npm -g # 安装yarn npm install yarn -g # 安装quasar npm install @quasar/cli -g # 安装cordova npm install cordova -g # 检查 Quasar 版本 quasar -v
6、下载 GreaterWMS 代码
cd /alidata/www git clone https://gitee.com/Singosgu/GreaterWMS
7、安装 Python 依赖库
cd GreaterWMS pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
8、解决报错问题:PySQLite版本过低【不管SQLite了,我们使用MySQL】
django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher
9、启动后端,端口为 30006
(1) 设置开放防火墙端口:30006(后端),40006(前端)
firewall-cmd --permanent --add-port=30006/tcp firewall-cmd --permanent --add-port=40006/tcp # 重启防火墙(修改配置后要重启防火墙) firewall-cmd --reload
(2) Django默认使用sqlite3作为数据库,这里需要改为MySQL数据库,在greaterwms/settings.py
里面配置DATABASE:
vim greaterwms/settings.py
修改数据库配置:
DATABASES = { #'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': BASE_DIR / 'db.sqlite3', #} 'default':{ 'ENGINE':'django.db.backends.mysql', 'HOST':'127.0.0.1', 'PORT':'3306', 'NAME':'greater_wms', # 数据库名 'USER':'root', 'PASSWORD':'wjb123456', 'OPTIONS':{ 'init_command':"SET sql_mode='STRICT_TRANS_TABLES'" }, } }
创建好数据库:greater_wms
CREATE DATABASE IF NOT EXISTS `greater_wms` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
参考:https://www.cnblogs.com/BlueSkyyj/p/7910957.html
另外,还需要修改 Django 连接MySQL的方式,安装依赖包
pip3 install PyMySQL
修改文件 ./greaterwms/__init__.py
vim ./greaterwms/__init__.py
在头部增加如下代码:
import pymysql pymysql.install_as_MySQLdb()
(3) 启动后端
/usr/local/bin/daphne -p 30006 -b 0.0.0.0 greaterwms.asgi:application # 现在打开浏览器,输入"0.0.0.0:30006",你会看到500错误,恭喜你,你已经可以正常部署接下来的事情了 # 回到GreaterWMS文件夹 Ctrl + C # 数据库生成 python3 manage.py makemigrations # 数据库迁移 python3 manage.py migrate /usr/local/bin/daphne -p 30006 -b 0.0.0.0 greaterwms.asgi:application # 现在打开浏览器,输入"127.0.0.1:30006",你会看到项目已经运行了 # 输入 "127.0.0.1:30006/myip", 你会得到你的内网IP,一定记住它 # 回到GreaterWMS文件夹 Ctrl + C
10、编译 前端资源(注意:如果没有涉及到前端页面的调整,不需要执行这一步操作)
# 进入 templates 文件夹 cd /alidata/www/GreaterWMS/templates # 更改yarn为国内源 yarn config set registry https://registry.npm.taobao.org/ # 单独设置electron国内源 npm config set electron_mirror https://npm.taobao.org/mirrors/electron/ # 等待Yarn安装完成,其实你也可以npm install ,就是会慢一点 /alidata/data/nodejs_repo/node_global_v14/bin/yarn install # 使用quasar命令启动前端页面 /alidata/data/nodejs_repo/node_global_v14/bin/quasar d # 前端会向 "127.0.0.1:30006"发请求,在这里我们只是看下项目是不是可以运行 App dir........... /alidata/www/GreaterWMS/templates App URL........... http://localhost:8080 Dev mode.......... spa Pkg quasar........ v1.16.0 Pkg @quasar/app... v2.2.10 Transpiled JS..... yes (Babel) # 退回到templates文件夹 Ctrl + C
注意:
从2.0.19版本以后,优化了请求地址修改方式,直接修改templates/dist/spa/statics/baseurl.js
,中的baseurl和wsurl,就可以成功更改前端请求地址,不再需要做下面的quasar build打包工作。
如果需要修改前端内容,则还需要修改templates/public/statics/baseurl.js
中的baseurl和wsurl,然后重新使用quasar build进行打包
/alidata/data/nodejs_repo/node_global_v14/bin/quasar build
11、修改前端配置
vim templates/dist/spa/statics/baseurl.js
把里面的端口 8008
改为 30006
二、配置 Nginx
官方的Nginx配置 模板:nginx.conf
user root; worker_processes auto; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; gzip on; gzip_min_length 1k; gzip_comp_level 4; gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; gzip_disable "MSIE [1-6]\."; gzip_vary on; proxy_redirect off; proxy_set_header Host $host; proxy_set_header https $https; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 75M; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为保存到本地再传给用户 client_body_buffer_size 256k; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; proxy_connect_timeout 300s; #nginx跟后端服务器连接超时时间(代理连接超时) proxy_read_timeout 300s; #连接成功后,后端服务器响应时间(代理接收超时) proxy_send_timeout 300s; proxy_buffer_size 64k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小 proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置 proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2) proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘 proxy_ignore_client_abort on; #不允许代理端主动关闭连接 upstream GreaterWMS { server 127.0.0.1:8008; } server { listen 80; server_name {{ Domin Name }}; rewrite ^(.*)$ https://{{ Domin Name }}$1; } server { listen 443 ssl; server_name {{ Domin Name }}; root /path/to/GreaterWMS; charset utf-8; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; client_max_body_size 75M; ssl_certificate /path/to/GreaterWMS.pem; ssl_certificate_key /path/to/GreaterWMS.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; access_log off; error_log /path/to/GreaterWMS/greaterwms-error.log error; location /websocket/ { proxy_pass http://GreaterWMS/; proxy_read_timeout 60s; proxy_set_header Host $host; proxy_set_header X-Real_IP $remote_addr; proxy_set_header X-Forwarded-for $remote_addr; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'Upgrade'; } location / { #root html; #index testssl.html index.html index.htm; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8008/; } location /static/ { alias /path/to/GreaterWMS/static_new/; } location /media/{ alias /path/to/GreaterWMS/media/; } } }
根据自己的实际情况,调整如下:
(1) nginx/conf/nginx.conf
user www www; worker_processes auto; pid logs/nginx.pid; events { worker_connections 4096; } http { include mime.types; default_type application/octet-stream; sendfile on; gzip on; gzip_min_length 1k; gzip_comp_level 4; gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; gzip_disable "MSIE [1-6]\."; gzip_vary on; proxy_redirect off; proxy_set_header Host $host; proxy_set_header https $https; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 75M; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为保存到本地再传给用户 client_body_buffer_size 256k; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; proxy_connect_timeout 300s; #nginx跟后端服务器连接超时时间(代理连接超时) proxy_read_timeout 300s; #连接成功后,后端服务器响应时间(代理接收超时) proxy_send_timeout 300s; proxy_buffer_size 64k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小 proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置 proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2) proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘 proxy_ignore_client_abort on; #不允许代理端主动关闭连接 server { listen 80; #server_name localhost alias 127.0.0.1; location / { root html; index index.html index.php; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } include vhost/*.conf; }
(2) nginx/conf/vhost/GreaterWMS_web_40006.conf
upstream GreaterWMS { server 127.0.0.1:30006; } server { listen 40006; root /alidata/www/GreaterWMS; charset utf-8; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; client_max_body_size 75M; access_log off; error_log /alidata/logs/GreaterWMS/greaterwms-error.log error; location /websocket/ { proxy_pass http://GreaterWMS/; proxy_read_timeout 60s; proxy_set_header Host $host; proxy_set_header X-Real_IP $remote_addr; proxy_set_header X-Forwarded-for $remote_addr; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'Upgrade'; } location / { #root html; #index testssl.html index.html index.htm; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://GreaterWMS/; } location /static/ { alias /alidata/www/GreaterWMS/static_new/; } location /media/{ alias /alidata/www/GreaterWMS/media/; } }
三、使用 Supervisord 启动 /usr/local/bin/daphne
1、安装supervisor
pip3 install supervisor
配置软连接:
ln -s /usr/local/lib/python3.9/site-packages/supervisor/supervisord.py /usr/bin/supervisord
2、新建配置文件:
vim /etc/supervisord.conf
增加内容:
[supervisord] nodaemon=false #调试的时候可以设置为true user=root [program:daphne] directory=/alidata/www/GreaterWMS #项目目录 (绝对路径) command=/usr/local/bin/daphne -p 30006 -b 0.0.0.0 greaterwms.asgi:application #启动命令 autostart=true autorestart=true stdout_logfile=/alidata/logs/GreaterWMS/daphne.log redirect_stderr=true
3、启动supervisord
supervisord -c /etc/supervisord.conf
4、关闭 supervisord
(1) 先找到 对应的进程ID
ps -ef | grep supervisord
(2) 然后杀死进程
kill -9 进程ID值
参考:
https://gitee.com/Singosgu/GreaterWMS/blob/master/Centos%20Build(CN).md
CentOS 7安装GreaterWMS时报错(2):安装electron项目的时候老是报错:Command failed.