阿里云 Centos7 部署 Django 项目

      1. 前期准备
        1. 阿里云服务器
        2. mysql数据库
        3. 已经本地运行成功的项目
      2. 阿里云服务器的环境配置
        1. Git #代码管理
        2. Gitlab #代码托管,要求服务器内存不低于2G,我选择放弃
        3. Mysql #连接数据库
        4. Python3 #python项目的运行环境,默认为python2
          1. Django #项目环境
          2. Uwsgi #项目运行后访问的相关的配置文件
        5. Virtualenv #创建虚拟python环境
        6. Nginx #配置项目运行转发的相关配置
      3. 环境配置的详细操作
        1. 更新软件包并安装可能用到的依赖
          1. yum update -y
          2. yum -y groupinstall "Development tools"
          3. yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
        2. 安装mysql
          1. 下载安装包
            1. wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm     
          2. 安装
            1. yum install mysql80-community-release-el7-3.noarch.rpm
            2. yum -y install mysql-community-server
          3. 启动mysql并查看运行状态
            1. systemctl start  mysqld.service
            2. systemctl status mysqld.service
        3. 安装python3
          1.  下载
            1. cd /usr/local/
            2. wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
            3. tar -zxvf Python-3.6.6.tgz
          2. 编译
            1. cd Python-3.6.6
            2. ./configure --prefix=/usr/local/python
          3. 安装
            1.  make
            2.  make install
          4. 建立软连接
            1.  ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
            2.  ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3
        4. 安装virtualenv
          1. 安装
            1.  pip3 install virtualenv
          2. 建立软连接
            1.  ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv
        5. 创建文件目录
          1.  mkdir -p /data/env
          2.  mkdir -p /data/wwwroot
        6. 创建环境
          1.  cd /data/env
          2.  virtualenv --python=/usr/bin/python3 hellofuture
        7. 启动环境
          1.  cd hellofuture/bin
          2.  source activate
        8. 安装第三方包
          1.  pip3 install django
          2.  pip3 install uwsgi
          3.  ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi
        9. 拉代码
          1.  cd /data/wwwroot
          2.  git clone  https://gitlab.com/feizisy/hellofuture.git/
        10. 配置uwsgi
          1.  cd /data/wwwroot/hellofuture
          2.  touch hellofuture.xml
          3.  vim hellofuture.xml
            1. <uwsgi>
            2.    <socket>127.0.0.1:8001</socket><!-- 内部端口,自定义 -->
            3.    <chdir>/data/wwwroot/hellofuture/</chdir><!-- 项目路径 -->
            4.    <module>hellofuture.wsgi</module>
            5.    <processes>4</processes> <!-- 进程数 -->
            6.    <daemonize>uwsgi.log</daemonize><!-- 日志文件 -->
            7. </uwsgi>
        11. 安装/配置nginx
          1.  cd home
          2.  wget http://nginx.org/download/nginx-1.13.7.tar.gz
          3.  tar -zxvf nginx-1.13.7.tar.gz
          4.  cd nginx-1.13.7
          5.  ./configure
          6.  make
          7.  make install
          8.  cd /usr/local/nginx/conf
          9.  cp nginx.conf nginx.conf.bak
          10.  vim nginx.conf
          11.  配置nginx.conf
          12.  cd ../sbin
          13.  ./nginx -t
          14.  ./nginx
        12. uwsgi配置
          1.  cd /data/wwwroot/hellofuture/
          2.  uwsgi -x hellofuture.xml
        13. 重启nginx
          1.  cd /usr/local/nginx/
          2.  ./nginx -s reload
        14. 运行项目
          1.  cd /data/wwwroot/hellofuture/
          2.  python3 manage.py runserver 0.0.0.0:8001
        15. 本地访问
          1. 公网IP:8001

猜你喜欢

转载自www.cnblogs.com/feizisy/p/11847945.html