搜尋

搜尋結果

架設 Squid proxy,作為國産 Linux RPM 安裝包更新的 RPM proxy
科技新知
MacauYeah・2026-02-26

前編我們介紹了 Qemu 運行國産OS做快速測試。應該基本使用大家都可以實驗到。 在投産環境上,我們通常還要控制它的kernel或lib版本更新,但這麼多的不同OS版本,想一次過做rpm mirror,並不太實際。 若以監管為目標,那些不同種類的OS,限制互聯網存取,統一經過某個http proxy的取得RPM更新,應該是一個最低成本的做法。 本文就來介紹一下,使用Ubuntu 24建設 Squid http proxy,達到rpm proxy的結果。 ubuntu 24.04 squid settings aptget update amp;amp; aptget install squid vim etcsquidsquid.conf 約在1404行,指定一個新的aclaccess control list名字,fixip, 它的允許來源IP是你的rpm base OS # around line 1404, add acl fixip src xxx.xxx.xxx.xxx 約在1627行, 放行新的acl # around line 1627, add http_access allow fixip rpm os settings 在rpm base的OS上,通常在 etcyum.repos.d 低下就找到它們的 rpm 包來源為置,在每個來源上加上 proxy 設定,就可以了。 Anolis OS 8 因為rpm來源眾多,我們只想讓其中兩個經proxy更新,例如 etcyum.repos.dAnolisOSAppStream.repo, etcyum.repos.dAnolisOSBaseOS.repo, 最在後加入 proxy=httpyyy.yyy.yyy.yyy3128。 yyy.yyy.yyy.yyy 就是設了 Squid的機器 AppStream name=AnolisOS$releasever AppStream baseurl=httpmirrors.openanolis.cnanolis$releaseverAppStream$basearchos enabled=1 gpgkey=fileetcpkirpmgpgRPMGPGKEYANOLIS gpgcheck=1 proxy=httpyyy.yyy.yyy.yyy3128 BaseOS name=AnolisOS$releasever BaseOS baseurl=httpmirrors.openanolis.cnanolis$releaseverBaseOS$basearchos enabled=1 gpgkey=fileetcpkirpmgpgRPMGPGKEYANOLIS gpgcheck=1 proxy=httpyyy.yyy.yyy.yyy3128 OpenEuler 22 來源檔只有一個,etcyum.repos.dopenEuler.repo, 但內存多個section, 需要在每個section的尾段,加入 proxy=httpyyy.yyy.yyy.yyy3128 OS name=OS baseurl=httprepo.openeuler.orgopenEuler22.03LTSSP4OS$basearch metalink=httpsmirrors.openeuler.orgmetalinkrepo=$releaseverOSamp;arch=$basearch metadata_expire=1h enabled=1 gpgcheck=1 gpgkey=httprepo.openeuler.orgopenEuler22.03LTSSP4OS$basearchRPMGPGKEYopenEuler proxy=httpyyy.yyy.yyy.yyy3128 everything name=everything baseurl=httprepo.openeuler.orgopenEuler22.03LTSSP4everything$basearch metalink=httpsmirrors.openeuler.orgmetalinkrepo=$releasevereverythingamp;arch=$basearch metadata_expire=1h enabled=1 gpgcheck=1 gpgkey=httprepo.openeuler.orgopenEuler22.03LTSSP4everything$basearchRPMGPGKEYopenEuler proxy=httpyyy.yyy.yyy.yyy3128 ... ... update name=update baseurl=httprepo.openeuler.orgopenEuler22.03LTSSP4update$basearch metalink=httpsmirrors.openeuler.orgmetalinkrepo=$releaseverupdateamp;arch=$basearch metadata_expire=1h enabled=1 gpgcheck=1 gpgkey=httprepo.openeuler.orgopenEuler22.03LTSSP4OS$basearchRPMGPGKEYopenEuler proxy=httpyyy.yyy.yyy.yyy3128 ... ... 指令 我們可以先用curl,來測試一下最基本的連線。請確保指令是在最初定義的xxx.xxx.xxx.xxx範圍內。 curl v x httpyyy.yyy.yyy.yyy3128 httpmirrors.openanolis.cnanolis8.10 部份更新指令 由於我們前述 rpm 包並不是所有都加了proxy,我們只限定某些進行更新,所以我們使用disablerepo enablerepo來限制指定的更新來源。 # anolis dnf install disablerepo='' enablerepo='BaseOS' 'tmux' dnf upgrade disablerepo='' enablerepo='kernel5.10' 'kernel' # openeuler dnf install disablerepo='' enablerepo='everything' tmux dnf upgrade disablerepo='' enablerepo='update' 'kernel' 參考連結 squid tutorial httpswww.digitalocean.comcommunitytutorialshowtosetupsquidproxyonubuntu2004 yum proxy tutorial httpswww.baeldung.comlinuxyumdnfrepositoriessetproxy

