docker network && storage summary

network

按照官方文档讲常用基本 network 有3种:bridge、overlay、host。
  1. bridge:单一主机上容器连通网络,可以隔离其他容器,同时命名 bridge netowrk 比默认的多了名字解析功能,每个容器拥有自己的 ip。

  2. overlay:多主机上容器连通网络。

    • an overlay network called ingress, which handles control and data traffic related to swarm services. When you create a swarm service and do not connect it to a user-defined overlay network, it connects to the ingress network by default.
    • a bridge network called docker_gwbridge, which connects the individual Docker daemon to the other daemons participating in the swarm。
  3. host:容器使用 host 主机的 ip。

storage

基本有3种:volume、bind、tmpfs,图示:

volume 有几种创建方式:
  • 常规挂载到本机
  • sshfs 挂载到其他主机:
docker plugin install --grant-all-permissions vieux/sshfs
docker volume create --driver vieux/sshfs \
  -o [email protected]:/home/test \
  -o password=testpassword \
  sshvolume
docker volume create --driver vieux/sshfs \
  -o [email protected]:/home/test \
  -o password=testpassword \
  sshvolume

 # 注意这里 node2 需要 docker daemon。另外如果已经共享了公钥,可以省略参数 password。
bind propagation 配置有6种:

若有 /mnt_origin, /mnt_replica 2个挂载点: - shared:任意挂载点下创建文件,彼此都可见。

  • slave:单向传播,mnt_origin 下创建的文件,mnt_replica 下可见;反之不行。
  • private: 彼此下新建文件都不可见。
  • 上述3种模式都有对应的 r+ 模式,表示递归。

Docker Get Started, Part 1~6 Summary

container:

a server app 
-> docker build image from a Dockerfile
-> docker run

services:

one host, run a service with multi app instance
-> docker swarm init 
-> docker stack deploy -c docker-compose.yml xxx, which define replic, deploy params …
-> docker stack rm xxx
-> docker swarm leave --force

swarms:

multi host as a cluster, run a service with multi app instance, strategies to run containers in compose.yml can be:
    “emptiest node”: fills the least utilized machines with containers. 
    “global”: which ensures that each machine gets exactly one instance of the specified container
-> docker-machine create
-> docker swarm init on one host as master
-> docker swarm join master as worker

stacks:

with multi host as a cluster, run multi services which can be run in multi app instance, 
using strategies the same as swarms

FAQ:

What is the difference between docker service and stack?

2019年计算机相关读书总结

2019年订阅了极客时间里的一个专栏,按照专栏里面的练级攻略,有些很有价值的书,我都没看过或者完整看过,所以决定把它们看一遍。现在总结一下部分我看过的:

  • 《代码大全》:目前觉得最实用的是调整代码的策略和技术,比如子程序分解。
  • 《Java 核心技术(卷1)》:算是强化一下 Java 的基础知识。
  • 《Spring in Action》:传统的样板代码 spring mvc。
  • 《Spring Boot 实战》:参考官方文档,利用起步依赖,外加使用 gradle 编译程序,写 Java 项目手到擒来。
  • 《Effective Java》:各种语言都有对应的 effective...
  • 《Google Guava》:google 的 java 库工具。
  • 《Java 并发编程实战》:粗略的看了看...
  • 《Java 性能权威指南》:使用 JDK 自带工具可以收集 Java 应用的性能数据,同时也了解了各种 GC 以及它们的适用场景。还有堆内存模型,新生代/老年代,等等等等。
  • 《重构:改善既有代码设计》
  • 《OWASP top 10》
  • 《Monitoring 101》:运维相关,指示如何收集正确的指标数据。
  • 《设计模式》:这回看的是 Java 版本,有点绕,对比熟悉的 Python 版本,外加维基百科,尽量理解了一些。
  • 《Go 101》: 过了一遍,同时给原项目贡献了个 pr 。
  • 《Effective Go》:如果以后用 go 作为主力语言,这个文档还需要再过一遍。
  • 《深入理解计算机系统》:外号是《程序员所需要了解的计算机知识》。
  • 《Unix 高级环境编程》:主要是了解信号方面的一些知识...
  • 《Unix 网络编程 第一卷》:主要是看讲解那几种 io 模型。
  • 《TCP/IP 详解 卷一》:里面的图示很清楚,加深印象。
  • 《Wireshark 数据包分析实战》:之前做项目用到过,现在全面了解一下,学习下过滤语法。

  • to be continued...

the meaning of “tar xxx.tar –strip 1”

“tar xxx.tar --strip 1”,--strip 1 的意思是表明把解压文件的内容里的所有最上层目录去掉。

例如有:压缩文件 ab.tar,其内容为:
├── Da
│   └── a.txt
├── Db
│   └── b.txt

如果常规解压"tar xvf ab.tar" ,得到内容如上图描述一样。

倘若执行 "tar xvf ab.tar --strip 1",最终内容为:
│   ── a.txt
│   ── b.txt

科学上网之 Brook

Brook

Brook是一个由 Go语言编写的跨平台代理软件,支持 Linux/MacOS/Windows/Android/iOS 各个平台。

Brook Github项目:https://github.com/txthinking/brook
Github Wiki教程:https://github.com/txthinking/brook/wiki/使用说明(中文)

服务器一行命令安装:

  • wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/brook.sh && chmod +x brook.sh && bash brook.sh

常见设计模式

1.观察者模式

2.装饰器模式

3.简单工厂 通过传递不同参数得到不同实例。

4.抽象工厂 通过创建实现了抽象工厂接口的工厂,内部实例创建的封装,创建一组相关实例。

5.工厂方法:通过实现接口,使得不同接口返回不同实例。

6.单例模式:java 枚举类型

7.命定模式:记录请求历史;实现回调;实现撤销功能

8.外观模式:聚合其他接口,简化接口