The Django framework
果库网站 V4
- Ubuntu
- Python2.7
- MySQL
- Nginx
- Redis
brew install mysql
brew install imagemagick
virtualenv guoku-v4
source /path/to/guoku-v4/bin/active
pip install -r requirements
- django-1.6.5 相关文档
- django-storage (果库开发) https://github.com/guoku/django-storages.git
- MySQL-python
- django-debug-toolbar
- Wand 相关文档
- "结巴"中文分词 相关文档
pip install jieba
- django-debug-toolbar 相关文档
- 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
* 以获取热门商品为例:
利用 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)
- 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 主要运行在 docker 容器中
- 10.0.2.115
- 10.0.2.110 (backup)
- 10.0.2.125 (rabbitmq)