Maven常用插件

=========Maven Report Plugin=========
1.源码分析

<artifactId>maven-pmd-plugin</artifactId>

2.代码格式检查

<artifactId>maven-checkstyle-plugin</artifactId>

3.代码相似度检查

<groupId>org.codehaus.mojo</groupId>
<artifactId>simian-maven-plugin</artifactId>

4.格式化统计报告

<groupId>org.codehaus.mojo</groupId>
<artifactId>jdepend-maven-plugin</artifactId>

5.FireBug检查

<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>

6.JavaDoc

<artifactId>maven-javadoc-plugin</artifactId>

7.生成java代码交叉引用和源代码的html格式

<artifactId>maven-jxr-plugin</artifactId>

8.代码覆盖率

<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>

<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>

9.java代码的度量工具

<groupId>org.codehaus.mojo</groupId>
<artifactId>javancss-maven-plugin</artifactId>

10.单元测试报告

<artifactId>maven-surefire-report-plugin</artifactId>

11.TODO检查报告

<groupId>org.codehaus.mojo</groupId>
<artifactId>taglist-maven-plugin</artifactId>

12.项目总报告

<artifactId>maven-project-info-reports-plugin</artifactId>

 

=========Maven Common Plugin=========
1.SCP文件传输

<groupId>com.github.goldin</groupId>
<artifactId>copy-maven-plugin</artifactId>

2.SSH命令

<groupId>com.github.goldin</groupId>
<artifactId>sshexec-maven-plugin</artifactId>

3.Maven Job

<groupId>com.github.goldin</groupId>
<artifactId>jenkins-maven-plugin</artifactId>

4.生成about信息

<groupId>com.github.goldin</groupId>
<artifactId>about-maven-plugin</artifactId>

5.查找重复依赖

<groupId>com.github.goldin</groupId>
<artifactId>duplicates-finder-plugin</artifactId>

6.Maven邮件发送

<groupId>com.github.goldin</groupId>
<artifactId>mail-maven-plugin</artifactId>

7.项目目录查找

<groupId>com.github.goldin</groupId>
<artifactId>find-maven-plugin</artifactId>

8.获取SVN版本

<groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
<artifactId>maven-svn-revision-number-plugin</artifactId>

9.编译C++

<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>

10.DDL生成

<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>

11.Eclipse RCP

<groupid>org.sonatype.tycho</groupid>
<artifactid>target-platform-configuration</artifactid>

 

=========Maven Official Plugin=========
1.自动定义打包

<artifactId>maven-assembly-plugin</artifactId>

2.ANT

<artifactId>maven-antrun-plugin</artifactId>

 

=========Maven 全局属性=========
1.源码编码

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
maven.compile.classpath
maven.runtime.classpath
maven.test.classpath
maven.plugin.classpath

2.ClassPath

maven.compile.classpath
maven.runtime.classpath
maven.test.classpath
maven.plugin.classpath

用jetty-runner.jar 运行程序的脚本

先阐述清楚 linux/unix下特性:

一般情况下,每个 Unix/Linux 命令运行时都会打开三个文件:
标准输入文件(stdin):stdin的文件描述符为0,Unix程序默认从stdin读取数据。
标准输出文件(stdout):stdout 的文件描述符为1,Unix程序默认向stdout输出数据。
标准错误文件(stderr):stderr的文件描述符为2,Unix程序会向stderr流中写入错误信息。

有时候,程序刚启动会刷日志到std out(console),很烦的~ 今天根据上面的说明, 优化了一下脚本。

启动脚本

#!/bin/bash
java -Xmx512m -Xms64m -XX:PermSize=256M -XX:MaxPermSize=512M -jar jetty-runner.jar --port 12345 server-0.0.1-SNAPSHOT.war  >/web/program/gw/logs/stdout.log 2>&1 &


echo $! > ./program.pid

启动脚本说明:

1. java – jar 和一些jvm参数
2. jetty-runner.jar 参数
3. 把标准输出、标准错误(1/2) 从定向到/web/program/gw/logs/stdout.log
4. & 后台启动
5. 把程序的pid输出到program.pid

关闭脚本

