| |
| -支付宝 |
| -微信支付:官方API |
| |
| |
| -用户在我们的系统点击购买----》我们后端生成订单,订单是未支付状态,生成支付链接---》返回到前端---》打开支付链接页面----》用户扫描支付----》支付完成,支付宝商家账户收到钱----》get回调回调前端--->post回调,回调后端----》通过post回调,验签后修改订单状态----》前端通过get回调回来显示,支付成功页面,为了准确性,二次校验 |
| |
| |
| |
| -生成公钥,私钥---》软件 |
| -公钥配置在支付宝网站----》支付宝公钥 |
| -项目中使用私钥和支付宝公钥 |
| -API,sdk,第三方sdk |
| -实例化得到alipay对象,传一堆参数 |
| -使用对象的api_alipay_trade_page_pay生成支付链接 |
| -前面拼接上支付宝地址(测试地址,实际地址) do?生成的 |
| |
| |
| |
| |
| -向数据库写入数据【订单,订单详情表】 |
| -生成支付链接 |
| -validate(self, attrs): |
| |
| |
| -你们公司唯一id号如何生成的? |
| -使用uuid:uuid好像有重复的可能,我们知道有重复的可能,但是我们没有遇到过,可能因为数据量比较小 |
| -如果使用时间戳:会重复 |
| -时间戳+mysql自增(速度慢) |
| -时间戳+redis自增 |
| -雪花算法,美图leaf算法。。。 |
| |
| |
| |
| |
| -重写create 存两个表 |
| 修改个人信息:名字,年龄,地址。。。 |
| 用户表,用户详情表 |
| 重写update方法 |
| |
| |
| -点击向后端发送请求 |
| -验证是否登录:只要cookie中有token |
| -携带token【请求头】,携带请求参数[body] |
| -返回后,前端判断code,成功open支付页面 |
| |
| |
| |
| |
| -post:支付宝 |
| -get:咱们前端,二次校验 |
| |
| |
| |
| |
| |
| |
| -我们写的项目,如果没有公网ip,都是内网,只能公司内部使用,外网的人访问不到 |
| -内网穿透的工具,让外网的人能够访问到我们的项目 |
| -花生壳 |
| -做测试用 |
| |
| |
| -程序监听了 127.0.0.1,只能使用localhost,127.0.0.1 |
| -程序监听了 0.0.0.0 localhost,127.0.0.1 本机网卡地址 都可以访问 |
| -局域网内的机器可以通过你的ip[本机网卡地址],访问到你 |
| -如果监听了127.0.0.1,是不行的 |
| |
| |
| |
今日内容
0 上线前准备
| |
| -忽略掉日志文件后,空文件夹不会被git管理,做成包后会被管理,咱们需要logs文件夹 |
| |
| |
| -服务端,迁移数据库,如果执行 python manage.py migrate 使用的数据库是测试环境 |
| -服务端使用manage_pro.py,迁移到正式的数据库中 |
| |
| |
| |
| -官方建议:提交 |
| -我建议:不要提 |
| -改了后,有记录 |
| -服务端: |
| python manage.py makemigrations |
| python manage.py migrate |
| |
| |
| -假设: |
| 本地张三在user表增加了一个字段,migrations记录 |
| 本地张三在user表增加了一个字段,migrations记录 |
| 提到远端,服务端看到两个变更记录 |
| 服务端只需要执行python manage.py migrate |
| |
| -我的建议: |
| 本地张三在user表增加了一个字段,migrations记录 |
| 本地张三在user表增加了一个字段,migrations记录 |
| 不提到远端,服务端没有变更记录 |
| 服务端只需要执行 |
| python manage.py makemigrations 只生成一条 |
| python manage.py migrate |
| |
| |
| |
| -在配置文件中配置好阿里云的地址 |
| |
| |
| |
| |
| |
| -修改ajax的地址 |
| export default { |
| BASE_URL:'http://101.132.179.71:8080/api/v1/' |
| } |
| -编译 |
| npm run build |
| -项目路径下出现dist文件夹:html,css,js |
1 阿里云机器购买
| |
| |
| |
| |
| |
| |
| |
| -包年包月:公司买,一买买几年 |
| -按量付费:用一会,用完就释放:余额里必须大于100 |
| -抢占式:空跑的资源,偏移卖给你,等有人正常买,空跑的越来越少,就会把抢占式实例释放调 |
| -选择流量付费 |
| -2核4g |
| -centos 7.9系统 |
| -选公网ip |
| -自定义密码:root用户和自己写的密码 |
| -确定购买成功 |
| |
| |
| |
| |
| |
| |
| |
| 80 |
| 8080 |
| 3306 |
| 6379 |
| |
2 上线架构图
| |
| -mysql 5.7 |
| -redis 5.x |
| -python解释器 3.8 |
| -创建虚拟环境 |
| |
| |
| |
| |
| -mysql |
| -redis |
| -python3.8 |
| -nginx:代理静态资源 |
| -git:拉取代码 |
| -uwsgi:运行django |