Spring boot 10 - openapi 生成器 - spring boot java client
科技新知
MacauYeah・2025-08-19

之前我們在介紹Spring Boot Web 調試工具 ,就試安裝 openapi 相關的元件。其實 openapi 並不單是為了提供 swagger 測試介面,它主要是提供一個描述的方式,讓我們針對一個特定 openapi 文件,生成對應的 api server 或 api client 接口。也就是,如果 server 方有提供該文件,道理上可以經 openapi 的工具,生成一個可以直接訪問 server 的 client library。本節,可以沿用之前的 spring boot web api doc ,為它產生一個client library 作為實驗。 在生成 client library 之前,我們還需要一個工具 openapigeneratorcli 。最簡單的取得方式,就是經過 npm , 在你需要生成 client library 的專案中,安裝你需要的 openapigeneratorcli 版本。 npm install @openapitoolsopenapigeneratorcli 那怕你不是使用 nodejs 作為開發,也可以經過這個方法安裝。它只提供使用 cmd 指令的捷徑。 生成 Java Client Library 我們先把 backend server 起好 cd somewhere amp;amp; mvn springbootrun,然後使用 openapigeneratorcli 去生成以 java spring boot 3 為底的 client library 。 npx openapigeneratorcli generate i httplocalhost8080v3apidocs apipackage io.github.macauyeah.springboot.tutorial.openapiclient.api modelpackage io.github.macauyeah.springboot.tutorial.openapiclient.model invokerpackage io.github.macauyeah.springboot.tutorial.openapiclient.invoker groupid io.github.macauyeah.springboot.tutorial artifactid springbootwebapiopenapiclient artifactversion 0.0.1SNAPSHOT g java p useJakartaEe=true p useSpringBoot3=true library webclient o springbootwebapiopenapiclient 生成的 source code 就像是 springbootwebapiopenapiclient ,具體的使用方式,可以看看測試用例 ApiControllerApiTest.java private final ApiControllerApi api = new ApiControllerApi; @Test public void postDateQueryTest default call ApiDateRequest apiDateRequest = new ApiDateRequest; apiDateRequest.setInputDateOffsetDateTime.now; LOG.debugquot;default web client postDateQueryquot;, api.postDateQueryapiDateRequest.block; replace webClient in ApiClient if you have special auth config on webClient, you can also change basePath during new obj creation ObjectMapper mapper = new ObjectMapper; mapper.setDateFormatnew SimpleDateFormat; mapper.registerModulenew JavaTimeModule; WebClient webClient = WebClient.builder .codecsconfigurer gt; configurer.defaultCodecs.jackson2JsonDecodernew Jackson2JsonDecodermapper; configurer.defaultCodecs.jackson2JsonEncodernew Jackson2JsonEncodermapper; .build; ApiControllerApi api2 = new ApiControllerApi new ApiClientwebClient .setBasePathquot;httplocalhost8080quot;; LOG.debugquot;create api2 by local web client postDateQueryquot;, api2.postDateQueryapiDateRequest.block; use webClient directly String response = webClient.post.uriquot;httplocalhost8080apirecordquot;.bodyValueapiDateRequest.retrieve .bodyToMonoString.class.block; LOG.debugquot;request by local web client postDateQueryquot;, response; 上述例子中,如果大家沒有任何特殊要求,其實經過 api.postDateQueryapiDateRequest.block 就完成了。有需要改 api endpoint 的,只要生成新的 ApiClient 並設定 basePath new ApiClient.setBasePathquot;XXXXXXquot; 就好。真的要加入更多權限設定,就需要生成新的 ApiClient 並設定 webClient new ApiClientwebClient 這個生成的 Java Client Library 道理上還是要經過 maven 等打包,變成 jar 檔,才能被其他 Java 專案所引用。筆者就建議大家直接把成生的視為獨立的 module sub module 存放,其他專案就以 maven dependency 的方式引用。想要混合現有專案,動態生成專案內某些 java package,暫時不太可行。因為它也有大量的 dependency ,交由 openapigeneratorcli 自己管理會比較好,它們升級時,你也可以完整升級。 openapigeneratorcli httpsgithub.comOpenAPIToolsopenapigeneratorcli springbootwebapiopenapiclient