‘IT DOC’ Posts

 

GITLAB /var/opt/gitlab/.ssh/authorized_keys 未更新

Read full article  | 评论关闭

 

用户添加public key 后,/var/opt/gitlab/.ssh/authorized_keys 未更新, 重启sidekiq即可!

$ sudo gitlab-ctl kill sidekiq

$ sudo gitlab-ctl start sidekiq

Read More

GITLAB 修改DNS

Read full article  | 评论关闭

 

修改文件 “/var/opt/gitlab/gitlab-rails/etc/gitlab.yml”

修改成如下的样子就好了哦。

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: gitlab.ops.ac.cn
    port: 80
    https: false
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Read More

mongoengine 更新

Read full article  | 评论关闭

mongoengine 更新

collection.update({‘userid’:int(float(item))},{‘$set’:{‘status’:1}},upsert=False,multi=True)

有兴趣可以研究一下update的四个参数:

第一个为匹配

第二个为条件(条件上可以大作文章),

第三个为没找到是否插入,

第四个为是否支持多操作

Read More

django view太大,切分到不同的目录

Read full article  | 评论关闭

(新增目录下面一定得有__init__.py,    方法1,需要修改__init__.py,  方法2可以将__init__.py 保持为空)

备注:view 子目录引用model, 可用 from app_name.models import * 方式引用, 记得加上 app_name

方法1:

Remove the views.py file and create a directory named views. Add a __init__.py file inside it and create the separated view files.

|∙∙core/
  |∙∙__init__.py
  |∙∙admin.py
  |∙∙migrations/
  |∙∙models.py
  |∙∙tests.py
  |∙∙urls.py
  |∙∙views/
    |∙∙__init__.py
    |∙∙alpha.py
    |∙∙beta.py

views/__init__.py

This is an important step: import all the modules inside each view file.

from .alpha import *
from .beta import *

views/alpha.py

from django.shortcuts import render

def view_a(request):
    return render(request, 'view_a.html')

def view_b(request):
    return render(request, 'view_b.html')

views/beta.py

from django.shortcuts import render

def view_c(request):
    return render(request, 'view_c.html')

def view_d(request):
    return render(request, 'view_d.html')

urls.py

You don’t need to change anything here.

from django.conf.urls import url
import .views

urlpatterns = [
    url(r'^aaa$', views.view_a, name='view_a'),
    url(r'^bbb$', views.view_b, name='view_b'),
    url(r'^ccc$', views.view_c, name='view_c'),
    url(r'^ddd$', views.view_d, name='view_d'),
]

方法2:

Remove the views.py file and create a directory named views. Add a __init__.py file inside it and create the separated view files.

|∙∙core/
  |∙∙__init__.py
  |∙∙admin.py
  |∙∙migrations/
  |∙∙models.py
  |∙∙tests.py
  |∙∙urls.py
  |∙∙views/
    |∙∙__init__.py
    |∙∙alpha.py
    |∙∙beta.py

views/alpha.py

from django.shortcuts import render

def view_a(request):
    return render(request, 'view_a.html')

def view_b(request):
    return render(request, 'view_b.html')

views/beta.py

from django.shortcuts import render

def view_c(request):
    return render(request, 'view_c.html')

def view_d(request):
    return render(request, 'view_d.html')

urls.py

You don’t need to change anything here.

from django.conf.urls import url
import .views

urlpatterns = [
    url(r'^aaa$', views.view_a, name='view_a'),
    url(r'^bbb$', views.view_b, name='view_b'),
    url(r'^ccc$', views.view_c, name='view_c'),
    url(r'^ddd$', views.view_d, name='view_d'),
]



Read More

virtualenv 准备django 环境

Read full article  | 评论关闭

virtualenv ./env_chq -p /opt/apps/python/bin/python

pip install django

django-admin startproject pj_chq .

python manage.py startapp app_chq

Read More

根据列表内字典的某个KEY 进行排序

Read full article  | 评论关闭

方法1 (lambda):

newlist = sorted(list_to_be_sorted, key=lambda k: k['name']) 
备注:  如果key类型为不同类型,注意一下转换,比如int  (k: int(k['name']))

方法2:

from operator import itemgetter

newlist = sorted(list_to_be_sorted, key=itemgetter('name')) 

newlist = sorted(list_to_be_sorted, key=itemgetter('name'), reverse=True)

Read More

python mongo Q

Read full article  | 评论关闭

 

from mongoengine.queryset.visitor import Q as mongo_Q

from django.db.models import Q as normal_Q

Read More

减小AWS EC2 根分区大小

Read full article  | 评论关闭

 

https://serverfault.com/questions/673048/how-to-reduce-aws-ebs-root-volume-size

 

核心点:

1,容量小的EBS, 一定不能直接创建,而是从一个小容量ROOT EBS 克隆 (snapshot, recovery)过来的,这样克隆过来的,才有分驱表,不然根本就不能启动

2. 小容量EBS 的e2label 一定要与 /etc/fstab 里面的label  一致

3. 小容易EBS 的UUID, 应用到grub.conf , 不然照样不能启动 (可用blkid 查看 UUID)

blkid /dev/sda6

/dev/sda6: LABEL=“/” UUID=”ae6dcc02-3f7f-47cc-8a6e-e29218b4d345 ” TYPE=”ext3″ SEC_TYPE=”ext2 ”

 

 

sudo rsync -aHAXxSP /mnt/snap/ /mnt/small

 

 

Read More

调整AWS EC2 根分区大小

Read full article  | 评论关闭

 

https://serverfault.com/questions/673048/how-to-reduce-aws-ebs-root-volume-size

Read More

jenkins 以自定义时区运行

Read full article  | 评论关闭

 

java -Duser.timezone=Asia/Shanghai -Dorg.apache.commons.jelly.tags.fmt.timeZone=Asia/Shanghai -jar jenkins.war

 

两个参数都需要

Read More