wuxing@name
  • Archives
  • Baby
  • CODING
  • About
wuxing@name
  • Archives
  • Baby
  • CODING
  • About
Category:

个人日志

个人兴趣爱好。

个人日志

Gunicorn FastAPI 宝塔Linux 部署

by Andy 8月 26, 2021

使用宝塔Linux 7.7.0 CentOS 7.5.1804 x86_64

Linux环境下一直使用宝塔。在部署 FastAPI 时遇到困难。
使用 Python项目管理器、Supervisor管理器,只能使用Python 的方式运行 uvicorn,或ssh 命令进入虚拟环境后运行gunicorn。无法直接使用 Gunicorn 运行FastAPI。

source /data/python/project1_venv/bin/activate
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8751

我没在网上找到基于宝塔Linux的 Gunicorn 运行FastAPI的成功案例。
网上案例与本人实测,在使用 Python项目管理器 启动方式 Gunicorn 都会出现 内部错误,由于在日志上没有显示错误类型,也不知道问题所在。估计是程序没有适配FastAPI。

解决方法、步骤

一、程序打包、上传
将程序文件、requirements.txt上传至服务器。

pip freeze > requirements.txt

二、使用Python项目管理器下载虚拟环境、模块(建议);
(开发、部署环境相同时,也可以本地上传。)

确认后,无需运行程序,本步骤仅为下载虚拟环境、模块。

三、使用宝塔应用管理器
添加应用

应用环境需要选择与开发环境相同的环境,使用刚才Python项目管理器下载的环境,方法见下文。
启动文件选择刚才Python项目管理器下载的gunicorn 模块
执行目录选择项目目录;
启动参数 根据项目填写:默认为:

gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8751
#或 使用刚才Python项目管理器 生成的conf文件 gunicorn.conf
gunicorn main:app -c gunicorn.conf

点击添加按钮,即可完成应用部署。

应用环境部分说明

启动文件选择使用的Python版本。
如:/www/wwwroot/xFAPI_demo/xFAPI_demo_venv/bin/python

如果配置文件提示
!!! !!! WARNING: configuration file should have a valid Python extension. !!!
将文件gunicorn.conf更改为 gunicorn.py再运行。

import multiprocessing

# 监听内网端口8000
bind = "0.0.0.0:8751"
# 并行工作进程数
workers = multiprocessing.cpu_count() * 2 + 1
# 监听队列
backlog = 2048
# 工作模式协程。
worker_class = "uvicorn.workers.UvicornWorker"
# 设置守护进程,将进程交给supervisor管理
daemon = 'false'
# worker_connections最大客户端并发数量,默认情况下这个值为1000。
worker_connections = 2000
# 设置日志记录水平
loglevel = 'info'
# supervisor管理gunicorn 日志输出到supervisor日志文件
errorlog = '-'
accesslog = '-'
# 日志格式
logconfig_dict = {
    'formatters': {
        "generic": {
            "format": "%(process)d %(asctime)s %(levelname)s %(message)s",  # 打日志的格式
            "datefmt": "[%Y-%m-%d %H:%M:%S %z]",  # 时间显示方法
            "class": "logging.Formatter"
        }
    }
}

参考文献:
https://blog.csdn.net/sun_hentai/article/details/114878143
https://www.sitstars.com/archives/86/
https://blog.csdn.net/weixin_42881588/article/details/108768493

8月 26, 2021 0 comment
0 FacebookTwitterPinterestEmail
个人日志

DeepL机器翻译的力量

by Andy 7月 7, 2020

https://www.deepl.com/translator

DeepL 是一家德国公司,其目标是通过使用人工智能消除世界范围内的语言障碍。DeepL 发布了一套全新的翻译系统,代表着翻译质量的巨大飞跃。其人工智能远远优于所有现存的翻译技术,自 2017 年以来,它向公众提供了基于计算机翻译系统的 DeepL 翻译器,根据盲测,它实现了世界上最好的翻译质量。

