BlueXIII's Blog

热爱技术,持续学习

0%

简介

Angular开发过程中,Debug方式大概有如下3种:

  • Chrome DevTools - Chrome自带开发工具
  • Augury插件 - Angular官方Chrome插件
  • JetBrains内置工具 - IDEA/WebStorm内置Debug工具,需要安装Chrome插件

Chrome DevTools

启动

F12Cmd+Option+I调出DevTools

使用

使用ng serve启动前端Server时,默认开发模式,会提供sourcemap,直接在Srource选项卡中,找到相应的源码,可以断点调试
2020-02-18-16-50-23

其它关于DevTools用法不再赘述


Augury插件

安装Chrome插件

https://chrome.google.com/webstore/detail/augury/elgalmkoelokbchhkhacckoklkejnhcd

安装后,在ChromeDevTool中,会多出一个名为Augury选项卡

Component Tree

查看组件树
2020-02-18-16-41-40

在此界面还可以查看属性、方法、依赖注入等信息

Route Tree

查看路由
2020-02-18-16-42-59

Ng Modules

查看模块信息
2020-02-18-16-43-29


JetBrains内置工具

安装Chrome插件

首先需要安装Chrome插件:
https://chrome.google.com/webstore/detail/jetbrains-ide-support/hmhgeddbohgjknpmjagkdomcpobmllji

配置IDE Debug选项

IDE右上角点击Edit Configurations
2020-02-18-16-34-51

点击左上角+,添加一个JavaScript Debug选项,URL中输入http://localhost:4200
2020-02-18-16-36-06

运行ng serve

在console中执行npm run hmr,启动前端Server

运行IDEA Debug工具

点击右上角DEBUG图标,启动IDEA的Debug工具
2020-02-18-16-38-07

启动后,会连接到4200端口,IDEA的DEBUG区域会显示Console/Script等信息
2020-02-18-16-38-46

断点调试

直接在IDEA源码中,左侧单击打断点即可
2020-02-18-16-41-16

Sonar地址

http://localhost:9000

admin/admin
暂定localhost,后期根据部署情况修改

本机Maven配置

配置~/.m2/settings.xml

1
2
3
4
5
6
7
8
9
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>http://localhost:9000</sonar.host.url>
</properties>
</profile>

为工程添加Jacoco插件

配置工程的pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<project>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

注意将surefire插件的skipTests选项关闭:

1
2
3
4
5
6
7
8
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<!-- <configuration> -->
<!-- <skipTests>true</skipTests> -->
<!-- </configuration> -->
</plugin>

代码手工上传Sonar

1
mvn clean verify sonar:sonar

Sonar代码检查结果

上传Sonar后,会生成代码质量检查报告
2020-02-07-19-34-54

点击链接即可查看
2020-02-07-19-44-56

页面中会展示代码的BUG、漏洞、单元测试覆盖率、代码重复率等信息,可点击进入详情页面,Sonar会给出详细的修改建议,根据提示修改代码。
2020-02-07-19-36-05

整合springfox

修改父pom

添加springfox的依赖:

1
2
3
4
5
6
7
8
9
10
11
12
<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

增加spring配置

新增配置类SwaggerConfiguration.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket getDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("swagger-demo")
.description("demo")
.version("1.0.0")
.build())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/.*"))
.build();
}
}

相关路径

编码示例

Domain层

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@ApiModel("附件信息")
public class Attachment {
@ApiModelProperty(value = "附件ID", example = "1")
private String id = PublicUtils.uuid();

@ApiModelProperty(value = "附件名称", example = "1.docx")
private String name;

@ApiModelProperty(value = "附件类型", example = "text/plain")
private String genre;

@ApiModelProperty(value = "附件路径", example = "/tmp/1.docx")
private String path;

@ApiModelProperty(value = "附件大小", example = "100")
private double size;
}

Controller层

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@Api("附件管理")
@RestController
@RequestMapping("/attachment")
public class AttachmentController {
@Autowired
private AttachmentService service;

@ApiOperation("保存附件")
@PostMapping
public RestResponse save(@ApiParam("附件信息") @RequestBody Attachment attachment) {
service.save(attachment);
return RestResponse.result(attachment);
}

@ApiOperation("删除附件")
@DeleteMapping("/{id}")
public RestResponse delete(@ApiParam(value = "附件ID", example = "1") @PathVariable String id) {
service.delete(id);
return RestResponse.result(id);
}

@ApiOperation("查询附件")
@GetMapping
public RestResponse query(@ApiParam(value = "附件名称", example = "1.docx") @RequestParam(required = false) String name,
@ApiParam(value = "页数", example = "1") @RequestParam(required = false, defaultValue = "0") int pageNum,
@ApiParam(value = "每页条数", example = "10") @RequestParam(required = false, defaultValue = "10") int pageSize) {
PageInfo<Attachment> page = service.query(name, pageNum, pageSize);
return RestResponse.result(page);
}
}

