1安装git
yum install git - y
mkdir / home/ project
cd / home/ project
git clone gitee仓库地址
或
git clone github仓库地址
2 购买云服务器
3 云服务器安装数据库mysql
yum - y groupinstall "Development tools"
yum install openssl- devel bzip2- devel expat- devel gdbm- devel readline- devel sqlite- devel psmisc libffi- devel
( 1 ) 前往用户根目录
cd ~
( 2 ) 下载mysql 5.7
wget http: // dev. mysql. com/ get/ mysql57- community- release- el7- 10 . noarch. rpm
( 3 ) 安装mysql 5.7
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
xxyy+ 1sdfjn+ ( 默认随机密码)
mysql - uroot - p
( 6 ) 修改密码
ALTER USER 'root' @'localhost' IDENTIFIED BY 'new password' ;
ALTER USER 'root' @'localhost' IDENTIFIED BY 'qazwsx@159' ;
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服务
shutdown
pkill - f redis - 9
5云服务器安装python3.8(源码安装)
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. 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
python3. 8 - m pip install - - upgrade pip
python3. 8 - m pip install - - upgrade setuptools
pip3. 8 install pbr
pip check用来验证已安装的包是否有兼容的依赖性问题
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 proj_name
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
( 10 ) 测试Nginx环境,服务器运行nginx,本地访问服务器ip
nginx
nginx - s stop
( 11 ) 服务器绑定的域名
netstat - nlp | grep 80
9 前端项目部署(vue为例)
npm run build
或者使用命令
rz
unzip dist. zip
mv ~ / dist / home/ html
设置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;
}
}
}
ps aux | grep nginx
nginx - s reload
nginx - s stop
nginx
10 项目后端部署
os. environ. setdefault( 'DJANGO_SETTINGS_MODULE' , 'backend_name.settings.pro' )
pip freeze > requirements. txt
mkvirtualenv backend_proj
workon backend_proj
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
10.2 配置数据库
mysql - uroot - p
create database backend_proj default charset= utf8;
grant all privileges on backend_proj. * to 'backend_proj' @'%' identified by 'qazwsx@159?' ;
grant all privileges on backend_proj. * to 'backend_proj' @'localhost' identified by 'qazwsx@159?' ;
flush privileges;
quit;
10.3 迁移数据库
1 )数据库迁移
python manage_prod. py makemigrations
python manage_prod. py migrate
2 )把本地数据,导入到生产库
10.4 使用uwsgi启动django
vim . / backend_name. xml
< uwsgi>
< socket> 127.0 .0 .1 : 9999 < / socket>
< chdir> / home/ project/ backend_name/ < / chdir>
< module> backend_name. wsgi< / module>
< processes> 4 < / processes>
< daemonize> uwsgi. log< / daemonize>
< / uwsgi>
uwsgi - x . / backend_name. 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 : 9999 ;
uwsgi_param UWSGI_SCRIPT backend_name. wsgi;
uwsgi_param UWSGI_CHDIR / home/ project/ backend_name/ ;
}
}
}
nginx - s reload
11 项目后台管理样式处理
( 1 ) 编辑线上配置文件
vim / home/ project/ backend_name/ backend_name/ settings/ pro. py
( 2 ) 修改static配置,新增STATIC_ROOT、STATICFILES_DIRS
STATIC_URL = '/static/'
STATIC_ROOT = '/home/project/backend_name/static'
STATICFILES_DIRS = ( os. path. join( BASE_DIR, "../static" ) , )
( 3 ) 退出编辑
esc
: wq
( 4 ) 项目目录下没有static文件夹需要新建
mkdir / home/ project/ backend_name/ static
( 5 ) 完成静态文件迁移
python / home/ project/ backend_name/ manage_pro. py collectstatic
( 6 ) 修改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 : 9999 ;
uwsgi_param UWSGI_SCRIPT backend_name. wsgi;
uwsgi_param UWSGI_CHDIR / home/ project/ backend_name/ ;
}
location / static {
alias / home/ project/ backend_name/ static;
}
}
}