Debian+Django+uWsgi+nginx+mysql+celery

來源:互聯網
上載者:User

標籤:nts   virtual   目錄   for   net   ble   any   min   charset   

 

下載系統各種依賴

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的家目錄下

 

Debian+Django+uWsgi+nginx+mysql+celery

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.