JoyLau's Blog

JoyLau 的技术学习与思考

背景

使用 docker run -p 或者 docker compose 启动暴露的端口的容器, 会直接穿透防火墙, 不受系统防火墙的 firewalld 的管控

原因

docker 容器会在启动的时候向 iptables 添加转发的规则
而 firewalld 也是通过操作 iptables 来实现的防火墙的功能

1
2
3
4
5
6
7
[root@centOS7 es-test]# iptables -L DOCKER
Chain DOCKER (3 references)
target prot opt source destination
ACCEPT tcp -- anywhere 172.18.0.2 tcp dpt:xic
ACCEPT tcp -- anywhere 172.20.0.2 tcp dpt:vrace
ACCEPT tcp -- anywhere 172.20.0.2 tcp dpt:wap-wsp

可以看到是 anywhere

解决方式

第一种 禁用 docker 操作 iptables

在 /etc/docker/daemon.json 配置禁用 iptables:

1
2
{"iptables": false}

之后重启 docker 服务, 可以看到 docker 不会自动往 iptables 里添加规则了

这种方式有个弊端: 就是容器之间无法互相访问, 而且容器里的程序也无法访问外部网络

解决方式:
在防火墙里开始 net 转发:

配置 /etc/firewalld/zones/public.xml

1
2
3
4
5
6
7
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="ssh"/>
<service name="dhcpv6-client"/>
<masquerade/>
</zone>

或者使用下面的方式添加 iptables 规则

1
firewall-cmd --zone=public --add-masquerade

之后使用 firewall-cmd –restart 或者 systemctl restart firewalld 使配置生效即可

但是这样做还有个问题, 就是所有访问容器的程序对于容器来说 IP 的变成的网关的 IP
这样的问题对于一些需要特定限制一些 IP 地址来源的应用和使用 IP 地址来作区分的应用来说就有很大问题, 比如注册中心
目前没有找到什么方式解决这个问题

第二种 容器直接指定主机网络

docker run 的时候不显式暴露端口 -p 什么的, 使用 –net host 的形式直接将容器的端口绑定到宿主机上

docker compose 运行的时候使用:

1
2
3
4
version:  '3.2'
services:
abc:
network_mode: "host"

Maven 私服 Nexus3 因磁盘爆满而导致的无法启动的问题

背景

同事在 Nexus3 私服的宿主机上部署了一个服务, 结果因为网络问题导致服务打印大量的日志信息, 将宿主机的磁盘撑爆了,经过一系列排除, 删除了大日志文件
重启 Nexus3 容器,发现无法启动了, 报错如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
com.orientechnologies.orient.core.exception.OStorageException: Cannot open local storage '/nexus-data/db/config' with mode=rw
DB name="config"
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:323)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:259)
at org.sonatype.nexus.orient.DatabaseManagerSupport.connect(DatabaseManagerSupport.java:178)
at org.sonatype.nexus.orient.DatabaseManagerSupport.createInstance(DatabaseManagerSupport.java:312)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
at org.sonatype.nexus.orient.DatabaseManagerSupport.instance(DatabaseManagerSupport.java:289)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)
Caused by: java.lang.NullPointerException: null
at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog.cutTill(ODiskWriteAheadLog.java:919)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.makeFullCheckpoint(OAbstractPaginatedStorage.java:3706)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.recoverIfNeeded(OAbstractPaginatedStorage.java:3937)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:288)
... 14 common frames omitted

解决

  1. 进入宿主机存放 Nexus3 数据目录下

先对该目录分配用户和用户组:

1
chown -R 200 /home/transport/maven-repos-data

分别删除 db/config 目录下和 db/component 目录下的所有的 .wal 文件

1
2
3
4
5
6
7
cd /home/transport/maven-repos-data/db/config

rm -rf *.wal

cd /home/transport/maven-repos-data/db/component

rm -rf *.wal
  1. 找到容器中的 nexus-orient-console.jar jar 包
1
find / -name nexus-orient-console.jar

