架設 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