#!/bin/bash
pkill -F ./program.pid
rm ./program.pid

关闭脚本简单, 就是一个pkill -F 然后删除文件。

小小心得

java -Xmx512m -Xms64m -XX:PermSize=256M -XX:MaxPermSize=512M -jar jetty-runner.jar --port 12345 server-0.0.1-SNAPSHOT.war  >/web/program/gw/logs/stdout.log 2>&1 &

之前是没有上面红色的部分的。问题就是系统启动后,控制台在刷日志, 神烦。 把上面红色的加上, 意思是把标准输出和标准错误都输出到这个文件中。

Google、IBM和Lyft开源的微服务管理框架Istio

本文根据官网的文档整理而成,步骤包括安装istio 0.1.5并创建一个bookinfo的微服务来测试istio的功能。

文中使用的yaml文件可以在kubernetes-handbookmanifests/istio目录中找到,所有的镜像都换成了我的私有镜像仓库地址,请根据官网的镜像自行修改。

安装环境

  • CentOS 7.3.1611
  • Docker 1.12.6
  • Kubernetes 1.6.0

安装

1.下载安装包

下载地址:https://github.com/istio/istio/releases

下载Linux版本的当前最新版安装包

wget https://github.com/istio/istio/releases/download/0.1.5/istio-0.1.5-linux.tar.gz

2.解压

解压后,得到的目录结构如下:

.
├── bin
│   └── istioctl
├── install
│   └── kubernetes
│       ├── addons
│       │   ├── grafana.yaml
│       │   ├── prometheus.yaml
│       │   ├── servicegraph.yaml
│       │   └── zipkin.yaml
│       ├── istio-auth.yaml
│       ├── istio-rbac-alpha.yaml
│       ├── istio-rbac-beta.yaml
│       ├── istio.yaml
│       ├── README.md
│       └── templates
│           ├── istio-auth
│           │   ├── istio-auth-with-cluster-ca.yaml
│           │   ├── istio-cluster-ca.yaml
│           │   ├── istio-egress-auth.yaml
│           │   ├── istio-ingress-auth.yaml
│           │   └── istio-namespace-ca.yaml
│           ├── istio-egress.yaml
│           ├── istio-ingress.yaml
│           ├── istio-manager.yaml
│           └── istio-mixer.yaml
├── istio.VERSION
├── LICENSE
└── samples
    ├── apps
    │   ├── bookinfo
    │   │   ├── bookinfo.yaml
    │   │   ├── cleanup.sh
    │   │   ├── destination-ratings-test-delay.yaml
    │   │   ├── loadbalancing-policy-reviews.yaml
    │   │   ├── mixer-rule-additional-telemetry.yaml
    │   │   ├── mixer-rule-empty-rule.yaml
    │   │   ├── mixer-rule-ratings-denial.yaml
    │   │   ├── mixer-rule-ratings-ratelimit.yaml
    │   │   ├── README.md
    │   │   ├── route-rule-all-v1.yaml
    │   │   ├── route-rule-delay.yaml
    │   │   ├── route-rule-reviews-50-v3.yaml
    │   │   ├── route-rule-reviews-test-v2.yaml
    │   │   ├── route-rule-reviews-v2-v3.yaml
    │   │   └── route-rule-reviews-v3.yaml
    │   ├── httpbin
    │   │   ├── httpbin.yaml
    │   │   └── README.md
    │   └── sleep
    │       ├── README.md
    │       └── sleep.yaml
    └── README.md

11 directories, 41 files

从文件里表中可以看到,安装包中包括了kubernetes的yaml文件,示例应用和安装模板。

3.安装istioctl

./bin/istioctl拷贝到你的$PATH目录下。

4.检查RBAC

因为我们安装的kuberentes版本是1.6.0默认支持RBAC,这一步可以跳过。如果你使用的其他版本的kubernetes,请参考官方文档操作。

执行以下命令,正确的输出是这样的:

$ kubectl api-versions | grep rbac
rbac.authorization.k8s.io/v1alpha1
rbac.authorization.k8s.io/v1beta1

5.创建角色绑定

