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.外观模式:聚合其他接口,简化接口

单服务多端口-Nginx 配置备忘

nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main    '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include vhosts/*.conf;

    include upstream/*.conf;
}

vhosts/example.conf

server {
    listen 8089;
    server_name localhost;

    location / {
        access_log  /var/log/nginx/bear.nginx.log;
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://example;
    }

    location ~ \.(gif|jpg|png)$ {
        root   /usr/local/src/static/;
        autoindex on;
    }
}

upstream/example.conf

upstream example {
    server 127.0.0.1:8090 max_fails=2 fail_timeout=30s weight=10;
    server 127.0.0.1:8091 max_fails=2 fail_timeout=30s weight=10;

    keepalive 32;
}