进入上述目录, 我这里是: /var/lib/docker/overlay2/3b9c8d7685a03dcbb9ee69c33cd8fd9b487d980731596da27e7639854c0bb6e1/diff/opt/sonatype/nexus/lib/support

执行 java -jar nexus-orient-console.jar , 来连接数据库

1
connect plocal:/home/transport/maven-repos-data/db/component admin admin

执行下列命令进行修复, 修复完成并退出:

1
2
3
4
5
6
7
rebuild index *

repair database --fix-links

disconnect

exit
  1. 数据目录重新授权
1
chmod 777 -R /home/transport/maven-repos-data/db
  1. 重启容器

Maven 私服 Nexus3 忘记 admin 用户密码的解决

如上述步骤描述的, 运行 nexus-orient-console.jar

进入 security 数据库:

1
connect plocal:/home/transport/maven-repos-data/db/security admin admin

将 admin 用户密码重置为 admin123

1
update user SET password="$shiro1$SHA-512$1024$NE+wqQq/TmjZMvfI7ENh/g==$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==" UPSERT WHERE id="admin"

数据目录重新授权

1
chmod 777 -R /home/transport/maven-repos-data/db

清理 brew

  1. brew cleanup
  2. brew cleanup –prune 1 #清理早于 1 天的

防止 mac 锁屏后关闭显示器的方法

brew cask install keepingyouawake

zsh 对 docker 命令的自动提示

  1. 首先确定安装好了 oh-my-zsh
  2. 在文件 ~/.zshrc 文件中启用 docker docker-compose, 下面是我启用的插件

参考: https://docs.docker.com/compose/completion/

1
plugins=(git gradle mvn node npm brew yarn docker docker-compose)

zsh 插件推荐

  1. 自动补全插件 zsh-autosuggestions

这里利用Oh my zsh的方法安装。直接一句话命令行里下载并移动到 oh my zsh 目录中:

1
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

然后在 ~/.zshrc 文件中找到 plugins 数组,加入 zsh-autosuggestions 名字,重新打开终端即可。

  1. 语法高亮插件 zsh-syntax-highlighting

将插件下载到oh my zsh的插件目录下的该新建插件同名文件夹中

1
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

编辑 ~/.zshrc 文件将然后将插件引用命令写入该文件最后一行(必须)

1
source "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"

保存重新打开即可看到高亮的命令行了。

简介

组装一台黑苹果最重要的是硬件的选择, 选择的重点是尽量选择与白苹果一致的配件
在硬件选择的方面有几点需要特别的注意

  1. CPU 的选择,CPU尽量选择 Intel 的,7/8/9代 酷睿 i9,i7,i5,i3 都可以, AMD 的CPU 也不是不行, 只不过需要打补丁,折腾的东西比较多
  2. 显卡的选择, 白苹果的显卡都是 A 卡, 所以在显卡的选择上直接选择 A 卡即可, 选择 A 卡需要注意的是,直接选择免驱动的 A 卡类型, 首选蓝宝石和微星的,下面列举了一些免驱的 A 卡
  • Vega FE (真正免驱,无需搭配集显也可完全硬件加速)
  • Vega 64 (真正免驱,无需搭配集显也可完全硬件加速)
  • Vega 56 (真正免驱,无需搭配集显也可完全硬件加速)
  • Vega Nano (真正免驱,无需搭配集显也可完全硬件加速)
  • Pro SSG (真正免驱,无需搭配集显也可完全硬件加速)
  • WX 9100 (真正免驱,无需搭配集显也可完全硬件加速)
  • WX 8200 (真正免驱,无需搭配集显也可完全硬件加速)
  • RX 590
  • RX 580 (注意,缩水的阉割版2048SP的RX580马甲卡不是免驱的,标准2304SP才是免驱卡)
  • RX 570
  • RX 560 (个别型号的HDMI/DVI输出黑屏,需要改FB,DP输出没问题)
  1. 主板的选择,华硕,微星,技嘉 的 主板推荐选择, 8/9代酷睿首选Z390/Z370芯片组
  2. 硬盘的选择,三星 970 EVO Plus 和 三星 PM981 无法做为macOS系统盘安装原版,不要选择
  3. 显示器的选择,首选 4K 显示器,2K 以下的显示器需要开启 HiDPI,而且使用体验不好
  4. 无线网卡和蓝牙的选择,主板自带的WI-FI和蓝牙目前都无法驱动, 这个无解, 推荐免驱的 BCM94360CD 或者 BCM943602CS,直接插上即可使用

