UUBlog

UUBlog

红帽系源是默认用mariadb的,而且mariadb也很优秀,但是我们开发是基于MySQL5.7上做的开发,基本10.2起,应该对MySQL5.7所有的特性是完整支持的.

但是为了稳妥,还是决定给客户安装一样的版本.

在官网找文档的时候,发现藏得有点深,所以还是打算记录下.

安装

完整的命令大致如下

1
2
3
4
shell> yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
shell> yum repolist all | grep mysql
shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql57-community

当看到mysql源是57(自己想要的版本的时候就可以直接安装了)

1
2
3
4
5
6
shell> yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 118
mysql-tools-community/x86_64 MySQL Tools Community 95
mysql57-community/x86_64 MySQL 5.7 Community Server 364

shell> yum install mysql-community-server
Read more »

关注公众号 尹安灿

下载地址

https://www.charlesproxy.com/latest-release/download.do

example:

wget https://www.charlesproxy.com/assets/release/4.2.8/charles-proxy-4.2.8_amd64.tar.gz

破解文件

破解文件生成: https://www.zzzmode.com/mytools/charles/

tar zxvf charles-proxy-4.2.8_amd64.tar.gz

把下载的破解文件覆盖到 charles/lib 目录即可

添加charles ca证书 抓取https数据

  1. 访问: chls.pro/ssl 下载证书

  2. 放置证书
    创建个目录放证书 sudo mkdir /usr/share/ca-certificates/charles
    sudo mv ~/charles-ssl-proxying-certificate.pem /usr/share/ca-certificates/charles

  3. 刷新证书配置

Read more »

关注公众号 尹安灿

本地是在虚拟机中建立的k8s环境,安装好后,因为没有负载均衡器,所externalip一直处于pending.官网解决方案是使用nodeport转发.

但是,直接edit svc填写externalip为虚拟机ip即可正常使用了.

1
2
3
4
# kubectl edit svc istio-ingressgateway -n istio-system
spec:
externalIPs:
- xxx.xxx.xxx.xxx
Read more »

关注公众号 尹安灿

之前跨域处理的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 »

关注公众号 尹安灿

0%