Debian+Django+uWsgi+nginx+mysql+celery

下载系统各种依赖

nano /etc/apt/sources.list

在Debian中使用apt-get安装软件包时经常会提示让你插入netinst的光盘:

Media change: please insert the disc labeled

把下面这一行注释掉

deb cdrom:[Debian GNU/Linux 8.2.0 _Jessie_ - Official amd64 CD Binary-1 20150$

apt-get update

apt-get install python-setuptools python-dev python-pip python-virtualenv redis-server mysql-server mysql-client git -y

把项目拉到服务器

cd ~

ssh-keygen -t rsa

cat ~/.ssh/id_rsa.pub

把公钥粘贴到码云上

git clone xxxxxxxxx

此处应以码云上的地址为准

pip安装各种包

cd ~/serve/

EnvironmentError:mysql config not found

apt-get install libmysqld-dev

网上有人解释说使用apt-get安装的MySQL是没有mysql_config这个文件的

pip install -r requirements.txt

配置celery

cd /etc/systemd/system/

nano celery.service

内容如下:

[Unit]

Description=Celery Service

After=network.target

[Service]

Type=forking

#User=celery

#Group=celery

EnvironmentFile=-/etc/conf.d/celery

WorkingDirectory=/root/serve

ExecStart=/bin/sh -c ‘${CELERY_BIN} multi start ${CELERYD_NODES} \

-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \

--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}‘

ExecStop=/bin/sh -c ‘${CELERY_BIN} multi stopwait ${CELERYD_NODES} \

--pidfile=${CELERYD_PID_FILE}‘

ExecReload=/bin/sh -c ‘${CELERY_BIN} multi restart ${CELERYD_NODES} \

-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \

--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}‘

[Install]

WantedBy=multi-user.target

mkdir conf.d

cd conf.d/

nano celery

内容如下:

CELERYD_NODES="w1 w2 w3"

CELERY_BIN="/usr/local/bin/celery"

CELERY_APP="serve"

CELERYD_MULTI="multi"

CELERYD_PID_FILE="/etc/celery/%n.pid"

CELERYD_LOG_FILE="/etc/celery/%n%I.log"

CELERYD_LOG_LEVEL=“INFO”

启动celery

systemctl daemon-reload

systemctl start celery

ps -ef|grep celery

systemctl enable celery

systemctl stop celery

安装配置uwsgi

pip install uwsgi

cd /root/

nano serve.ini

内容如下:

[Install]

WantedBy=multi-user.target

[email protected]:/etc/apt# nano /etc/conf.d/celery

[email protected]:/etc/apt# cat /root/serve.ini

[uwsgi]

chdir=/root/serve

socket=/var/run/serve.sock

chmod-socket=666

module=serve.wsgi:application

master=True

pidfile=/tmp/serve.pid

vacuum=True

max-requests=5000

processes = 4

daemonize=/var/log/uwsgi/serve.log

测试uwsgi是否正常

uwsgi -i /root/serve.ini

ps -ef |grep uwsgi

pkill -9 uwsgi

安装配置nginx

apt-get install nginx

cd  /etc/nginx/sites-enabled/

nano court

注意要把server_name的ip地址改了

内容如下:

server {

listen          80;

server_name    172.16.146.133;

client_max_body_size    10m;

gzip_vary on;

gzip_proxied any;

gzip_comp_level 6;

gzip_buffers 16 8k;

gzip_http_version 1.1;

gzip_types text/plain text/css application/json application/x-javascript;

location / {

uwsgi_pass      unix:///var/run/serve.sock;

include         uwsgi_params;

uwsgi_param     UWSGI_SCHEME $scheme;

uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;

}

location /static/ {

alias           /root/serve/static/;

index           index.html index.htm;

}

location /static/admin/ {

alias           /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin$

index           index.html index.htm;

}

charset  utf-8;

}

systemctl restart nginx

ps -ef|grep nginx

卸载nginx(if necessary)

dpkg --get-selections|grep nginx

apt-get --purge remove nginx

apt-get --purge remove nginx-common

apt-get --purge remove nginx-core

find / -name "*nginx*"|rm -fr

数据库相关操作

service mysql start

mysql -u root -p

create database serve;

create user ‘serve‘@‘localhost‘ identified by ‘serve‘;

grant all privileges ON serve.* to ‘serve‘@‘localhost‘;

flush privileges;

exit;

在django生成数据库相关表

cd ~/serve/

python manage.py makemigrations

python manage.py migrate

python manage.py createsuperuser

启动服务

systemctl start celery

