阿里云 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

原文地址:https://www.cnblogs.com/feizisy/p/11847945.html

时间: 2024-07-29 07:38:43

阿里云 Centos7 部署 Django 项目的相关文章

向云服务器部署django项目

1. ftp服务器的搭建 为了把项目文件上传至云服务器,我们需要在云服务器端设置ftp服务,进行文件传输. (1)云服务器端 a. 首先,我们需要安装vsftpd,输入命令 sudo apt-get install vsftpd -y b. 安装成功后,我们需要建立一个ftp专用账户. 检查一下nologin文件夹的位置,一般在/usr/sbin/nologin或者/sbin/nologin下.若没有这个文件夹,就在/sbin下新建一个. 进入nologin之后,输入命令: useradd -d

阿里云ECSserver部署django

highlight=uwsgi%20django">參考 server安装的是Centos 系统. uwsgi是使用pip安装的. nginx是使用yum install nginx安装. python 2.7, mysql 5.5使用 yum安装. 它们之间的逻辑关系例如以下: the web client <-> the web server <-> the socket <-> uwsgi <-> Django uswgi负责从Djan

Centos7部署Django项目

uwsgi Python环境搭建[略] uwsgi模块的安装: pip3 install uwsgi uwsgi配置文件编写: uwsgi配置文件格式可以是xml也可以是ini文件,这里使用ini文件 在django项目的根目录新建一个uwsgi.ini文件,写入以下内容 [uwsgi] http = :8000 # 绑定端口 chdir = /home/trunk/ # 项目主目录 module = SpiderServer.wsgi #项目主目录下的SpiderServer.wsgi.py文

阿里云 centos 部署 Django 可能遇到的问题

问题一:版本限制   File "/Users/icourt/Desktop/hf/venv/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 36, in <module>     raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version_

教你在裸机centos7系统中部署django项目

概要 本文用一台安装了centos7.5系统的裸奔的Linux机器(当然是虚拟机)详细讲解部署django项目的过程. 配置yum源 至于什么是yum源大家请自行百度,本人想用阿里云的yum源,因此需要在裸机上配置一下: 进入yum源的目录 cd /etc/yum.repos.d/ 查看yum源文件 ls -l 配置阿里云yum源 1.好习惯,备份yum源 mkdir repo_bak mv *.repo repo_bak/ 2.下载阿里云repo文件 wget http://mirrors.a

Centos7部署tornado项目

今天帮一个学生解决tornado的部署问题,在此记录了这其中的过程,其中的tornado项目为随手写的示例. 开发环境: 本地开发环境:Win10 + Python3.5.4 + PyCharm 线上环境:Centos7.3 + Python3.5.4 第一步:本地项目编写.Python3.x适用,并且已经安装并配置好了环境变量 1. 首先创建名为torn_test的虚拟环境 virtualenv --python=python.exe --no-site-packages torn_test

Docker 部署Django项目

使用docker部署django项目也很简单,挺不错,分享下 环境 默认你已安装好docker环境 django项目大概结构 (p3s) [[email protected]]# tree opsweb opsweb ├── apps ├── logs ├── manage.py ├── media ├── opsweb ├── README.md ├── requirements.txt └── static 编写Dockerfile 这里指定 Python 版本为docker官方提供的 "0

阿里云server部署架构

近期要上马一个项目,客户要求所有部署到阿里云的server,做了一个阿里云的部署方案. 上图: 跟传统的部署相比,用云盾替代了传统的防火墙,负载均衡设备也不用自己买了,购买一个LBS负载均衡服务能够加入10个负载均衡实例,内网免费.由于项目的出口带宽能够统一,所以干脆使用负载均衡的流量费替代了带宽费用.(即在购买ECS的时候能够带宽能够为0或者1Mps,使用LBS负责输出流量. 有点麻烦的是,假设数据库使用的是oracle的话,好像RAC不好安装,由于没共享存储.(阿里也在推它自己的RDS关系型

阿里云上部署webservice其他机器调用提示“测试窗体只能用于来自本地计算机的请求”问题

阿里云上部署webservice,服务器本身测试可以整成使用,但是在其他机器上调用时找不到网页或者webservice 前一段时间做项目时需要用到webservice,开始时在自己的本地机器上创建了webservice,然后在vs2012中发布了这个webservice 然后在iis上配置好以后,本地调用测试开发都可以,项目接近尾声时我们需要把webservice发布到外网上,让其他程序调用, 调用时提示|:测试窗体只能用于来自本地计算机的请求 我们只要在webconfig文件中的<system