关闭

Django打造运维简单的IMS系统

标签: djangocentos运维
610人阅读 评论(0) 收藏 举报
分类:

Django

学习资料

实战项目(CentOS 6.6 + Python 3.4.5 + Django 1.10)

部署Python

cd /usr/local/src/
wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
tar xzvf Python-2.7.12.tgz
cd Python-2.7.12
./configure --prefix=/usr/local/python-2.7.12
make -j 4
make install

新建虚拟环境

# virtualenv -p /usr/local/python-2.7.12/bin/python2.7 /usr/local/scripts/iiotdjangovirtualenv -p /usr/local/python-3.4.5/bin/python3.4 /usr/local/scripts/python3.4iiotdjango

# alias djangoenv="source /usr/local/scripts/iiotdjango/bin/activate"

alias djangoenv="source /usr/local/scripts/python3.4iiotdjango/bin/activate"

source /usr/local/scripts/iiotdjango/bin/activate

安装Django

pip install django
yum install -y mysql-devel
pip install MySQL-pythonpython3 -m pip install pymysqlpip3 install mysqlclient
# apt-get install libmysqld-dev
# apt-get install libpython-dev
# 参考
http://stackoverflow.com/questions/23376103/python-3-4-0-with-mysql-database

数据库准备

yum install -y mysql-server
service mysqld restart
CREATE USER 'ops'@'localhost' IDENTIFIED BY '123123';GRANT ALL PRIVILEGES ON *.* TO 'ops'@'localhost';FLUSH PRIVILEGES;
CREATE USER 'ops'@'%' IDENTIFIED BY '123123';GRANT ALL PRIVILEGES ON *.* TO 'ops'@'%';FLUSH PRIVILEGES;
mysql -u root -p123123
create database iiot

Django调整

DB准备

python manage.py migratepython manage.py makemigrations
python manage.py createsuperuser

新建Project

django-admin startproject iiotdjango

新建APP

django-admin startapp ims

Models调整

from __future__ import unicode_literalsfrom django.db import modelsclass ims(models.Model): lanip = models.CharField(max_length = 100) password = models.CharField(max_length = 100) type = models.CharField(max_length = 100) className = models.CharField(max_length = 100) groupName = models.CharField(max_length = 100) jifang = models.CharField(max_length = 100) jigui = models.CharField(max_length = 100) beizhu = models.CharField(max_length = 100)

 def __str__(self): return self.lanipmodels的简单用法 https://docs.djangoproject.com/en/1.10/ref/models/fields/

admin.py调整

from django.contrib import admin
from ims.models import ims
class imsAdmin(admin.ModelAdmin):
 list_display=('lanip','password','type','className','groupName','jifang','jigui','suzhuji','beizhu')
 search_fields = ('lanip','password','type','className','groupName','jifang','jigui','suzhuji','beizhu')
admin.site.register(ims,imsAdmin)

settings.py 调整

  • APP的地方加入 “ims”

  • DB的地方


INSTALLED_APPS = (  'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog',)

运行


source /usr/local/scripts/python3.4iiotdjango/bin/activatepython manage.py runserver 0.0.0.0:8081

Nginx


server {
 listen 80;
 charset utf-8;
 server_name ims.ops.ac.cn;
 location / {
 proxy_pass http://127.0.0.1:8081;
 }
}

联合测试

采用USWGI

  • 安装
pip install uwsgi
  • 配置文件
# FileName : uwsgi.ini
[uwsgi]
socket = 127.0.0.1:3031
chdir = /usr/local/scripts/python34projectpiot
wsgi-file = ./python34projectpiot/
wsgi.pyprocesses = 4
threads = 2
stats = 127.0.0.1:9191
daemonize=/var/log/nginx/uwsgi.log
  • 运行
uwsgi uwsgi.ini
  • nginx 配置文件
upstream django { 
    server 127.0.0.1:3031;
}

server { 
    listen 80; 
    charset utf-8; 
    server_name ims.ops.ac.cn; 
    location / { 
        include uwsgi_params; 
        #proxy_set_header Host $host; 
        #proxy_pass http://127.0.0.1:8081; 
        #uwsgi_pass 127.0.0.1:3031; 
        uwsgi_pass django; 
    } 
    location /static { 
        root /usr/local/scripts/python3.4iiotdjango/lib/python3.4/site-packages/django/contrib/admin; 
    }
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:255537次
    • 积分:10085
    • 等级:
    • 排名:第1697名
    • 原创:779篇
    • 转载:34篇
    • 译文:5篇
    • 评论:50条
    链接
    文章分类
    最新评论
    google analysis