赞
踩
本质三件事:
在阿里云、腾讯云或者其他平台购买一台服务器。
本文以 阿里云 + 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 .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # 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 logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ cover/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder .pybuilder/ target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_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 stuff celerybeat-schedule celerybeat.pid # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ # pytype static type analyzer .pytype/ # Cython debug symbols cython_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 init
git 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 www
cd /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 -y
cd /data/
wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
解压—编译—安装:
tar -xvf Python-3.9.5.tgz
cd Python-3.9.5.tgz
./configure
make all
make install
Python解释器配置豆瓣源:
pip3.9 config set global.index-url https://pypi.douban.com/simple/
pip3.9 install virtualenv
mkdir /envs
cd /envs/
virtualenv /envs/test --python=python3.9
source /envs/test/bin/activate
pip install flask
激活虚拟环境,在虚拟环境中安装
source /envs/test/bin/activate
pip install uwsgi
cd /data/www/test/
vim test_uwsgi.ini
编写uwsgi的配置文件:
[uwsgi]
socket = 127.0.0.1:8001
chdir = /data/www/test/
wsgi-file = app.py
callable = app
processes = 1
virtualenv = /envs/test/
uwsgi --ini test _uwsgi.ini
yum install nginx -y
vim /etc/nginx/nginx.conf
systemctl enable nginx
systemctl start nginx
如果无法启动80端口被占用,输入以下命令查看并关闭相关进程:
lsof -i:80 80端口被占用的问题查看
如上:关闭httpd即可
再次启动nginx即可成功:systemctl start nginx
nginx启动后,依次执行以下语句即可拉起test项目
source /envs/test/bin/activate
cd /data/www/test/
uwsgi --ini test_uwsgi.ini >nohup.out
浏览器中输入你服务器的公网ip,即可看到你的项目
每个项目所依赖的库不同,需要你在虚拟环境中下载对应的使用到的库。
B站链接:
https://www.bilibili.com/video/BV1gR4y1D7qe?p=1&vd_source=d017010c9713a9f8e98390906782f3ef
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。