日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

《Linux》阿里云部署django全攻略

發布時間:2023/12/31 linux 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 《Linux》阿里云部署django全攻略 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.登錄root用戶在系統下新建用戶

useradd -m zhaozhao 復制代碼

2. 為新用戶(zhaozhao)添加密碼(默認創建的用戶沒有密碼)

passwd zhaozhao 復制代碼

3.為新用戶添加sudo權限

usermod -a -G adm zhaozhao usermod -a -G sudo zhaozhao 復制代碼

4.退出root用戶,用新賬戶重新登錄Linux

exit ssh zhaozhao@主機ip地址 復制代碼

5.在用戶根目錄下新建項目目錄(如果登錄后控制鍵亂碼,輸入bash,然后回車即可!)

mkdir ~/data mkdir ~/data/{backup,code,logs,server,soft,virtual} 復制代碼

支持中文sudo locale-gen zh_CN.UTF-8

6.安裝python環境(大多數ubuntu自帶,python環境,無需安裝),本步驟可跳過

sudo apt install python3 復制代碼

##為當前用戶添加遠程認證(可選)

ssh-keygen -t rsa # 生成加密算法為 rsa的秘鑰ssh-copy-id zhaozhao@遠程ip #將公鑰拷貝到服務器端(公鑰可多次使用,私鑰相當于一卡通!)復制代碼

7.將本地項目壓縮,并通過scp, 傳輸到~/data/code

tar -zcvf fangyuanxiaozhan.tar.gz fangyuanxiaozhan 復制代碼scp fangyuanxiaozhan.tar.gz zhaozhao@遠程ip:~/data/code/fangyuanxiaozhan.tar.gz 復制代碼

8.將本地配置導出到文件,并將文件傳輸到服務端

pip freeze > requirements.txt 復制代碼scp requirements.txt zhaozhao@遠程ip:~/data/soft/requirements.txt 復制代碼

9.安裝虛擬環境軟件,并將virtualenvwrapper.sh配置到shell環境中

sudo apt install python-pip sudo pip install virtualenv sudo pip install virtualenvwrapper 復制代碼

# 添加pytho虛擬環境配置 vim ~/.bashrc export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh 復制代碼

10. 創建虛擬環境,安裝依賴包

# 創建虛擬環境 mkvirtualenv dj_py3 --python="/usr/bin/python3"# 安裝依賴包 pip install -r ~/data/soft/requirements.txt 復制代碼

出現錯誤:Python.h: No such file or directory 解決方式:sudo apt-get install python3-dev


11.安裝Nginx

1.上傳軟件包到指定目錄

scp nginx-1.10.3.tar.gz zhaozhao@遠程ip:~/data/soft/nginx-1.10.3.tar.gzscp openssl-1.0.2l.tar.gz zhaozhao@遠程ip:~/data/soft/openssl-1.0.2l.tar.gzscp zlib-1.2.11.tar.gz zhaozhao@遠程ip:~/data/soft/zlib-1.2.11.tar.gz 復制代碼

2.安裝pcre(nginx正則匹配依賴)

sudo apt-get install libpcre3 libpcre3-dev 復制代碼

3.安裝zlib

tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure make sudo make install cd .. 復制代碼

4.安裝openssl(解壓即可,目錄~/data/soft/openssl-1.0.2l)

tar -zxvf openssl-1.0.2l.tar.gz 復制代碼

5.安裝nginx

# 解壓nginx tar -zxvf nginx-1.10.3.tar.gz # 進入nginx安裝目錄 cd nginx-1.10.3# 在指定位置安裝nginx ./configure --prefix=/opt/nginx/ --with-openssl=~/data/soft/openssl-1.0.2l# 編譯 make # 安裝 sudo make install # 啟動 cd /opt/nginx/sbin sudo ./nginx # 查看 ps ajx | grep nginx 復制代碼

12.安裝mysql(一定要設置密碼,會避免很多麻煩)

sudo apt-get install mysql-server 復制代碼

13.配置uwsgi

  • 在項目目錄的同名模塊下,新建配置文件uwsgi.ini
  • 2.在配置文件中加入以下內容

    [uwsgi] # 配置nginx socket = 127.0.0.1:3309 # 配置項目目錄 chdir = /home/zhaozhao/data/code/fangyuanxiaozhan # 配置入口模塊 wsgi-file = fangyuanxiaozhan/wsgi.py # 開啟master, 將會多開一個管理進程, 管理其他服務進程 master = True # 服務器開啟的進程數量 processes = 2 # 服務器進程開啟的線程數量 threads = 4 # 以守護進程方式提供服, 輸出信息將會打印到log中 # daemonize = wsgi.log # 退出的時候清空環境變量 vacuum = true # 進程pid pidfile=uwsgi.pid 復制代碼

    3.以配置好的文件 uwsgi.ini啟動uwsgi

    uwsgi --ini uwsgi.ini 復制代碼

    ##14.配置啟動nginx的文件

  • nginx.conf配置內容
  • #user nobody; worker_processes 1;#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024; }http {include mime.types;default_type application/octet-stream;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;#location / {# root html;# index index.html index.htm;#}location / {# 將nginx所有請求轉到uwsgiinclude uwsgi_params;# uwsgi的ip與端口uwsgi_pass 127.0.0.1:3309;}location /static {alias /home/zhaozhao/data/code/fangyuanxiaozhan/static;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}復制代碼

    2.重啟nginx

    cd /opt/nginx/sbin sudo ./nginx -s stop sudo ./nginx 復制代碼

    重啟服務

    ps ajx | grep uwsgi kill -9 2844 復制代碼

    部署完成

    教程涉及到的資源我都通過百度網盤分享給大家,為了便于大家的下載,資源整合到了一張獨立的帖子里,鏈接如下: http://www.jianshu.com/p/4f28e1ae08b1

    總結

    以上是生活随笔為你收集整理的《Linux》阿里云部署django全攻略的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。