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