配置

先贴出我本次的黑苹果主机的配置信息, 如下:

项目 型号 价格 链接
CPU Intel i9-9900K 8核16线程 盒装CPU 2899 https://item.jd.com/100000634429.html
主板 技嘉(GIGABYTE)Z390 AORUS PRO WIFI 956 https://item.jd.com/100000612305.html
内存 金士顿(Kingston) DDR4 3200频 128GB(32G×4) 4409 https://item.jd.com/100008221061.html
硬盘 三星970 EVO 1TB M.2接口(NVMe) 1087 https://item.jd.com/7234468.html
显卡 蓝宝石 RX 580 2304sp 8G 满血版 (淘宝二手) 1238 https://item.taobao.com/item.htm?spm=a1z09.2.0.0.661e2e8d5l686T&id=614820302674&_u=425lenq48296
散热器 九州风神大霜塔 179 https://item.jd.com/689273.html
电源 长城 750W 全模组金牌电源 490 https://item.jd.com/8025804.html
显示器 戴尔 U2720QM 27英寸4K 3468 https://item.jd.com/100011317048.html
无线网卡 BCM94360CD 265 https://item.jd.com/10021401339167.html
鼠标 罗技 MX Master 3 for Mac 668 https://item.jd.com/100014681386.html
键盘 Keychron K6蓝牙双模机械键盘 青轴 327 https://item.jd.com/100007939581.html
机箱 先马(SAMA)剑魔升级版 179 https://item.jd.com/100007087962.html
其他 RGB风扇 x3 / DP 线 1.4版 130 https://item.jd.com/100007577985.html https://item.jd.com/100008069617.html
总计 16295

效果图

效果图-1

效果图-2

系统信息

设备信息

CPU得分

CPU超频

Power 显示的是当前 CPU 的功率;

Frequency 显示当前 CPU 的频率;

Temperature 显示当前 CPU 的温度,此温度是内核温度;

Utilization 显示当前 CPU 的占用率。

显卡 Metal 得分

显卡 OpenCL 得分

磁盘速度

步骤