$ kubectl create -f install/kubernetes/istio-rbac-beta.yaml
clusterrole "istio-manager" created
clusterrole "istio-ca" created
clusterrole "istio-sidecar" created
clusterrolebinding "istio-manager-admin-role-binding" created
clusterrolebinding "istio-ca-role-binding" created
clusterrolebinding "istio-ingress-admin-role-binding" created
clusterrolebinding "istio-sidecar-role-binding" created

注意:官网的安装包中的该文件中存在RoleBinding错误,应该是集群级别的clusterrolebinding,而release里的代码只是普通的rolebinding,查看该Issue Istio manager cannot list of create k8s TPR when RBAC enabled #327

6.安装istio核心组件

用到的镜像有:

docker.io/istio/mixer:0.1.5
docker.io/istio/manager:0.1.5
docker.io/istio/proxy_debug:0.1.5

我们暂时不开启Istio Auth

注意:本文中用到的所有yaml文件中的type: LoadBalancer去掉,使用默认的ClusterIP,然后配置Traefik ingress,就可以在集群外部访问。请参考安装Traefik ingress

kubectl apply -f install/kubernetes/istio.yaml

7.安装监控插件

用到的镜像有:

docker.io/istio/grafana:0.1.5
quay.io/coreos/prometheus:v1.1.1
gcr.io/istio-testing/servicegraph:latest
docker.io/openzipkin/zipkin:latest

为了方便下载,其中两个镜像我备份到了时速云:

index.tenxcloud.com/jimmy/prometheus:v1.1.1
index.tenxcloud.com/jimmy/servicegraph:latest

安装插件

kubectl apply -f install/kubernetes/addons/prometheus.yaml
kubectl apply -f install/kubernetes/addons/grafana.yaml
kubectl apply -f install/kubernetes/addons/servicegraph.yaml
kubectl apply -f install/kubernetes/addons/zipkin.yaml

在traefik ingress中增加增加以上几个服务的配置,同时增加istio-ingress配置。

    - host: grafana.istio.io
      http:
        paths:
        - path: /
          backend:
            serviceName: grafana
            servicePort: 3000
    - host: servicegraph.istio.io
      http:
        paths:
        - path: /
          backend:
            serviceName: servicegraph
            servicePort: 8088
    - host: prometheus.istio.io
      http:
        paths:
        - path: /
          backend:
            serviceName: prometheus
            servicePort: 9090
    - host: zipkin.istio.io
      http:
        paths:
        - path: /
          backend:
            serviceName: zipkin
            servicePort: 9411
    - host: ingress.istio.io
      http:
        paths:
        - path: /
          backend:
            serviceName: istio-ingress
            servicePort: 80

测试

我们使用Istio提供的测试应用bookinfo微服务来进行测试。

该微服务用到的镜像有:

istio/examples-bookinfo-details-v1
istio/examples-bookinfo-ratings-v1
istio/examples-bookinfo-reviews-v1
istio/examples-bookinfo-reviews-v2
istio/examples-bookinfo-reviews-v3
istio/examples-bookinfo-productpage-v1

该应用架构图如下:

BookInfo Sample应用架构图

部署应用

kubectl create -f <(istioctl kube-inject -f samples/apps/bookinfo/bookinfo.yaml)

Istio kube-inject命令会在bookinfo.yaml文件中增加Envoy sidecar信息。参考 istio 文档

在本机的/etc/hosts下增加VIP节点和ingress.istio.io的对应信息。具体步骤参考:边缘节点配置

在浏览器中访问http://ingress.istio.io/productpage

监控

不断刷新productpage页面,将可以在以下几个监控中看到如下界面。

Grafana页面

http://grafana.istio.io

Istio Grafana界面

Prometheus页面

http://prometheus.istio.io

Prometheus页面

Zipkin页面

http://zipkin.istio.io

Zipkin页面

ServiceGraph页面

http://servicegraph.istio.io/dotviz

可以用来查看服务间的依赖关系。

获得json格式的返回结果,访问http://servicegraph.istio.io/graph

ServiceGraph页面

OSI七层协议模型、TCP/IP四层模型

1. OSI七层和TCP/IP四层的关系

