Debian+django+uwsgi+nginx+mysql+celery

Source: Internet
Author: User
Tags chmod

Download the system various dependencies

Nano/etc/apt/sources.list

Using Apt-get to install packages in Debian often prompts you to insert Netinst discs:

Media change:please Insert the disc labeled

Comment out the following line

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

Pull the project to the server

CD ~

SSH-KEYGEN-T RSA

Cat ~/.ssh/id_rsa.pub

Paste the public key onto the code cloud

git clone xxxxxxxxx

The address on the code cloud should prevail here

PIP installs various packages

CD ~/serve/

Environmenterror:mysql Config not found

Apt-get Install Libmysqld-dev

Online someone explained that using Apt-get installed MySQL is not mysql_config this file

Pip Install-r requirements.txt

Configure celery

cd/etc/systemd/system/

Nano Celery.service

The contents are as follows:

[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

The contents are as follows:

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"

Start celery

Systemctl Daemon-reload

Systemctl start celery

Ps-ef|grep celery

Systemctl Enable celery

Systemctl Stop celery

Installation Configuration Uwsgi

Pip Install Uwsgi

cd/root/

Nano Serve.ini

The contents are as follows:

[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

Test whether the Uwsgi is normal

Uwsgi-i/root/serve.ini

Ps-ef |grep Uwsgi

Pkill-9 Uwsgi

Installation Configuration Nginx

Apt-get Install Nginx

cd/etc/nginx/sites-enabled/

Nano Court

Take care to change the server_name IP address.

The contents are as follows:

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 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

Uninstalling 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

Database-related Operations

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

In the Django Build database related tables

CD ~/serve/

Python manage.py makemigrations

Python manage.py Migrate

Python manage.py Createsuperuser

Start the service

Systemctl start celery

Uwsgi-i/root/serve.ini

Problems that may occur

After you enter the IP address, you may lose the style, online workaround:

Chmod-r 755/root

This method personally think is dangerous, but is the quickest solution, no way, who told you to put the project in Root's home directory

Debian+django+uwsgi+nginx+mysql+celery

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.