阿里云服务器:https://www.aliyun.com/product/ecs
yum install git -y
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
# mysql -uroot -p
6)修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
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)编译环境
# 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 &
查看进程是否在运行:ps aux | grep redis
ctrl + c
11)测试redis环境
# redis-cli
12)关闭redis服务
客户端连进去,敲 shutdown
pkill -f redis -9
所有linxu和mac,都自带python2,阿里云的centos默认装了python3.6。
源码安装python,依赖一些第三方zlib* libffi-devel
# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel zlib* libffi-devel -y
1 前往用户根目录
# cd ~
2 下载 或 上传 Python3.8.6 服务器终端
wget https://registry.npmmirror.com/-/binary/python/3.8.6/Python-3.8.6.tgz
3 解压安装包
# tar -xf Python-3.8.6.tgz
4 进入目标文件
# cd Python-3.8.6
5 配置安装路径:/usr/local/python3
把python3.8.6 编译安装到/usr/local/python38路径下
# ./configure --prefix=/usr/local/python38
6 编译并安装,如果报错,说明缺依赖
# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel zlib* libffi-devel -y
# make && make install
#7 建立软连接:/usr/local/python38路径不在环境变量,终端命令 python3,pip3
ln -s /usr/local/python38/bin/python3 /usr/bin/python3.8
ln -s /usr/local/python38/bin/pip3 /usr/bin/pip3.8
# 机器上有多个python和pip命令,对应关系如下
python 2.x pip
python3 3.6 pip3
python3.8 3.8 pip3.8
#8 删除安装包与文件:
>: rm -rf Python-3.8.8
>: rm -rf Python-3.8.8.tar.xz
使用uwsgi运行django,不再使用测试阶段的wsgiref来运行django了
uwsgi是符合wsgi协议的web服务器,使用c写的性能高,上线要使用uwsgi
安装步骤
1)在真实环境下安装
# pip3.8 install uwsgi
安装到了python38的安装路径的bin路径下了
2)建立软连接
# ln -s /usr/local/python38/bin/uwsgi /usr/bin/uwsgi
1)安装依赖
# pip3.8 install virtualenv
# python3.8 -m pip install --upgrade pip
# python3.8 -m pip install --upgrade setuptools
# pip3.8 install pbr
# pip3.8 install virtualenvwrapper
2)建立虚拟环境软连接
# ln -s /usr/local/python38/bin/virtualenv /usr/bin/virtualenv
3)配置虚拟环境:填入下方内容
~/ 表示用户家路径:root用户,就是在/root/.bash_profile
# 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 venv
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
# 启动 :nginx
# 停止: nginx -s stop
>: 服务器绑定的域名 或 ip:80
# netstat -nlp | grep 80
# ps aux | grep 进程名
修改前端向后端发ajax请求的地址:项目的地址。
编译vue项目成html,css,js。
1) npm run bulid
2) 项目根路径下生成dist文件夹(编译过后的文件)
3) 使用SFTP连接服务器,将dict压缩包拖拽到服务端
# 或者yum install -y unzip
# yum install lrzsz -y
直接把dist.zip 拖到 云服务器上去
或者在云服务器敲 rz 选择上传
4)解压文件
# unzip dist.zip
5)移动并重命名
mv ~/dist /home/html
6)去向Nginx配置目录,备份配置,完全更新配置:填入下方内容
/usr/local/nginx/conf/nginx.conf 是nginx的配置文件
制定nginx启动监听哪个端口
做请求转发,做负载均衡
做静态文件代理
# 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;
}
}
}
7)重启nginx
# nginx -s reload
或者
# nginx -s stop
# nginx
1)确认好wsgi.py 中得配置文件是不是用的prod.py
2)导出项目所有的依赖,当前虚拟环境的依赖,就是当前项目的依赖
pip freeze > requirements.txt
3)在/home/路径下拉取项目
git clone
4)切换到venv虚拟环境
workon venv
5)安装依赖
pip install -r requirements.txt
如果安装mysqlclient报错,需要安装下边依赖
yum install mysql-devel -y
yum install python-devel -y
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
创建数据库用户,和数据库,再迁移表
1)管理员连接数据库
mysql -uroot -p
2)创建数据库
create database db_name default charset=utf8;
3)设置权限账号密码:账号密码要与项目中配置的一致
grant all privileges on luffy.* to '用户名'@'%' identified by '密码';
grant all privileges on luffy.* to '用户名'@'localhost' identified by '密码';
flush privileges;
4)退出mysql
quit;
1)cd到项目目录下
2)执行数据库迁移命令
python manage_prod.py makemigrations
python manage_prod.py migrate
1)使用uwsgi跑之前先执行
python manage_pro.py runserver 0.0.0.0:8080
2)项目路径下,进行uwsgi服务配置
# uwsgi的配置文件
vim ./api.xml
127.0.0.1:8888
/home/project_api/
project.wsgi
4
uwsgi.log
3)启动uwsgi
uwsgi -x ./api.xml
4)查看uwsgi进程
ps aux |grep uwsgi
5)配置nginx,把8080的动态请求转发给8888端口
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; # 改为自己的域名,没域名修改为127.0.0.1:80
charset utf-8;
location / {
root /home/html; # html访问路径
index index.html; # html文件名称
try_files $uri $uri/ /index.html; # 解决单页面应用刷新404问题
}
}
# 新增的server
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 prject.wsgi;
uwsgi_param UWSGI_CHDIR /home/prject_api/;
}
}
}
6)重启nginx
nginx -s reload
uwsgi 只转发动态请求,静态资源它不管
1)编辑线上配置文件
vim /home/project_api/project/settings/prod.py
2)修改static配置,新增STATIC_ROOT、STATICFILES_DIRS
STATIC_URL = '/static/'
STATIC_ROOT = '/home/project_api/project/static'
STATICFILES_DIRS = (os.path.join(BASE_DIR, "../static"),)
3)退出保存
4)完成静态文件迁移
python /home/project_api/project/manage_prod.py collectstatic
5)修改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; # 改为自己的域名,没域名修改为127.0.0.1:80
charset utf-8;
location / {
root /home/html; # html访问路径
index index.html; # html文件名称
try_files $uri $uri/ /index.html; # 解决单页面应用刷新404问题
}
}
# 新增的server
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 project.wsgi;
uwsgi_param UWSGI_CHDIR /home/project_api/;
}
location /static {
alias /home/project_api/project/static;
}
}
}