注意事项

  1. 常用注解有@Api, @ApiOperation, @ApiParam, @ApiModelProperty
  2. @Produces, @ApiResponses受制于框架暂不使用,接口风格尽量向rest靠拢
  3. 尽量在注解中添加example属性,以方便后期在swagger-ui中做手工接口测试
  4. 注解在一定程度上可以替代/**/注释,具体看公司要求

swagge-ui

查看API信息

浏览器访问http://localhost:8090/zorrodemo/swagger-ui.html,打开swagger-ui的界面,可查看所有API的信息
2020-02-07-15-11-35

API测试验证

点击Try it out按钮,可对单个接口手工进行测试
2020-02-07-15-14-22

文档生成

  1. 通过swagger的原始描述json,可以使用各种工具生成多种格式的API文档(asciidoc/pdf/html/markdonwn)
  2. json api-docs的路径为: http://localhost:8090/zorrodemo/v2/api-docs
  3. 建议使用swagger-markdown工具生成markdown格式文档,方便后期格式转换、导出

介绍页面:
https://www.npmjs.com/package/swagger-markdown

安装及使用:

1
2
npm install -g swagger-markdown
swagger-markdown -i ./api-docs.json

主机

uat-master01.yourcompany.com 10.10.51.78 K8S主节点

步骤

1
2
3
4
5
6
7
8
9
10
# 创建命名空间
kubectl create namespace cale

# 部署应用
kubectl delete -k .
kubectl apply -k .

# 查看pod状态
kubectl get pods -n cale -o wide

yml配置

配置文件详见FTP install目录

某曙光服务器,在主板CMOS电池掉电后,NVRAM信息丢失。重新开机后,无法自动从SATA0硬盘的EFI分区的/EFI/boot/bootx64.efi进行引导。需要用启动盘进入恢复模式,将引导项重新写入NVRAM。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 挂EFI分区,已经进入系统时则不需要
fdisk -l /dev/sda
mount /dev/sda1 /boot/efi/

# 查看引导项
efibootmgr -v

# 删除引导项
efibootmgr -b 0001 -B

# 添加引导项
efibootmgr -c -d /dev/sda -p 1 -l '\EFI\centos\grubx64.efi' -L CentOS
efibootmgr -c -d /dev/sda -p 1 -l '\EFI\debian\grubx64.efi' -L Debian
-c 创建引导项
-d 选择硬盘
–p 选择分区
-l efi文件路径
-L 引导项标签

参考文档

macOS下brew方式安装

1
2
3
4
5
6
7
8
9
10
# 安装unixodbc
brew install unixodbc

# 查看配置文件位置
odbcinst -j
unixODBC 2.3.7
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /Users/yourname/.odbc.ini

OdbcManager图形界面

http://www.odbcmanager.net/

postgres驱动

https://odbc.postgresql.org/
https://blogs.sap.com/2015/01/22/%E6%80%8E%E6%A0%B7%E5%9C%A8linux%E4%B8%AD%E9%85%8D%E7%BD%AEpostgre-sql-odbc%E8%BF%9E%E6%8E%A5/

1
2
3
4
# 源码编译安装
./configure
make && make install

odbcinst.ini配置

1
2
3
4
5
6
7
[PostgreSQL]
Description = ODBC for PostgreSQL
Driver = /usr/local/lib/psqlodbcw.so
Setup = /usr/local/lib/psqlodbca.so
Driver64 = /usr/local/lib/psqlodbcw.so
Setup64 = /usr/local/lib/psqlodbca.so
FileUsage = 1

odbc.ini配置

1
2
3
4
5
6
7
8
9
10
[PostgreSQL35W]
Description = Test to pg
Driver = PostgreSQL
Database = gbdb
Servername = 127.0.0.1
UserName = postgres
Password = postgres
Port = 5432
ReadOnly = 0
ConnSettings = set client_encoding to UTF8

配置DNS

1
2
3
4
5
6
vi /etc/hosts
# 本地虚拟机
10.10.50.204 registry.yourcompany.com

# 离线环境
10.10.51.77 registry.yourcompany.com

配置Docker允许HTTP

1
2
vi /etc/docker/daemon.json
{ "insecure-registries":["registry.yourcompany.com:5000"] }

镜像导出脚本

repo_save.sh

1
2
3
4
5
6
7
8
images=(
tomcat/tomcat-oraclejdk8:8.5.50
)

for imageName in ${images[@]} ; do
docker pull registry.yourcompany.com:5000/$imageName
docker save registry.yourcompany.com:5000/$imageName > $imageName.tar
done

镜像导入脚本

repo_load.sh

1
2
3
4
5
6
7
8
images=(
tomcat/tomcat-oraclejdk8:8.5.50
)

for imageName in ${images[@]} ; do
docker load < $imageName.tar
docker push registry.yourcompany.com:5000/$imageName
done

手工导出导入

1
2
3
4
5
6
7
# 导出
docker pull registry.yourcompany.com:5000/yourimage:2.2.0
docker save registry.yourcompany.com:5000/yourimage:2.2.0 > yourimage:2.2.0.tar

# 导入
docker load < yourimage:2.2.0.tar
docker push registry.yourcompany.com:5000/yourimage:2.2.0

下载yml

