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
root@Aaron:/etc/apt# nano /etc/conf.d/celery
root@Aaron:/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的更多相关文章
- Linux 集群概念 , wsgi , Nginx负载均衡实验 , 部署CRM(Django+uwsgi+nginx), 部署学城项目(vue+uwsgi+nginx)
Linux 集群概念 , wsgi , Nginx负载均衡实验 , 部署CRM(Django+uwsgi+nginx), 部署学城项目(vue+uwsgi+nginx) 一丶集群和Nginx反向代理 ...
- Django+uWSGI+Nginx 部署网站
Django 1.11设置 保证Django在本地调试没有问题: 当然这是前提^_^ 收集静态文件至指定文件夹 Django静态文件设置具体参考:https://docs.djangoproject. ...
- django+uWSGI+nginx的工作原理流程与部署过程
django+uWSGI+nginx的工作原理流程与部署过程 一.前言 知识的分享,不应该只是展示出来,还应该解释这样做是为什么... 献给和我一样懵懂中不断汲取知识,进步的人们. 授人与鱼,不如授人 ...
- CentOS7.4部署Python3+Django+uWSGI+Nginx
CentOS7.4部署Python3+Django+uWSGI+Nginx http://www.showerlee.com/archives/2590
- virtualvenv+django+uWSGI+nginx 部署
原创博文 转载请注明出处! 1. virtualvenv 2. django 3. uWSGI 4. nginx 5. 踩坑记录 1. virtualvenv virtualvenv install ...
- Django+uwsgi+nginx+angular.js项目部署
这次部署的前后端分离的项目: 前端采用angular.js,后端采用Django(restframework),他俩之间主要以json数据作为交互 Django+uwsgi的配置可以参考我之前的博客: ...
- django+uwsgi+nginx部署(非常详细)
django+uwsgi+nginx部署 1.介绍: 在网上看了很多教程,但自己部署了很久都没有成功,这篇博文记录自己所踩过得坑. 2.环境: Ubuntu 16.04.1 LTS (GNU/Linu ...
- python django uwsgi nginx安装
python django uwsgi nginx安装 已安装完成python/django的情况下安装 pip install uwsgi cd /usr/share/nginx/html/ vim ...
- 10: Django + Uwsgi + Nginx 的生产环境部署
1.1 一些重要概念 1.Web协议介绍 Web协议出现顺序: CGI -> FCGI -> WSGI -> uwsgi 1. CGI: 最早的协议 2. FCGI: 比CGI快 ...
随机推荐
- Codeforces 1092C Prefixes and Suffixes(思维)
题目链接:Prefixes and Suffixes 题意:给定未知字符串长度n,给出2n-2个字符串,其中n-1个为未知字符串的前缀(n-1个字符串长度从1到n-1),另外n-1个为未知字符串的后缀 ...
- java强引用 软引用 弱引用 虚引用
https://www.cnblogs.com/yw-ah/p/5830458.html Java四种引用包括强引用,软引用,弱引用,虚引用. 强引用: 只要引用存在,垃圾回收器永远不会回收Objec ...
- 论decltype和auto的区别
论decltype和auto的区别 decltype和auto的区别 ①对引用变量的不同之处:auto将引用变量赋给变量后,变量的类型为引用变量所对应的变量的类型.而decltype则是为引用类型 ...
- 使用graphviz画图
安装: 要使用Graphviz,先要在系统上安装Graphviz. 在Ubuntu上安装可以使用命令: sudo apt-get install graphviz 在其他系统安装的方法可以查看Grap ...
- Java线程池源码解析
线程池 假如没有线程池,当存在较多的并发任务的时候,每执行一次任务,系统就要创建一个线程,任务完成后进行销毁,一旦并发任务过多,频繁的创建和销毁线程将会大大降低系统的效率.线程池能够对线程进行统一的分 ...
- clickhouse修改时区
clickhouse时区设置 sudo vim /etc/clickhouse-server/config.xml <timezone>Asia/Shanghai</timezone ...
- Android项目打包遇com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
查了网上很多处理都是在项目的gradle.properties中添加下面的配置,再编译就通过了: android.enableAapt2=false
- http升级https的时候,遇到一个问题
问题: Mixed Content: The page at 'https://api.xxxx.com/test' was loaded over HTTPS, but requested an i ...
- L1-Day6
1.我喜欢哈尔滨的夏天 [我的翻译]I like the summer in harebing. [标准答案]I like the summer in Harbin. [对比分析]哈尔滨 Harbin ...
- STL--sort源码分析
SGI STL sort源码 temlate <class RandowAccessIterator> inline void sort(RandowAccessIterator firs ...