uwsgi -i /root/serve.ini

可能出现的问题

输入ip地址之后,可能样式会丢失,网上解决办法:

chmod -R 755 /root

这个方法个人觉得是有危险的,但是是最快解决问题的,没办法,谁叫你把项目放在root的家目录下

时间: 2024-08-04 08:58:23

Debian+Django+uWsgi+nginx+mysql+celery的相关文章

Django+uWSGI+Nginx 部署网站

Django 1.11设置 保证Django在本地调试没有问题: 当然这是前提^_^ 收集静态文件至指定文件夹 Django静态文件设置具体参考:https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/ 在myproject/settings.py中设置静态文件STATIC_URL和STATIC_ROOT设置: 如: STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE

用Docker部署Django+uWSGI+Nginx

用Docker部署Django+uWSGI+Nginx 大致步骤如下: 创建Centos容器 安装Python及pip 安装MySQL 使Django连接到MySQL 运行uWSGI服务器 运行Nginx服务器 ? ? 创建Centos容器 安装docker软件 yum install docker 创建一个centos容器 docker run -d --name deploy1 --network host centos tail -f /dev/null -d:让它在后台运行. –name

Django + Uwsgi + Nginx 的生产环境部署

使用runserver可以使我们的django项目很便捷的在本地运行起来,但这只能在局域网内访问,如果在生产环境部署django,就要多考虑一些问题了.比如静态文件处理,安全,效率等等,本篇文章总结归纳了一下基于uwsgi+Nginx下django项目生产环境的部署 准备条件: 1.确保有一个能够用runserver正常启动的django项目 2.项目已上传到linux 3.linux上已部署好python环境,且已安装好项目所需的模块 安装uwsgi uwsgi是python的一个模块,安装u

Django + Uwsgi + Nginx 实现生产环境部署

一.如何在生产上部署Django? Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 二.uwsgi介绍 uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换. 要注意 WSGI / uwsgi / uWSGI 这三个概念的区分. WSGI是一种Web服务器网关接口.它是一个Web服务器(如nginx,uWSGI等服务器)与web应用(如用Flask

Django+uWsgi+nginx部署

一.环境 操作系统:Ubuntu 14.04 64位 python:2.7.6 Django:1.8.2 项目源码:https://github.com/youchuancong/django.git 部署方式:Django+uWsgi+nginx 二.部署 1.Django安装 官网:https://www.djangoproject.com/ 安装 wget https://www.djangoproject.com/m/releases/1.8/Django-1.8.2.tar.gz ta

python django+uwsgi+nginx 搭建步骤(血一般的教训)

安装Django 没有pip的童鞋可以看http://blog.csdn.net/imphp/article/details/38228619安装python包管理工具pip 先在 https://pypi.python.org/ 上 搜索Django,排在第一的那个就是我们要安装的主要框架Django啦- 点进去可以查找一些相关文档,虽然全部是鸟语花香,不过有翻译.百度.炕忙,就算是菜鸟也成英国鸟了. Django 的官网文档 https://docs.djangoproject.com/en

[linux]centos7.4部署django+Uwsgi+Nginx

前言:我已经写了几个接口用来部署在服务器上的,首先选择django+Uwsgi+Nginx因为配置简单,比较符合python的简单操作功能强大的特点 然后对于django的一些版本在之前的文章写了 参考:https://www.cnblogs.com/Jack-cx/p/9351633.html  根据版本,服务器pip3 install xxx 安装下 我的django项目大概结构: TestWebApi ----TestWebApi ----Apiso(创建的应用) ----manage.p

django+uwsgi+nginx部署(非常详细)

django+uwsgi+nginx部署 1.介绍: 在网上看了很多教程,但自己部署了很久都没有成功,这篇博文记录自己所踩过得坑. 2.环境: 1 Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-130-generic x86_64) 3.下载uwsgi以及nginx 1 apt-get install uwsgi 2 apt-get install nginx (注:如果下载异常出现权限问题,在命令前添加sudo) 4.创建Django项目 例如:项目名为mysite

CentOS + Python3.6+ Django2.0 + uwsgi + nginx + mysql web发布环境搭建

目录: CentOS上升级Python 安装easy_install和pip uwsgi安装及测试 Django安装及测试 连接uwsgi与Django nginx安装及测试 连接uwsgi与nginx 连接uwsgi与Django与nginx uwsgi ini mysql安装设置 python3 Django mysql连接及测试 快速搭建blog测试 Pycharm开发 如果只是想学习django开发直接用django本身自带的开发用服务器即可. 1. CentOS上升级Python 用的