Python 官方文档:入门教程 => 点击学习
文章目录 一、概述二、购买服务器1、简单介绍2、为什么使用Linux系统3、使用Xshell连接服务器 三、配置服务器1、关于端口2、配置服务器的安全组(入方向) 四、上传代码1、下载
本质三件事:
在阿里云、腾讯云或者其他平台购买一台服务器。
本文以 阿里云 + centos 7.9操作系统来进行操作。
根据需要为服务器选择合适的:CPU内核数量、内存大小、磁盘大小、带宽大小…
同时为该服务器设置登录的用户名和密码,后期登录该服务器。同时获得一个公网ip,用于连接该服务器。
本地下载安装Xshell:https://www.xshell.com/zh/xshell-download/
方式一:
方式二:也可以直接Xshell命令行中直接输入:
ssh root@101.201.52.143
弹出的验证框中输入密码即可
出现这个界面则表示连接成功:
ip地址:定位电脑(服务器)
端口:定位程序
端口 | 应用程序 |
---|---|
22 | SSH |
3306 | Mysql |
6379 | Redis |
80 | Http |
443 | https |
目的:配置服务器的开放端口,使得可以通过ip+端口远程连接对应的服务。
根据需要开放对应的端口。
百度网盘链接:https://pan.baidu.com/s/1MWce-lSTlnt5xRP1VGXFBw
提取码:ggit
安装成功在电脑任意位置右键出现git bash here和git gui here如下:
gitee官网:https://gitee.com/
完成登录后,点击右上角创建仓库:
仓库名称一般就是项目代码名称,方便对应,填好名称点击创建即可。
仓库地址:https://gitee.com/kd_harden_iring/test
直接使用别人写好的:https://github.com/github/gitignore/blob/main/Python.gitignore
# Byte-compiled / optimized / DLL files__pycache__/*.py[cod]*$py.class# C extensions*.so# Distribution / packaging.pythonbuild/develop-eggs/dist/downloads/eggs/.eggs/lib/lib64/parts/sdist/var/wheels/share/Python-wheels/*.egg-info/.installed.cfg*.eggMANIFEST# PyInstaller# Usually these files are written by a python script from a template# before PyInstaller builds the exe, so as to inject date/other infos into it.*.manifest*.speC# Installer logspip-log.txtpip-delete-this-directory.txt# Unit test / coverage reportshtmlcov/.tox/.nox/.coverage.coverage.*.cachenosetests.xmlcoverage.xml*.cover*.py,cover.hypothesis/.pytest_cache/cover/# Translations*.mo*.pot# Django stuff:*.loglocal_settings.pydb.sqlite3Db.sqlite3-journal# Flask stuff:instance/.WEBassets-cache# scrapy stuff:.scrapy# Sphinx documentationdocs/_build/# PyBuilder.pybuilder/target/# Jupyter Notebook.ipynb_checkpoints# IPythonprofile_default/ipython_config.py# pyenv# For a library or package, you might want to ignore these files since the code is# intended to run in multiple environments; otherwise, check them in:# .python-version# pipenv# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.# However, in case of collaboration, if having platfORM-specific dependencies or dependencies# having no cross-platform support, pipenv may install dependencies that don't work, or not# install all needed dependencies.#Pipfile.lock# poetry# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.# This is especially recommended for binary packages to ensure reproducibility, and is more# commonly ignored for libraries.# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control#poetry.lock# pdm# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.#pdm.lock# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it# in version control.# https://pdm.fming.dev/#use-with-ide.pdm.toml# PEP 582; used by e.g. GitHub.com/David-OConnor/pyflow and github.com/pdm-project/pdm__pypackages__/# Celery stuffcelerybeat-schedulecelerybeat.pid# SageMath parsed files*.sage.py# Environments.env.venvenv/venv/ENV/env.bak/venv.bak/# Spyder project settings.spyderproject.spyproject# Rope project settings.ropeproject# mkdocs documentation/site# mypy.mypy_cache/.dmypy.JSONdmypy.json# Pyre type checker.pyre/# pytype static type analyzer.pytype/# Cython debug symbolscython_debug/# PyCharm# JetBrains specific template is maintained in a separate JetBrains.gitignore that can# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore# and can be added to the global gitignore or merged into this file. For a more nuclear# option (not recommended) you can uncomment the following to ignore the entire idea folder.#.idea/
任意位置右键,git bash here出现git命令行窗口输入(一次性命令):
git config --global user.name “yjx”
git config --global user.email “3360@163.com”
在该位置右键,点击git bash here再依次输入:
git initgit remote add origin https://gitee.com/kd_harden_iring/test注意:git init执行后可以看到在当前目录下生成了一个空的.git本地仓库git remote add 别名代指远程仓库地址(下次使用) 远程仓库的地址(注意替换为自己在gitee中生成的远程仓库链接)
git add .git commit -m 'init'git push origin master'init'为了标识每次提交的说明,输入以上三句即可完成将代码提交到gitee远程仓库。
注意:执行第三句会弹出输入账号和密码,这个账号和密码是gitee网站的账号和密码
执行后即可在gitee仓库中看到如下内容:
git add .git commit -m 'update_module'git push origin master
即可更新仓库,同步本地和远程仓库的代码。
yum install git -y
cd /data/mkdirs wwwcd /data/www/
git clone https://gitee.com/kd_harden_iring/test前面生成的gitee仓库的连接,切换为自己的
python3.9.5
虚拟环境
uwsgi:接收用户的请求,高效
Nginx:反向代理请求,分类用户请求,转发用户请求
在Xshell中运行以下命令:
注:执行yum install mysql-devel -y可能会报错,具体解决:
下载Python3.9.5源码:
yum install wget -ycd /data/wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
解压—编译—安装:
tar -xvf Python-3.9.5.tgzcd Python-3.9.5.tgz./configuremake allmake install
Python解释器配置豆瓣源:
pip3.9 config set global.index-url https://pypi.douban.com/simple/
pip3.9 install virtualenv
mkdir /envscd /envs/virtualenv /envs/test --python=python3.9
source /envs/test/bin/activatepip install flask
激活虚拟环境,在虚拟环境中安装source /envs/test/bin/activatepip install uwsgi
cd /data/www/test/vim test_uwsgi.ini
编写uwsgi的配置文件:
[uwsgi]Socket = 127.0.0.1:8001chdir = /data/www/test/wsgi-file = app.pycallable = appprocesses = 1virtualenv = /envs/test/
uwsgi --ini test _uwsgi.ini
yum install nginx -y
vim /etc/nginx/nginx.conf
systemctl enable nginxsystemctl start nginx
如果无法启动80端口被占用,输入以下命令查看并关闭相关进程:
lsof -i:80 80端口被占用的问题查看
如上:关闭httpd即可
再次启动nginx即可成功:systemctl start nginx
nginx启动后,依次执行以下语句即可拉起test项目
source /envs/test/bin/activatecd /data/www/test/uwsgi --ini test_uwsgi.ini >nohup.out
浏览器中输入你服务器的公网ip,即可看到你的项目
每个项目所依赖的库不同,需要你在虚拟环境中下载对应的使用到的库。
B站链接:
https://www.bilibili.com/video/BV1gR4y1D7qe?p=1&vd_source=d017010c9713a9f8e98390906782f3ef
来源地址:https://blog.csdn.net/qq_45929019/article/details/131641655
--结束END--
本文标题: Python Web项目部署详细教程
本文链接: https://www.lsjlt.com/news/410908.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0