1.1 OSI引入了服务、接口、协议、分层的概念,TCP/IP借鉴了OSI的这些概念建立TCP/IP模型。

1.2 OSI先有模型,后有协议,先有标准,后进行实践;而TCP/IP则相反,先有协议和应用再提出了模型,且是参照的OSI模型。

1.3 OSI是一种理论下的模型,而TCP/IP已被广泛使用,成为网络互联事实上的标准。

TCP:transmission control protocol 传输控制协议

UDP:user data protocol 用户数据报协议

 

OSI七层网络模型

TCP/IP四层概念模型

对应网络协议

应用层(Application) 应用层 HTTP、TFTP, FTP, NFS, WAIS、SMTP
表示层(Presentation) Telnet, Rlogin, SNMP, Gopher
会话层(Session) SMTP, DNS
传输层(Transport) 传输层 TCP, UDP
网络层(Network) 网络层 IP, ICMP, ARP, RARP, AKP, UUCP
数据链路层(Data Link) 数据链路层 FDDI, Ethernet, Arpanet, PDN, SLIP, PPP
物理层(Physical) IEEE 802.1A, IEEE 802.2到IEEE 802.11

 

 

2. OSI七层协议模型

七层结构记忆方法:应、表、会、传、网、数、物

应用层协议需要掌握的是:HTTP(Hyper text transfer protocol)、FTP(file transfer protocol)、SMTP(simple mail transfer rotocol)、POP3(post office protocol 3)、IMAP4(Internet mail access protocol)

 

3. TCP/IP四层模型

3.1 应用层:对应OSI中的应用层、表示层、会话层

3.2 物理链路层:对应OSI中的数据链路层、物理层(也有叫网络接口层)

3.3 数据包说明:

IP层传输单位是IP分组,属于点到点的传输;TCP层传输单位是TCP段,属于端到端的传输

 

markdown + pandoc 生成 docx / pdf

Why

经常写文档, 但是又想要一种简单的方法, 我选择了markdown.
但是有时候写的文档要发布, 里面有一些图片, 直接生成pdf效果并不好, 特别是分页不好弄
分页和图片的排版还是在docx里面弄方便~~

Environment

windows + Typora + pandoc

Tools

  • Typora
    我用过的最好用的markdown编辑器,支持windows, mac, Typora 本身支持转换pdf..
  • pandoc
    实用全能的文档转换工具, markdown转换docx的工具

为了使用方便, pandoc安装好之后把他的安装路径添加到环境变量里面, 添加好之后用下面的方法测试

xsu@xsu MINGW64 /e/net/www/pic
$ pandoc -v
pandoc.exe 1.17.0.2

Step

pandoc的功能很多, 我只取我所常用的

markdown转换为docx

最简单例子

pandoc -s m.md -o m.docx

但是打开生成的docx一看, 我去, 丑到爆

看官别慌请接着看

使用reference文件

reference文件可以docx, 也可以是css,具体请细看Pandoc User’s Guide

docx

下载我提供的reference-docx文件

reference.docx 链接:http://pan.baidu.com/s/1jHHuIJ8 密码:2a4i
放到你要转换的md文件的同一级目录

pandoc -s m.md -o m.docx -c reference.docx

或者

pandoc -s m.md -S --reference-docx reference.docx -o m.docx

当然你也可以把reference.docx放到data-dir, 就可以省略-c reference.docx

mkdir %userprofile%/AppData/Roaming/pandoc
move reference.docx %userprofile%/AppData/Roaming/pandoc/reference.docx
pandoc -s m.md -o m.docx

其效果如下

如果不满意可自行修改样式

css

pandoc -s m.md -o m.docx -c github.css

github.css我就不提供文件, 请在Typora的安装目录下的resources\app\style\themes 查找或者自己搜索

常见问题

pandoc.exe: user error (word/numbering.xml missing in reference docx)

解决思路: 找到把丢失的numbering放到word目录下

解决办法: 打开github.com/jgm/pandoc/tree/master/data/docx/word

把里面numbering.xml下载下来, 把我们的自己的reference.docx改名为reference.zip,用压缩软件的打开, 放到word/目录下, 再 把reference.zip改为reference.docx

参考: