一、前期准备
1. 云服务器购买
阿里云服务器:https: // www. aliyun. com/ ?spm= 5176.13735996 . J_3207526240. 1 . 555e3c60eweQIY
腾讯云服务器:https: // cloud. tencent. com/
2. 系统环境
centos7. 9
3. 服务器端口组开放
开放端口:80 、3306 、8080 、6379
4. 远程连接
xshell\Finallshell
5. luffy项目后端配置
logs文件夹做成包
6. 新建一个manage_pro. py
服务端迁移数据库,如果执行 python manage. py migrate,使用的数据库是测试环境
服务端使用python manage_pro. py migrate,迁移到正式的数据库中
7. 配置文件中后台和前台地址,修改成上线服务器的地址
HOST_URL = 'http://1.117.93.128:8080'
LUFFY_URL = 'http://1.117.93.128:81'
NOTIFY_URL = HOST_URL + "/api/v1/order/success/"
RETURN_URL = LUFFY_URL + "/pay/success"
8. 提交luffy项目后端到远程仓库
git add .
git commit - m 'luffy项目上线V1'
git push origin master
9. luffy项目前端配置
settings. js中修改ajax地址:
export default {
BASE_URL: 'http://你的服务器地址:8080/api/v1/'
}
10. 项目编译打包
npm run build
在项目根路径下出现dist文件夹,把它压缩成zip 包,上传到你的云服务器上
二、上线流程
mysql 5.7
redis 5 . x
python解释器 3.8
创建虚拟环境
vue
mysql
redis
python3. 8
nginx:代理静态资源
git:拉取代码
uwsgi:运行django
三、安装git
yum install git - y
yum - y groupinstall "Development tools"
yum install openssl- devel bzip2- devel expat- devel gdbm- devel readline- devel sqlite- devel psmisc libffi- devel - y
四、安装mysql
1 )前往用户根目录
cd ~
2 )下载mysql57
> : wget http: // dev. mysql. com/ get/ mysql57- community- release- el7- 10 . noarch. rpm
3 )安装mysql57
> : yum - y install mysql57- community- release- el7- 10 . noarch. rpm
> : yum install mysql- community- server - - nogpgcheck
4 )启动mysql57并查看启动状态
> : systemctl start mysqld. service
> : systemctl status mysqld. service
5 )查看默认密码并登录
> : grep "password" / var/ log/ mysqld. log
Tl- 5uKq& Z+ tK
> : mysql - uroot - p
6 )修改密码
> : ALTER USER 'root' @'localhost' IDENTIFIED BY 'new password' ;
> : ALTER USER 'root' @'localhost' IDENTIFIED BY 'Lqz12345?' ;
五、安装redis
1 )前往用户根目录
> : cd ~
2 )下载redis- 5.0 .5 (源码包)
> : wget http: // download. redis. io/ releases/ redis- 5.0 .5 . tar. gz
3 )解压安装包
> : tar - xf redis- 5.0 .5 . tar. gz
4 )进入目标文件
> : cd redis- 5.0 .5
5 )编译环境(gcc编译- - - 》可执行文件- - 》src- - - 》可执行文件)
> : make
6 )复制环境到指定路径完成安装
> : cp - r / root/ redis- 5.0 .5 / usr/ local/ redis
7 )配置redis可以后台启动:修改下方内容
> : vim / usr/ local/ redis/ redis. conf
daemonize yes
8 )完成配置修改
> : esc
> : : wq
9 )建立软连接
> : ln - s / usr/ local/ redis/ src/ redis- server / usr/ bin / redis- server
> : ln - s / usr/ local/ redis/ src/ redis- cli / usr/ bin / redis- cli
10 )后台运行redis
> : cd / usr/ local/ redis
> : redis- server . / redis. conf &
ctrl + c
11 )测试redis环境
> : redis- cli
ctrl + c
12 )关闭redis服务
> : pkill - f redis - 9
六、安装python
yum install openssl- devel bzip2- devel expat- devel gdbm- devel readline- devel sqlite- devel psmisc libffi- devel zlib* libffi- devel - y
> : cd ~
wget https: // registry. npmmirror. com/ - / binary/ python/ 3.8 .6 / Python- 3.8 .6 . tgz
tar - xf Python- 3.8 .6 . tgz
cd Python- 3.8 .6
> : . / configure - - prefix= / usr/ local/ python38
yum install openssl- devel bzip2- devel expat- devel gdbm- devel readline- devel sqlite- devel psmisc libffi- devel zlib* libffi- devel - y
make & & make install
ln - s / usr/ local/ python38/ bin / python3 / usr/ bin / python3. 8
ln - s / usr/ local/ python38/ bin / pip3 / usr/ bin / pip3. 8
python 2 . x pip
python3 3.6 pip3
python3. 8 3.8 pip3. 8
> : rm - rf Python- 3.8 .8
> : rm - rf Python- 3.8 .8 . tar. xz
七、安装uwsgi
1 )在真实环境下安装
pip3. 8 install uwsgi
2 )建立软连接
ln - s / usr/ local/ python38/ bin / uwsgi / usr/ bin / uwsgi
八、安装虚拟环境
1 )安装依赖
> : pip3. 8 install virtualenv
> : pip3. 8 install - U virtualenvwrapper - i https: // pypi. douban. com/ simple/
> : pip3. 8 install virtualenvwrapper
2 )建立虚拟环境软连接
> : ln - s / usr/ local/ python38/ bin / virtualenv / usr/ bin / virtualenv
3 )配置虚拟环境:填入下方内容
> : vim ~ / . bash_profile
VIRTUALENVWRAPPER_PYTHON= / usr/ bin / python3. 8
source / usr/ local/ python38/ bin / virtualenvwrapper. sh
4 )退出编辑状态
> : esc
5 )保存修改并退出
> : : wq
6 )更新配置文件内容
> : source ~ / . bash_profile
7 )虚拟环境默认根目录:~ / . virtualenvs
8 ) mkvirtualenv - p python3. 8 luffy
九、安装nginx
1 )前往用户根目录
> : cd ~
2 )下载nginx1. 13.7
> : wget http: // nginx. org/ download/ nginx- 1.13 .7 . tar. gz
3 )解压安装包
> : tar - xf nginx- 1.13 .7 . tar. gz
4 )进入目标文件
> : cd nginx- 1.13 .7
5 )配置安装路径:/ usr/ local/ nginx
> : . / configure - - prefix= / usr/ local/ nginx
6 )编译并安装
> : make & & make install
7 )建立软连接:终端命令 nginx
> : ln - s / usr/ local/ nginx/ sbin/ nginx / usr/ bin / nginx
8 )删除安装包与文件:
> : cd ~
> : rm - rf nginx- 1.13 .7
> : rm - rf nginx- 1.13 .7 . tar. xz
9 )测试Nginx环境,服务器运行nginx,本地访问服务器ip
> :
> : 服务器绑定的域名 或 ip: 80
十、luffy前端部署
解压zip 软件:yum install - y unzip
上传下载的软件:yum install lrzsz - y
npm run build
unzip dist. zip
mv ~ / dist / home/ html
> : cd / usr/ local/ nginx/ conf
> : mv nginx. conf nginx. conf. bak
> : vim nginx. conf
events {
worker_connections 1024 ;
}
http {
include mime. types;
default_type application/ octet- stream;
sendfile on;
server {
listen 80 ;
server_name 127.0 .0 .1 ;
charset utf- 8 ;
location / {
root / home/ html;
index index. html;
}
}
}
nginx - s reload
nginx - s stop
nginx
十一、luffy后端部署
git拉取最新的代码
pip freeze > requirements. txt
git clone https: // gitee. com/ liuqingzheng/ luffy_api. git
workon luffy
pip install - r requirements. txt
yum install mysql- devel - y
yum install python- devel - y
rpm - - import https: // repo. mysql. com/ RPM- GPG- KEY- mysql- 2022
pip install mysqlclient
创建数据库
1 )管理员连接数据库
> : mysql - uroot - p
2 )创建数据库
> : create database luffy default charset= utf8;
3 )设置权限账号密码:账号密码要与项目中配置的一致
> : grant all privileges on luffy. * to 'luffy_api' @'%' identified by 'Luffy123?' ;
> : grant all privileges on luffy. * to 'luffy_api' @'localhost' identified by 'Luffy123?' ;
> : flush privileges;
4 )退出mysql
> : quit;
迁移数据库
python manage_pro. py makemigrations
python manage_pro. py migrate
- 本地的导出成sql
- 在navicate上右键- - - 》导出成sql
- 导入到远端中取
- 右键导入即可
uwsgi启动项目
python manage_pro. py runserver 0.0 .0 .0 : 8080
外部机器浏览器里输入:http: // 101.132 .179 .71 : 8080 / api/ v1/ home/ banner/ 就能访问到
> : vim . / luffyapi. xml
< uwsgi>
< socket> 127.0 .0 .1 : 8888 < / socket>
< chdir> / home/ luffy_api/ < / chdir>
< module> luffy_api. wsgi< / module>
< processes> 4 < / processes>
< daemonize> uwsgi. log< / daemonize>
< / uwsgi>
uwsgi - x . / luffyapi. xml
ps aux | grep uwsgi
vim / usr/ local/ nginx/ conf/ nginx. conf
events {
worker_connections 1024 ;
}
http {
include mime. types;
default_type application/ octet- stream;
sendfile on;
server {
listen 80 ;
server_name 127.0 .0 .1 ;
charset utf- 8 ;
location / {
root / home/ html;
index index. html;
try_files $uri $uri/ / index. html;
}
}
server {
listen 8080 ;
server_name 127.0 .0 .1 ;
charset utf- 8 ;
location / {
include uwsgi_params;
uwsgi_pass 127.0 .0 .1 : 8888 ;
uwsgi_param UWSGI_SCRIPT luffy_api. wsgi;
uwsgi_param UWSGI_CHDIR / home/ luffy_api/ ;
}
}
}
nginx - s reload
十二、luffy后台样式处理
1 )编辑线上配置文件
> : vim / home/ luffyapi/ luffy_api/ settings/ pro. py
2 )修改static配置,新增STATIC_ROOT、STATICFILES_DIRS
STATIC_URL = '/static/'
STATIC_ROOT = '/home/luffy_api/luffy_api/static'
STATICFILES_DIRS = ( os. path. join( BASE_DIR, "../static" ) , )
3 )退出编辑
> : esc
> : : wq
4 )项目目录下没有 static 文件夹需要新建
> : mkdir / home/ luffy_api/ static
> : mkdir / home/ luffy_api/ luffy_api/ static
5 )完成静态文件迁移
> : python / home/ luffy_api/ manage_pro. py collectstatic
6 )1 )修改nginx配置
> : vim / usr/ local/ nginx/ conf/ nginx. conf
events {
worker_connections 1024 ;
}
http {
include mime. types;
default_type application/ octet- stream;
sendfile on;
server {
listen 80 ;
server_name 127.0 .0 .1 ;
charset utf- 8 ;
location / {
root / home/ html;
index index. html;
try_files $uri $uri/ / index. html;
}
}
server {
listen 8080 ;
server_name 127.0 .0 .1 ;
charset utf- 8 ;
location / {
include uwsgi_params;
uwsgi_pass 127.0 .0 .1 : 8888 ;
uwsgi_param UWSGI_SCRIPT luffy_api. wsgi;
uwsgi_param UWSGI_CHDIR / home/ luffy_api/ ;
}
location / static {
alias / home/ luffy_api/ static;
}
}
}
十三、上线测试
http: // 你的服务器ip+ 端口号
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)