准备工作

  1. 一个容量大于等于 16G 的 U 盘
  2. 一台macOS操作系统的主机
  3. 下载 Mac 版的软件 balenaEtcher (https://www.balena.io/etcher/)
  4. 软件 Hackintool (https://github.com/headkaze/Hackintool)

准备安装镜像

  1. App Store 下载最新的操作 MacOS 操作系统,下载完成之后就可以在“应用程序”中找到
  2. 创建DMG文件: 打开“磁盘工具”,创建空白镜像,命名为 MyMacOS, 根据所下载的镜像的大小,分配一个合理的镜像大小,格式选择日志式,分区选择 GUID 分区类型,权限选择读写
  3. macOS 系统上的主机上 插入 U 盘,输入以下命令格式化 U 盘
1
diskutil partitionDisk /dev/{YOUR_DISK_ID} GPT JHFS+ "USB" 100%
  1. 双击打开 MyMacOS.dmg 文件进行挂载,输入如下命令,将下载的系统镜像文件写入 DMG 镜像中
1
sudo /Applications/Install\ macOS\ Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/MyMacOS
  1. 使用 balenaEtcher 将 MyMacOS.dmg 镜像刷入 U 盘中
  2. 使用 Hackintool 挂载 U 盘的 UEFI 分区,将我已经配置好的 USB_EFI 整个目录拷贝进去, 并且重命名为 EFI,之后卸载分区

BIOS 配置

在技嘉官网下载最新版 Z390 主板的 BIOS 固件(https://www.gigabyte.cn/Motherboard/Z390-AORUS-PRO-WIFI-rev-10/support#support-dl-driver)并刷入

当前最新版本 F12j
进行如下配置:

  • Load Optimized Defaults
  • Settings -> IO Ports -> Internal Graphics -> Enabled
  • Settings -> IO Ports -> DVMT Pre-Allocated -> 32M
  • Settings -> IO Ports -> Wi-Fi -> Disabled
  • Settings -> IO Ports -> Above 4G Decoding -> Enabled
  • Settings -> IO Ports -> Wake on LAN Enable -> Disabled
  • Settings -> IO Ports -> USB Configuration -> Legacy USB Support -> Disabled
  • Settings -> IO Ports -> USB Configuration -> XHCI Hand-off -> Enabled
  • Settings -> Miscellaneous -> Software Guard Extensions(SGX) -> Disabled
  • Settings -> Miscellaneous -> Trusted Computing -> Security Device Support -> Disabled
  • Boot -> CFG Lock -> Disabled

安装

  1. 插入 U 盘,启动时按 F12 进入启动设备选择, 选择 OpenCore, 之后选择安装 MacOS 选项
  2. 耐心等待跑码安装完毕, 之后会进入 MacOS 的安装界面, 先进入磁盘工具, 将要安装系统的那个硬盘抹掉, 格式选择 APFS,之后再安装 MacOS 系统, 之后等待重启
  3. 重启依然要使用 U 盘进行引导,进入硬盘里的 MacOS 系统
  4. 到这里整个系统的安装以及完成了一半了
  5. 注意此时进入系统是千万不要登入自己的 iCloud 账号进行使用,需要在下面生成并注入了序列号之后才可以安全的登录

后续完善

更换 EFI

使用 Hackintool 挂载 硬盘的 UEFI 分区,并且将我配置好的 EFI 目录复制进去,进行覆盖

USB 端口的配置

有 MacOS 系统的限制, 最多只允许开始使用 15个端口, 我这里就 Z390 的主板进行下面端口的开启
背面端口图
主板接口图

使用 Hackintool, 修改端口, 并导出, 注意保留 USBPorts.kext 文件以放入 Kexts 目录下, 我这里开启的端口如下配置
启用的端口

关闭啰嗦模式

找到 配置文件中的

1
2
<key>boot-args</key>
<string>-v keepsyms=1 agdpmod=pikera slide=0 shikigva=80</string>

去掉 -v

生成序列号

使用 Hackintool 生成序列号,选择的类型为 iMac (Retina 5K, 27-inch, 2019)
之后到官网查询,如果提示序列号不合法,则该序列号可用,这时候可以将其注入以下部分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<dict>
<key>AdviseWindows</key>
<false/>
<key>SystemMemoryStatus</key>
<string>Auto</string>
<key>MLB</key>
<string>M0000000000000001</string>
<key>ProcessorType</key>
<integer>0</integer>
<key>ROM</key>
<data>ESIzRFVm</data>
<key>SpoofVendor</key>
<true/>
<key>SystemProductName</key>
<string>iMac19,1</string>
<key>SystemSerialNumber</key>
<string>W00000000001</string>
<key>SystemUUID</key>
<string>00000000-0000-0000-0000-000000000000</string>
</dict>

分别是 MLBSystemSerialNumberSystemUUID

OpenCore 配置列表

OpenCore EFI

Download OpenCore RELEASE from here

ACPI

  • SSDT-EC-USBX.aml
  • SSDT-PLUG.aml
  • SSDT-HPET.aml
  • SSDT-PMC.aml

Driver

  • HfsPlus.efi
  • OpenRuntime.efi - Included in OpenCore package

Kext - Make sure to download RELEASE version

Tools

  • modGRUBShell.efi
  • OpenShell.efi - Included in OpenCore package
  • ResetSystem.efi - Included in OpenCore package
  • CleanNvram.efi - Included in OpenCore package

config.plist

  • Use config_usb.plist for installation media(USB). Rename it to config.plist.
  • Use config.plist for internal boot disk.

EFI Folder Structure

USB
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
EFI
├── BOOT
│   └── BOOTx64.efi
└── OC
├── ACPI
│   ├── SSDT-EC-USBX.aml
│   ├── SSDT-HPET.aml
│   ├── SSDT-PLUG.aml
│   └── SSDT-PMC.aml
├── Bootstrap
│   └── Bootstrap.efi
├── Drivers
│   ├── HfsPlus.efi
│   └── OpenRuntime.efi
├── Kexts
│   ├── AppleALC.kext
│   ├── IntelMausi.kext
│   ├── Lilu.kext
│   ├── SMCProcessor.kext
│   ├── SMCSuperIO.kext
│   ├── USBInjectAll.kext
│   ├── VirtualSMC.kext
│   └── WhateverGreen.kext
├── OpenCore.efi
├── Tools
│   ├── CleanNvram.efi
│   ├── OpenShell.efi
│   ├── ResetSystem.efi
│   └── modGRUBShell.efi
└── config.plist
SSD/NVME/HDD
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
EFI
├── BOOT
│   └── BOOTx64.efi
└── OC
├── ACPI
│   ├── SSDT-EC-USBX.aml
│   ├── SSDT-HPET.aml
│   ├── SSDT-PLUG.aml
│   └── SSDT-PMC.aml
├── Bootstrap
│   └── Bootstrap.efi
├── Drivers
│   ├── HfsPlus.efi
│   └── OpenRuntime.efi
├── Kexts
│   ├── AppleALC.kext
│   ├── IntelMausi.kext
│   ├── Lilu.kext
│   ├── SMCProcessor.kext
│   ├── SMCSuperIO.kext
│   ├── USBPorts.kext
│   ├── VirtualSMC.kext
│   └── WhateverGreen.kext
├── OpenCore.efi
├── Tools
│   ├── CleanNvram.efi
│   ├── OpenShell.efi
│   ├── ResetSystem.efi
│   └── modGRUBShell.efi
└── config.plist

工作状态

目前一切都正常工作,包括声卡,网卡,Wi-Fi,蓝牙,Airdrop,随航,接力,显示分辨率,睡眠,关机,重启

遇到的坑

  1. 我买的主板CPU针脚上有一个针脚弯曲了, 导致有2 个内存插槽无法读取, 如下图

CPU针脚

CPU针脚弯曲

这种情况的具体表现是只有插在主板的 DDR4_A1 槽或者 DDR4_A2 槽或者 2 个槽都插时才能短接进入 BIOS 界面,
插入全部 4 根内存条或者只要插入 DDR4_B2 或者 DDR4_B1 时将无法进入 BIOS 界面且主板无限重启,显示器无输出且 DRAM 指示灯常亮

后来我用镊子将其矫正就可以了

  1. 主板的 CSM Support 选项不能关闭, 关闭会导致无法进入 BIOS, 且主板上的 VGA 等常亮

最后

目录中的 EFIEFI_USB 都是我已经修改好的引导了,可以直接使用,其中 EFI 是复制到硬盘上用来引导系统的, EFI_USB 是复制到 U 盘上用来进行 U 盘引导的

引导下载地址见: https://github.com/JoyLau/Hackintosh-GIGABYTE-Z390-AORUS-PRO-WIFI-i9-9900K-RX580-BCM94360CD-OpenCore

参考资料

背景

有时在项目中调用的接口是 https 的形式, 这时使用 RestTemplate 来调用请求就会出错:

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
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1514)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
at cn.joylau.code.job.executor.service.jobhandler.HttpJobHandler.execute(HttpJobHandler.java:155)
at cn.joylau.code.job.core.thread.JobThread.run(JobThread.java:151)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
at sun.security.validator.Validator.validate(Validator.java:260)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1496)
... 12 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
... 18 more


I/O error on GET request for "https://xxxxxx":
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

下面是解决方式

配置

  1. 引入依赖
1
implementation 'org.apache.httpcomponents:httpclient'
  1. 代码配置
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
    import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;


@Bean
public RestTemplate restTemplate(){
return restTemplateBuilder.build();
}

/**
* HTTPS RestTemplate
*/
@Bean
public RestTemplate httpsRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);