3 安装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 |
3 云服务器安装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 |
| )kemghUlR6I6 |
| >: mysql -uroot -p |
| |
| 6)修改密码 |
| >: ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password'; |
| >: ALTER USER 'root'@'localhost' IDENTIFIED BY 'Lqz12345?'; |
4 云服务器安装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 |
5 云服务器源码安装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 |
6 安装uwsgi
| |
| |
| |
| |
| |
| 1)在真实环境下安装 |
| pip3.8 install uwsgi |
| |
| 2)建立软连接 |
| ln -s /usr/local/python38/bin/uwsgi /usr/bin/uwsgi |
7 安装虚拟环境
| |
| 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 |
8 安装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 |
| |
| |
| |
9 路飞前端部署
| |
| |
| |
| -解压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 |
10 路飞后端部署
10.1 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 |
10.2 配置数据库
| |
| 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; |
10.3 迁移数据库
| |
| |
| python manage_pro.py makemigrations |
| python manage_pro.py migrate |
| |
| |
| |
| |
| -本地的导出成sql |
| -在navicate上右键---》导出成sql |
| |
| -导入到远端中取 |
| -右键导入即可 |
10.4 使用uwsgi启动djagno
| |
| 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 |
| |
| |
| 补充:停掉uwsgi |
| pkill -8 uwsgi |
| |
| |
11 路飞后台样式处理
| |
| |
| |
| 1)创建线上luffy项目虚拟环境 |
| >: mkvirtualenv luffy |
| >: workon luffy |
| |
| 2)安装所需环境,在packages.txt所在目录下安装执行requirements.txt文件 |
| >: pip install uwsgi |
| >: pip install -r ./requirements.txt |
| |
| yum install mysql-devel |
| yum install python-devel |
| rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 |
| pip install mysqlclient |
| |
12.2 配置luffy数据库
| 1)管理员连接数据库 |
| >: mysql -uroot -p |
| |
| 2)创建数据库 |
| >: create database luffy default charset=utf8; |
| |
| 3)设置权限账号密码:账号密码要与项目中配置的一致 |
| >: grant all privileges on luffy.* to 'luffy'@'%' identified by 'Luffy123?'; |
| >: grant all privileges on luffy.* to 'luffy'@'localhost' identified by 'Luffy123?'; |
| >: flush privileges; |
| |
| 4)退出mysql |
| >: quit; |
12.3 迁移数据库
| |
| 1)数据库迁移 |
| python manage_prod.py makemigrations |
| python manage_prod.py migrate |
| |
| 2)把本地数据,导入到生产库 |
| |
| |
| |
12.4 使用uwsgi启动django
| |
| >: 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> |
| |
| |
| |
| pip install 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; |
| |
| } |
| } |
| |
| 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 luffyapi.wsgi; |
| uwsgi_param UWSGI_CHDIR /home/project/luffyapi/; |
| } |
| } |
| } |
| |
| |
| nginx -s reload |
| |
13 路飞后台管理样式处理
| 1)编辑线上配置文件 |
| >: vim /home/project/luffyapi/luffyapi/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 |
| |
| 5)完成静态文件迁移 |
| >: python 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; |
| } |
| } |
| 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 luffyapi.wsgi; |
| uwsgi_param UWSGI_CHDIR /home/luffy_api/luffy_api/; |
| } |
| location /static { |
| alias /home/luffy_api/luffy_api/static; |
| } |
| } |
| |
| } |
| |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)