Skip to content

coding-neuropathy/nut

 
 

Repository files navigation

The Django framework

概览

果库网站 V4

系统环境

  • Ubuntu
  • Python2.7
  • MySQL
  • Nginx
  • Redis

安装 MySQL

brew install mysql

安装 ImageMagick

brew install imagemagick

快速安装

virtualenv guoku-v4
source /path/to/guoku-v4/bin/active
pip install -r requirements

后端框架

前端框架

安装包

分词

pip install jieba

Debug 工具

部署到服务器

  • deploy 目录结构
deploy/
├── config.ini
├── guoku.pass
├── reload_server.py
├── update_online_code.sh
└── upload_code.py
  • config.ini 配置文件
  • guoku.pass 密码文件
  • reload_server.py 重启服务
  • upload_code.py 上传代码
  • update_online_code.sh 更新代码 并且重启服务
pip install fabric
cd deployo/
fab -f upload_static.py deploy_static
fab -f upload_code.py uploac_code

Models 与 Cache 之间的关系

* 以获取热门商品为例:

利用 django models queryset 实现扩展的 SQL 查询。 Manager 方法来实现缓存。 以减少 models 层面的改动,而影响 views.

class EntityLikeQuerySet(models.query.QuerySet):

    def popular(self):
        dt = datetime.now()
        days = timedelta(days=7)
        popular_time = (dt - days).strftime("%Y-%m-%d") + ' 00:00'
        return self.filter(created_time__gt=popular_time).annotate(dcount=models.Count('entity')).values_list('entity_id', flat=True)

    def user_like_list(self, user, entity_list):

        return self.filter(entity_id__in=entity_list, user=user).values_list('entity_id', flat=True)


class EntityLikeManager(models.Manager):

    def get_query_set(self):
        return EntityLikeQuerySet(self.model, using=self._db)

    def popular(self):
        res = cache.get('entity_popular')
        if res:
            return res
        res = self.get_query_set().popular()
        cache.set('entity_popular', res, timeout=3600)
        return res

    def user_like_list(self, user, entity_list):

        return self.get_query_set().user_like_list(user=user, entity_list=entity_list)

导出数据

/opt/mysql5/bin/mysqldump --single-transaction --flush-logs -u root core --ignore-table=core.core_entity_like --ignore-table=core.notifications_notification > core.sql

发布服务器

  • 使用 keepalived 健康性检查
  • 10.0.2.49 (master)
  • 10.0.2.46 (backup)

application server

  • 10.0.2.46
  • 10.0.2.47

数据缓存服务

  • 10.0.2.46
  • 10.0.2.120
  • 10.0.2.115

图片处理服务器 相关代码

  • 10.0.2.110
  • 10.0.2.115

图片缓存服务器

  • 10.0.2.110
  • 10.0.2.115

图片存储服务器

  • 10.0.2.50 (tracker)
  • 10.0.2.48
  • 10.0.2.125
  • 10.0.2.200

数据库服务器

  • 10.0.2.90 (master)
  • 10.0.2.95 (slave) read only

solr 服务器

  • solr 主要运行在 docker 容器中
  • 10.0.2.115
  • 10.0.2.110 (backup)

消息队列服务器

  • 10.0.2.125 (rabbitmq)

Email

jiaxin@guoku.com

Packages

No packages published

Languages

  • JavaScript 31.6%
  • HTML 31.2%
  • CSS 21.8%
  • Python 15.2%
  • PLpgSQL 0.2%
  • PHP 0.0%