yum update -y
yum -y install gcc gcc-c++
yum -y groupinstall “Development tools”
yum -y install zlib zlib-devel openssl openssl-devel ncurses-devel sqlite sqlite-devel bzip2-deve readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum -y install nginx
cd /opt/
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz(下载地址可能会失效)
tar -xvJf Python-3.6.2.tar.xz
cd Python-3.6.2
./configure -prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
pip3 install --upgrade pip
cd /data
mkdir website
cd website
python3 -m venv abnormalenv
cd abnormalenv
mkdir src
cd src
source ../bin/activate
pip3 install --upgrade pip
上传django项目到服务器(项目中包括sql文件,requirements依赖包文件,sll密钥文件)
cd django项目
pip3 install django==2.1.8(django版本不宜过高,否则要对对sqlite3做更新)
yum install -y mysql-devel gcc gcc-devel python36-devel(mysqlclient的依赖包,注意python-devel的版本要和python一致)
pip3 install -r requirements.txt(不要包含django)
pip3 install uwsgi
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi
ln -s /usr/local/python3/bin/django-admin /usr/bin/django-admin
systemctl start mariadb
mysqladmin -uroot -p123456 password MyNewPass4!
mysql -uroot -pMyNewPass4!
create database abnormalclub_db;
quit
mysql -uroot -pMyNewPass4! abnormalclub_db < abnormalclub_db.sql
创建uwsgi启动文件:
vim uwsgi_abnormal.ini
写入:-------------------------------------------------------------------------------------------------------------------
[uwsgi]
socket = 0.0.0.0:9001
chdir = /data/website/finder/back/
wsgi-file = back/wsgi.py
process = 4
#buffer-size = 32768 #设置用于uwsgi包解析的内部缓存区大小为64k。默认是4k。
daemonize = /var/log/uwsgi/finderuwsgi.log
# 使进程在后台运行,并将日志打到指定的日志文件或者udp服务器
log-maxsize = 5000000 #设置最大日志文件大小
vacuum = true #当服务器退出的时候自动删除unix socket文件和pid文件。
listen = 30 #设置socket的监听队列大小(默认:100)
#reload-mercy = 8
#设置在平滑的重启(直到接收到的请求处理完才重启)一个工作子进程中,等待这个工作结束的最长秒数。这个配置会使在平滑地重启工作子进程中,如果工作进程结束时间超过了8秒就会被强
行结束(忽略之前已经接收到的请求而直接结束)
#max-requests = 5000
#为每个工作进程设置请求数的上限。当一个工作进程处理的请求数达到这个值,那么该工作进程就会被回收重用(重启)。你可以使用这个选项来默默地对抗内存泄漏
#harakiri = 60
#一个请求花费的时间超过了这个harakiri超时时间,那么这个请求都会被丢弃,并且当前处理这个请求的工作进程会被回收再利用(即重启)
disable-logging = true #不记录请求信息的日志。只记录错误以及uWSGI内部消息到日志中。
pidfile = /data/website/finder/back/uwsgi.pid
#指定pid文件
退出:-------------------------------------------------------------------------------------------------------------------
:wq
创建nginx启动文件:
vim nginx_abnormal.conf
写入:----------第一种(http)---------------------------------------------------------------------------------------------------------
events{}
http{
server{
listen 80;
server_name 106.54.78.112;
charset utf-8;
client_max_body_size 75M;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass 127.0.0.1:9000;
uwsgi_read_timeout 30;
}
location /static/ {
alias /data/website/abnormalenv/src/abnormalclub_backend/static;
}
location /media/ {
alias /data/website/abnormalenv/src/abnormalclub_backend/media;
}
}
}
退出:-------------------------------------------------------------------------------------------------------------------
:wq
写入:----------第二种(https)---------------------------------------------------------------------------------------------------------
# worker_rlmit_nofile 65500;
events{}
http{
server{
# 监听http默认端口80,重定向到https默认端口443上
listen 80;
server_name www.zoesama.club;
rewrite ^/(.*) https://$server_name/$1 permanent;
}
# superhero-dev
server{
# https默认端口443
listen 443 ssl;
server_name www.zoesama.club;
# ssl证书配置
ssl_certificate /root/ssl/1_zoesama.club_bundle.crt;
ssl_certificate_key /root/ssl/2_zoesama.club.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# nginx基本配置
charset UTF-8;
access_log off; # 关闭访问日志
error_log /var/log/nginx/finder_err.log error; # 错误日志输出位置,错误日志不能关闭,只能输出到linux黑洞,请这样写error_log /dev/null crit;
client_max_body_size 75M;
# 项目后端根目录配置
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass 127.0.0.1:8001; # uwsgi端口配置,(django项目<->uwsgi本地8001端口<->nginx外网www.zoesama.club)
uwsgi_read_timeout 2;
}
# 项目静态资源根目录配置(主要是django-admind的css,通过文件settings.py配置,命令python3 manage.py collectstatic收集)
location /static {
alias /webroot/superhero-dev/src/superhero_dev/static;
}
# 项目媒体资源根目录配置(图片和视频资源)
location /media {
alias /webroot/superhero-dev/src/superhero_dev/media;
}
# 项目h5前端根目录配置
location /h5 {
alias /webroot/superhero-dev/src/h5;
try_files $uri $uri/ /h5/index.html; # 页面刷新时在uri文件或者uri目录下重新搜索该页面,uri就是alias配置的路径
}
}
# 解决:h5部署到Nginx后,静态文件加载不正常(MIME TYPE问题)
include /etc/nginx/mime.types;
default_type application/octet-stream;
}
退出:-------------------------------------------------------------------------------------------------------------------
:wq
启动uwsgi和nginx:
uwsgi --ini uwsgi_abnormal.ini & nginx -c /data/website/abnormalenv/src/abnormalclub_backend/nginx_abnormal.conf