CloseableHttpClient httpClient
= HttpClients.custom()
.setSSLHostnameVerifier(new NoopHostnameVerifier())
.setSSLSocketFactory(sslConnectionSocketFactory)
// .setDefaultCredentialsProvider(credsProvider)
.build();
HttpComponentsClientHttpRequestFactory requestFactory
= new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
requestFactory.setConnectTimeout((int)Duration.ofSeconds(5).toMillis());
return new RestTemplate(requestFactory);
}

使用

之前使用方式不变:

1
2
@Autowired
private RestTemplate restTemplate;

使用 https RestTemplate

1
2
@Autowired
private RestTemplate httpsRestTemplate;

背景

最近因为工作原因不得不在 Mac 上安装了 Office 套件

但是有一个问题, 我的 Mac 的系统语言是英文的, 安装完 Office 后, 整个操作都是英文的, 蒙蔽了….

解决

方式一

打开终端:

1
2
3
defaults write com.microsoft.Word AppleLanguages '("zh_CN")'
defaults write com.microsoft.Excel AppleLanguages '("zh_CN")'
defaults write com.microsoft.Powerpoint AppleLanguages '("zh_CN")'

切换回英文的话, 修改 zh_CH 为 en 即可

方式二

在系统设置里面修改特定APP的语言

