0%

之前跨域处理的header都是后端返回的.昨天改回nginx来添加这个header,感觉这样写比较好用清晰,所以记录一下.

注意在allow headers添加上自己额外增加的header就好了,比如我们header添加了token,所以这里也加了.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
set $origin '*';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' $origin;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,token';
add_header 'Content-Length' 0;
return 204;
}

if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' $origin;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,token';
}

if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' $origin;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,token';
}

Read more »

开始

什么是 GraphQL?

GraghQL的介绍,概览和概念,参考 官方介绍

让我们构建一个基本的GraphQL schema.

依赖

  • Python(2.7, 3.4, 3.5, 3.6, pypy)
  • Graphene (2.0)

项目安装

1
pip install "graphene>=2.0"

创建一个基础的Schema

一个描述你数据模型的GraphQL Schema,和提供GraphQL 服务,关联对应的解析方法,该方法知道怎样获取对应的数据.

我们将创建一个非常简单的schema,一个Query,只有一个field:hello和输入名字.当我们查询它,它应当返回`”Hello {argument}”.

1
2
3
4
5
6
7
8
9
import graphene

class Query(graphene.ObjectType):
hello = graphene.String(argument=graphene.String(default_value="stranger"))

def resolve_hello(self, info, argument):
return 'Hello ' + argument

schema = graphene.Schema(query=Query)

查询

然后我们开始查询我们的schema:

1
2
3
4
5
6
result = schema.execute('{ hello }')
print(result.data['hello']) # "Hello stranger"

# or passing the argument in the query
result = schema.execute('{ hello (argument: "graph") }')
print(result.data['hello']) # "Hello graph"
Read more »

最近consul节点被意外终止后,重新运行.发现该节点下的服务均无法注册上去.

看日志,发现类似的错误

1
rpc error making call: failed inserting node: Error while renaming Node ID: "xxxxx": Node name node2 is reserved by node xxxxxx-xxxxx-384e-0bf4-xxxxx with name node2

日志里两个node id是不一样的. 估计是重启后,生成了新的node id.这和挂掉之前,存在consul server中的 node2的id不一致,导致冲突.

解决

上面例子中,我是在节点2执行了一个 consul leave的动作就好了.

1
docker exec consul consul leave

如果不行,就 离开集群 -> 重启consul -> 加入集群

另外看到其它应该可行的方法,但是我没有尝试.

以上问题,主要是因为生成了新的node id 导致的node id冲突. 那不让它生成不就好了.

启动时加入-disable-host-node-id

或者指定node id -node-id=$(uuidgen | awk ‘{print tolower($0)}‘) node id必须是guid格式

Read more »

1. 注解方式

如: @app.route('/')

1
2
3
4
5
6
7
8
9
10
11
12
# -*- coding: utf-8 -*-

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
return 'index.'


app.run(debug=True)

@app.route('/')还可以附带options.如限定特定的method. @app.route(rule='/',methods=['GET','POST'])

2. app.add_url_rule('/',view_func=index)

实际上注解也是调用了这个接口,来注册的.只不过用了闭包形式来封装注册过程显得更为简洁.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# -*- coding: utf-8 -*-

from flask import Flask

app = Flask(__name__)


def index():
return 'index.'

app.add_url_rule(rule='/', view_func=index)

app.run(debug=True)

Read more »

最近经常需要装nodejs,在发现有这个方法后,毅然抛弃了源码安装,舒服.

1
2
3
4
5
6
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum install -y nodejs
yum install -y gcc-c++ make
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
yum install yarn

参考资料

Read more »

什么是容器

  • 资源视图隔离 - namespace
  • 控制资源使用率 - cgroup
  • 独立的文件系统 - chroot

容器是一个视图隔离、资源可限制、独立文件系统的进程集合。

什么是镜像

运行容器所需要的所有文件集合 - 容器镜像

Dockerfile - 描述镜像构建步骤

构建步骤所产生出文件系统的变化 - changeset

容器的生命周期

单进程模型

  1. init进程生命周期 - 容器生命周期
  2. 运行期间可运行exec执行运维操作

数据持久化

  1. 独立于容器的生命周期
  2. 数据卷 - docker volume vs bind

容器项目架构

moby 容器引擎架构

  • containerd
  1. 容器运行时管理引擎,独立于moby daemon
  2. containerd-shim 管理容器生命周期 可以被containerd动态接管
  • 容器运行时
  1. 容器虚拟化技术方案
  2. runC kata gVisor
Read more »

插图大小

宽: 1200px

字体

描述大小: 18px
标题大小: 32px
字体: Source Code Pro

颜色

用途 颜色
背景色
#EEEEEE
文字颜色1
#EEEEEE
文字颜色2
#333333
组件颜色 - Sinbad
#66CCCC
组件颜色 - Sinbad Light
#99CCCC
组件颜色 - Golden Sand
#FFCC66
组件颜色 - Golden Sand Light
#FFCC99
组件颜色 - Gray
#555555
组件颜色 - Gray Light
#888888
组件颜色 - Sweet Pink
#FF6666
组件颜色 - Sweet Pink Light
#FF9999

高饱和度: https://flatuicolors.com/palette/se

参考资料

1
2
3
4
5
6
yum -y install yum-utils
yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional
yum install -y python2-certbot-nginx
pip install -U pip
pip install --upgrade --force-reinstall 'requests==2.6.0' urllib3
ln -s /usr/local/nginx/conf /etc/nginx

配置证书 certbot --nginx 根据提示生成证书

配置定时续约证书

crontab -e

1
0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew 

好了没了,就这么简单

Read more »

因为最近换了jenkins地址,之前CI环节依赖的gitee webhook。但是之前webhook的URL写的是ip。所以需要批量修改。

然而仓库上百个,头皮发麻。不过好在看到gitee有提供了API,虽然没找到sdk,但是也好很多了。

简单写了一个,放上来存档。

Read more »

漏洞成因

微擎米波现场插件存在任意修改密码漏洞。

  • meepo_xianchang/inc/web/account_manage.inc.php

143-193行,普通用户登录后,修改密码功能,ac_uid是可以外部传入的。只要传入其它用户的UID,即可修改掉其它用户的密码。

Read more »