1. 程式人生 > 其它 >專案:使用 Nginx 搭建本地YUM倉庫

專案:使用 Nginx 搭建本地YUM倉庫

技術標籤:專案linuxyumnginxcentos專案架構

目錄

環境

伺服器IP伺服器功能伺服器操作
192.168.126.130YUM私有倉庫安裝createreponginx
192.168.126.131測試伺服器配置私有yum源 private.repo

搭建步驟

1. 安裝搭建倉庫所需軟體

# 安裝 nginx
yum install -y nginx
# 啟動 nginx
systemctl start nginx
# 安裝 createrepo
yum install -y createrepo

2. 建立倉庫目錄

# 建立私有yum倉庫
cd /usr/share/nginx \
&& mkdir myyum \
&& cd myyum \
&& createrepo .

3. 將準備好的 rpm 包匯入到倉庫目錄

# 將下載好的 rpm 包匯入到 nginx 下 myyum 目錄
cp *.rpm /usr/share/nginx/html/myyum

4. 在測試伺服器配置私有yum源

# 建立私有yum原始檔 private.repos 如使用需要替換IP
cat > /etc/yum.repos.d/private.repo <<
EOF [private] name=myyum baseurl=http://192.168.126.130/myyum gpgcheck=0 EOF

5. 測試本地yum倉庫是否搭建成功

# 清理快取
yum clean all
# 檢視倉庫列表
yum repolist

yum repo

技巧

  • 如何快取 yum 下載的軟體包?

    # 開啟 yum 安裝包快取
    sed -i.bak s/keepcache=0/keepcache=1/g /etc/yum.conf
    # 檢視快取路徑
    cat /etc/yum.conf | grep cachedir