JoyLau's Blog

JoyLau 的技术学习与思考

配置

1
2
3
4
5
6
7
{
"log-opts": {
"max-size": "100m"
},
"data-root": "/data/docker-data",
"dns": ["192.168.1.17","223.5.5.5"]
}

配置上面的 dns 配置,对所有的容器生效

我在本地用 docker 部署了一个 webmin 服务,其中 bind 可以用来做DNS 服务
启动docker 容器后发现,不能通过 192.168.1.17 来解析域名
解决办法是 webmin 的服务使用 host 网络即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
version: "3"
services:
dns-server:
image: sameersbn/bind:9.16.1-20200524
container_name: dns-server
restart: always
volumes:
- ./data:/data
network_mode: "host"
#ports:
# - 53:53/udp
# - 10000:10000
environment:
- ROOT_PASSWORD=xxxx
- WEBMIN_INIT_SSL_ENABLED=false

更新一个更简单的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
version: "3"
services:
dns-server:
image: cytopia/bind:stable-manifest-linux-arm64
container_name: dns-server
restart: always
ports:
- 53:53/udp
volumes:
- ./named.conf.local:/etc/bind/named.conf.local:ro
- ./custom-hosts:/etc/bind/custom-hosts:ro
environment:
- DEBUG=1
- DEBUG_ENTRYPOINT=2
- DOCKER_LOGS=1
- ALLOW_QUERY=any
- ALLOW_RECURSION=none
# 下面的配置会追加了 .rpz.触发名变成了 package.zksd.com.rpz. 不能使用
#- DNS_A=im.jiangs.jy.gov.cn=10.110.100.137,package.zksd.com=170.168.113.71

named.conf.local:

1
2
3
4
5
6
7
8
9
zone "zksd.com" {
type master;
file "/etc/bind/custom-hosts/db.zksd.com";
};

zone "jiangs.jy.gov.cn" {
type master;
file "/etc/bind/custom-hosts/db.jiangs.jy.gov.cn";
};

db.zksd.com:

1
2
3
4
5
6
7
$TTL 3600
@ IN SOA ns.local. admin.local. ( 2026110601 3600 600 86400 3600 )
@ IN NS ns.local.

package IN A 170.168.113.71
shengju IN A 170.168.113.71

这个服务的作用是:封闭内网,只解析这几个域名,彻底不查上游

如果需要 只想覆盖这几个名字,其余域名仍要能正常解析
需要配置环境变量

- ALLOW_RECURSION=any # 递归开着,未覆盖的名字才会转发到 10.1.8.8
- DNS_FORWARDER=10.1.8.8

named.conf.local(zone 名=完整 FQDN)

1
2
3
4
5
6
7
8
zone "package.zksd.com" {
type master;
file "/etc/bind/custom-hosts/db.package.zksd.com";
};
zone "im.jiangs.jy.gov.cn" {
type master;
file "/etc/bind/custom-hosts/db.im.jiangs.jy.gov.cn";
};

db.package.zksd.com(@ 就是 zone 顶点 package.zksd.com)

1
2
3
4
$TTL 3600
@ IN SOA ns.local. admin.local. ( 2026110601 3600 600 86400 3600 )
@ IN NS ns.local.
@ IN A 170.168.113.71

复现

实体类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@Getter
@Setter
@TableName(autoResultMap = true)
public class AdapterManager implements Serializable {
@Serial
private static final long serialVersionUID = 3254095985232547523L;

/**
* id。
*/
@TableId(type = IdType.AUTO)
private Integer id;

/**
* 测试意向申请。
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<Attachment> letterIntent;
}

更新代码:

1
2
3
4
adapterManagerMapper.update(null, Wrappers.lambdaUpdate(AdapterManager.class)
.eq(AdapterManager::getId, aid)
.set(AdapterManager::getLetterIntent, list)
);

在使用 lambdaUpdate 无法更新字段, 会报错 Caused by: java.io.NotSerializableException: xxxxxx.Attachment

阅读全文 »

引入依赖

RestClient 默认 requestFactory 使用的是 JdkClientHttpRequestFactory, 没有日志功能
这里需要切换为 HttpComponentsClientHttpRequestFactory

1
2
3
4
5
<!-- 新版 restClient 使用-->
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>

配置类

这里我额外加入了 Base 认证和一个 json 的消息转换器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Bean
public RestClient mqttApiRestClient(ObjectMapper objectMapper) {
String auth = mqttProperties.getRest().getApiKey() + ":" + mqttProperties.getRest().getSecretKey();
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.UTF_8));
String header = "Basic " + new String(encodedAuth);
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setConnectTimeout(3000);
factory.setConnectionRequestTimeout(5000);
return RestClient.builder()
.requestFactory(factory)
.messageConverters(httpMessageConverters -> httpMessageConverters.add(4,
new MappingJackson2HttpMessageConverter(objectMapper)))
.baseUrl(mqttProperties.getRest().getApi())
.defaultHeader("Authorization", header)
.build();
}

日志配置

1
2
3
4
logging:
level:
# restClient 日志打印
org.apache.hc.client5.http.wire: debug

操作

  1. 打开 Internet协议版本4(TCP/IPv4) 的属性
  2. 设置 高级中的 “接口跃点数”, 值越小 优先级越高
0%