阿里云 Centos7 部署 Django 项目
生活随笔
收集整理的這篇文章主要介紹了
阿里云 Centos7 部署 Django 项目
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
- 前期準備
- 阿里云服務器
- mysql數據庫
- 已經本地運行成功的項目
- 阿里云服務器的環境配置
- Git #代碼管理
- Gitlab #代碼托管,要求服務器內存不低于2G,我選擇放棄
- Mysql #連接數據庫
- Python3 #python項目的運行環境,默認為python2
- Django #項目環境
- Uwsgi #項目運行后訪問的相關的配置文件
- Virtualenv #創建虛擬python環境
- Nginx #配置項目運行轉發的相關配置
- 環境配置的詳細操作
- 更新軟件包并安裝可能用到的依賴
- yum update -y
- yum -y groupinstall "Development tools"
- yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
- 安裝mysql
- 下載安裝包
- wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
- 安裝
- yum install mysql80-community-release-el7-3.noarch.rpm
- yum -y install mysql-community-server
- 啟動mysql并查看運行狀態
- systemctl start mysqld.service
- systemctl status mysqld.service
- 安裝python3
- 下載
- cd /usr/local/
- wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
- tar -zxvf Python-3.6.6.tgz
- 編譯
- cd Python-3.6.6
- ./configure --prefix=/usr/local/python
- 安裝
- make
- make install
- 建立軟連接
- ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
- ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3
- 安裝virtualenv
- 安裝
- pip3 install virtualenv
- 建立軟連接
- ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv
- 創建文件目錄
- mkdir -p /data/env
- mkdir -p /data/wwwroot
- 創建環境
- cd /data/env
- virtualenv --python=/usr/bin/python3 hellofuture
- 啟動環境
- cd hellofuture/bin
- source activate
- 安裝第三方包
- pip3 install django
- pip3 install uwsgi
- ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi
- 拉代碼
- cd /data/wwwroot
- git clone https://gitlab.com/feizisy/hellofuture.git/
- 配置uwsgi
- cd /data/wwwroot/hellofuture
- touch hellofuture.xml
- vim hellofuture.xml
- <uwsgi>
- <socket>127.0.0.1:8001</socket><!-- 內部端口,自定義 -->
- <chdir>/data/wwwroot/hellofuture/</chdir><!-- 項目路徑 -->
- <module>hellofuture.wsgi</module>
- <processes>4</processes> <!-- 進程數 -->
- <daemonize>uwsgi.log</daemonize><!-- 日志文件 -->
- </uwsgi>
- 安裝/配置nginx
- cd home
- wget http://nginx.org/download/nginx-1.13.7.tar.gz
- tar -zxvf nginx-1.13.7.tar.gz
- cd nginx-1.13.7
- ./configure
- make
- make install
- cd /usr/local/nginx/conf
- cp nginx.conf nginx.conf.bak
- vim nginx.conf
- 配置nginx.conf
- cd ../sbin
- ./nginx -t
- ./nginx
- uwsgi配置
- cd /data/wwwroot/hellofuture/
- uwsgi -x hellofuture.xml
- 重啟nginx
- cd /usr/local/nginx/
- ./nginx -s reload
- 運行項目
- cd /data/wwwroot/hellofuture/
- python3 manage.py runserver 0.0.0.0:8001
- 本地訪問
- 公網IP:8001
- 本文參考:https://blog.csdn.net/u012516524/article/details/82154053
總結
以上是生活随笔為你收集整理的阿里云 Centos7 部署 Django 项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: xshell6,xftp下载
- 下一篇: 四十一、python面向对象二