https://github.com/kubernetes/ingress-nginx/tree/ingress-nginx-3.3.0/deploy/static/provider/baremetal

下载镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 在线环境
docker pull k8s.gcr.io/ingress-nginx/controller:v0.35.0
docker pull docker.io/jettech/kube-webhook-certgen:v1.3.0

docker tag k8s.gcr.io/ingress-nginx/controller:v0.35.0 registry.yourcompany.com:5000/ingress-nginx/controller:v0.35.0
docker tag docker.io/jettech/kube-webhook-certgen:v1.3.0 registry.yourcompany.com:5000/jettech/kube-webhook-certgen:v1.3.0

docker save -o controller:v0.35.0.tar registry.yourcompany.com:5000/ingress-nginx/controller:v0.35.0
docker save -o kube-webhook-certgen:v1.3.0.tar registry.yourcompany.com:5000/jettech/kube-webhook-certgen:v1.3.0

# 离线环境
docker load -i controller:v0.35.0.tar
docker load -i kube-webhook-certgen:v1.3.0.tar

docker push registry.yourcompany.com:5000/ingress-nginx/controller:v0.35.0
docker push registry.yourcompany.com:5000/jettech/kube-webhook-certgen:v1.3.0

修改yml

1
2
image: registry.yourcompany.com:5000/ingress-nginx/controller:v0.35.0
image: registry.yourcompany.com:5000/jettech/kube-webhook-certgen:v1.3.0

部署

1
2
kubectl label node uat-worker01.yourcompany.com isIngress="true"
kubectl apply -f deploy.yaml

测试

http://test.ingress.com/ip

下载镜像

1
2
3
4
5
6
7
8
# 联网环境
docker pull quay.io/external_storage/nfs-client-provisioner:latest
docker save -o nfs-client-provisioner.tar quay.io/external_storage/nfs-client-provisioner

# 离线环境
docker load -i nfs-client-provisioner.tar
docker tag quay.io/external_storage/nfs-client-provisioner registry.yourcompany.com:5000/external_storage/nfs-client-provisioner
docker push registry.yourcompany.com:5000/external_storage/nfs-client-provisioner

部署

1
2
3
4
5
# 配置文件详见FTP目录
kubectl create namespace nfs-client
kubectl apply -f rbac.yaml
kubectl apply -f class.yaml
kubectl apply -f deployment.yaml

参考文档

下载地址

https://github.com/kubernetes/dashboard/releases

下载yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 在线环境,下载yml
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.4/aio/deploy/recommended.yaml

# 将Service修改为NodePort类型
spec:
type: NodePort
ports:
- port: 443
nodePort: 30443
targetPort: 8443

# 注释掉imagePullPolicy
imagePullPolicy: Always

# 在线环境,下载镜像
docker pull kubernetesui/dashboard:v2.0.4
docker pull kubernetesui/metrics-scraper:v1.0.4
docker save kubernetesui/dashboard:v2.0.4 > dashboard_v2.0.4.tar
docker save kubernetesui/metrics-scraper:v1.0.4 > metrics-scraper_v1.0.4.tar

# 离线环境,导入镜像
docker load < dashboard_v2.0.4.tar
docker load < metrics-scraper_v1.0.4.tar

# 创建自签名CA
openssl genrsa -out ca.key 2048
openssl req -new -x509 -key ca.key -out ca.crt -days 3650 -subj "/C=CN/ST=HB/L=WH/O=DM/OU=YPT/CN=CA"
openssl x509 -in ca.crt -noout -text

# 签发Dashboard证书
openssl genrsa -out dashboard.key 2048
openssl req -new -sha256 -key dashboard.key -out dashboard.csr -subj "/C=CN/ST=HB/L=WH/O=DM/OU=YPT/CN=yourcompany"
cat <<EOF > dashboard.cnf
extensions = san
[san]
keyUsage = digitalSignature
extendedKeyUsage = clientAuth,serverAuth
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
subjectAltName = IP:10.10.51.78,DNS:yourcompany.com
EOF
openssl x509 -req -sha256 -days 3650 -in dashboard.csr -out dashboard.crt -CA ca.crt -CAkey ca.key -CAcreateserial -extfile dashboard.cnf
openssl x509 -in dashboard.crt -noout -text

# 挂载证书
kubectl create namespace kubernetes-dashboard
kubectl delete secret kubernetes-dashboard-certs --namespace=kubernetes-dashboard
kubectl create secret generic kubernetes-dashboard-certs --from-file="./dashboard.crt,./dashboard.key" -n kubernetes-dashboard

# 离线环境,部署dashboard
kubectl delete -f recommended.yaml
kubectl apply -f recommended.yaml
kubectl get pods -n kubernetes-dashboard

# 生成token
kubectl create serviceaccount dashboard-admin-sa
kubectl create clusterrolebinding dashboard-admin-sa --clusterrole=cluster-admin --serviceaccount=default:dashboard-admin-sa
kubectl get secrets
kubectl describe secret dashboard-admin-sa-token-5sb8s

# 浏览器访问
https://10.10.51.78:30443

参考文档