IMage

注: 转自知乎

概述

在 CentOS 8 上安装 bpytop 很简单, 安装 epel 库后执行 dnf install bpytop 即可, 但是在 CentOS 7 的 epel 库里却没有这个 bpytop 包, 这里介绍如何在 CentOS 7 下安装 bpytop

步骤

  1. 安装 epel 库
1
yum install epel-release
  1. 安装 snapd 并启用 snapd 套接字
1
2
yum install snapd
systemctl enable --now snapd.socket
  1. 用户重新登录

  2. 安装及权限配置

1
2
3
4
5
6
7
8
9
10
11
12
13
snap install bpytop

sudo snap connect bpytop:mount-observe

sudo snap connect bpytop:network-control

sudo snap connect bpytop:hardware-observe

sudo snap connect bpytop:system-observe

sudo snap connect bpytop:process-control

sudo snap connect bpytop:physical-memory-observe

背景

很多时候我们通过 mount -t nfs -o nolock 服务端IP:共享目录绝对路径 本地挂载目录 来挂载网络磁盘

很多时候,为了安全考虑网络磁盘都设置了用户名密码

这时挂载的时候就需要设置用户名密码了

很可惜上述方式 nfs 没有找到设置用户名密码的参数

解决

使用 cifs

  1. 安装依赖: yum install cifs-utils

  2. 挂载: mount -t cifs -o username=USERNAME,password=PASSWORD,iocharset=utf8 //192.168.10.191/CM_Backup /mnt/191-nas

注意主机地址前的 // 不能省略

  1. 卸载挂载: umount /mnt/191-nas

额外的

挂载网络磁盘很多时候无非为了备份, 使用 cp 命令像本地拷贝文件一样备份即可,但是 cp 命令无法显示进度,对于大文件来说,就会等待上很长的时间无输出

我这里提供 2 中解决方式

  1. 使用 pv

语法: pv sourcefile > targetfile

优点: 提供实时进度条显示

缺点: 只能终端显示, 无法记录到文件中, 而且一旦终止任务, 进程无法正常退出

  1. 使用 rsync

语法: rsync -avPh sourcefile targetfile

优点: 使用命令 rsync -avPh sourcefile targetfile | tee log.log 可将进度写入日志文件中

缺点: 暂无

0%