DeepL is a German company that aims to eliminate language barriers worldwide through the use of artificial intelligence. DeepL has released a new translation system that represents a huge leap forward in translation quality. Its artificial intelligence is far superior to all existing translation technologies, and since 2017 it has offered the public computer-based Translation System’s DeepL translator, which, according to a blind test, achieves the best translation quality in the world.

7月 7, 2020 0 comment
0 FacebookTwitterPinterestEmail
个人日志

net Core Rest Api 调用

by Andy 7月 7, 2020

RestSharp

7月 7, 2020 0 comment
0 FacebookTwitterPinterestEmail
个人日志

Oracle EM 安装 修复

by Andy 5月 15, 2020

EM经常会莫名其妙的无法登陆。
卸载
emca -deconfig dbcontrol db -repos drop
安装
emca -config dbcontrol db -repos create

无法卸载:
EM运行异常,导致文件占用,无法卸载。先将占用em文件的进程关闭。

无法安装:
job_queue_processes 必须大于等于1
在9i和10g中,默认值是0;在11g和12cR1版本中,默认值为1000,在12cR2和18c版本中,默认值为4000。
查参数内容
show parameter job_queue_processes;
并设置合适的数值,如:
alter system set job_queue_processes=2;

无法使用:
请确保EM 的默认端口不会被 防火墙阻挡。

EM暂挂状态 修复
重新加载EM 参数、设置即可,不需要 设置其他时区。
1.关闭EM
emctl stop dbconsole
2.重新加载设置
emctl resetTZ agent
3.开启EM
emctl start dbconsole

5月 15, 2020 0 comment
1 FacebookTwitterPinterestEmail
个人日志

wpf c# login and Upgrade

by Andy 12月 6, 2019
12月 6, 2019 0 comment
0 FacebookTwitterPinterestEmail
个人日志

Open SSL 证书生成 对exe 签名

by Andy 11月 7, 2019

set RANDFILE=C:.rnd
set OPENSSL_CONF=C:\OpenSSL-Win64\bin\openssl.cfg

genrsa -des3 -out root.key 1024
req -new -key root.key -out root.csr
x509 -req -days 9553 -sha256 -extfile openssl.cfg -extensions v3_req -in root.csr -signkey root.key -out root.crt

genrsa -des3 -out client.key 1024
req -new -key client.key -out client.csr
x509 -req -sha256 -extensions v3_req -CA root.crt -CAkey root.key -in client.csr -out client.crt

genrsa –des3 -out server.key 1024
req -new -key server.key -out server.csr

Continue Reading
11月 7, 2019 0 comment
0 FacebookTwitterPinterestEmail
个人日志

V-lang

by Andy 6月 24, 2019

早起的鸟儿没虫吃。

6月 24, 2019 0 comment
0 FacebookTwitterPinterestEmail
东搞西搞

ASUS 开启 虚拟 VT-x

by Andy 1月 10, 2014

bois 截图
ASUS 的新版BOIS 界面,主板 H81M-A。
开启 Intel VT-x 的方法,在 Advanced Mode 高级模式 中 进行设置。
注意 这里请用鼠标滚轮 与 方向键向下滚动界面,我开始就被坑了 找了半天也没发现。

1月 10, 2014 1 comment
0 FacebookTwitterPinterestEmail
  • 1
  • 2
  • 3
  • …
  • 6

About Me

About Me

Writer & Reader

Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed.

Recent Posts

  • Gunicorn FastAPI 宝塔Linux 部署

    8月 26, 2021
  • DeepL机器翻译的力量

    7月 7, 2020
  • net Core Rest Api 调用

    7月 7, 2020
  • Oracle EM 安装 修复

    5月 15, 2020
  • wpf c# login and Upgrade

    12月 6, 2019
  • Facebook
  • Twitter
  • Instagram
  • Pinterest
  • Tumblr
  • Youtube
  • Bloglovin
  • Snapchat

@2019 - All Right Reserved. Designed and Developed by PenciDesign


Back To Top