Yum 信息库设置

本文解释了如何创建本地 yum 信息库并配置 up2date 和 yum 以便从它们安装和更新程序包。

服务器设置

前提条件:

  • 一台运行 Enterprise Linux 4 U4 for i386 的 i386 计算机
  • 一台运行 Enterprise Linux U4 for x86_64 的 x86_64 计算机
  • 一个有效的 CSI

以下步骤描述了如何从 linux-update.oracle.com 下载最新的程序包并通过本地 yum 服务器进行提供。对于 i386 和 x86_64,必须重复这些步骤,但 yum 信息库可以在同一计算机上共存。

  1. 在坚不可摧的 Linux 网络 (Unbreakable Linux Network) 上注册该计算机。
    1. 导入 RPM GPG 键
    2. rpm --import /usr/share/rhn/RPM-GPG-KEY
      
    3. 以文本模式运行 up2date。
    4. up2date-nox --register
      
    5. 注册该计算机。输入用户名、密码和一个有效的 CSI。

  2. 将该计算机注册到所有可用通道
    1. 打开一个 Web 浏览器并进入 linux.oracle.com
    2. 用注册该计算机的用户和密码登录
    3. 单击右上角的 Systems 选项卡
    4. 在列表中找到注册的计算机并单击它
    5. 选中所有可用通道并单击订阅

    6. i386 Channel x86_64 Channel 说明
      el4_u4_i386_base el4_u4_x86_64_base Enterprise Linux 4 更新 4
      el4_u4_i386_patch el4_u4_x86_64_patch Enterprise Linux 4 更新 4 补丁
      el4_i386_addons el4_x86_64_addons Enterprise Linux 4 附件
      el4_i386_latest el4_x86_64_latest 最新的 Enterprise Linux 4

  3. 安装 uln-yum-proxy。这将安装 yum 信息库所需的程序包
  4. up2date -i uln-yum-proxy
    
  5. 在 /var/www/html 中创建一个 yum 目录。该目录将托管信息库
  6. mkdir /var/www/html/yum
    
    请注意,随着更多程序包添加到这些通道,空间需求也将增长。

    Channel

    空间需求

    el4_u4_i386_base 2.0G
    el4_u4_i386_patch 103M
    el4_i386_addons 68K
    el4_i386_latest 2.1G
    el4_u4_x86_64_base 2.3G
    el4_u4_x86_64_patch 105M
    el4_x86_64_addons 168K
    el4_x86_64_latest 2.3G

  7. 创建信息库目录结构
    • i386
    • mkdir -p /var/www/html/yum/EnterpriseLinux/EL4/4/base/i386
      mkdir -p /var/www/html/yum/EnterpriseLinux/EL4/4/patch/i386
      mkdir -p /var/www/html/yum/EnterpriseLinux/EL4/addons/i386
      mkdir -p /var/www/html/yum/EnterpriseLinux/EL4/latest/i386
      
    • x86_64
    • mkdir -p /var/www/html/yum/EnterpriseLinux/EL4/4/base/x86_64
      mkdir -p /var/www/html/yum/EnterpriseLinux/EL4/4/patch/x86_64
      mkdir -p /var/www/html/yum/EnterpriseLinux/EL4/addons/x86_64
      mkdir -p /var/www/html/yum/EnterpriseLinux/EL4/latest/x86_64
      
  8. 填充信息库
    1. 创建名为 /root/rep_populate.sh 的文件并添加以下几行。如果它们有别于您已有的内容,则更改目录名
    2. #!/bin/sh
      
      UP2DATE=/usr/sbin/up2date
      
      ARCH32=i386
      ARCH64=x86_64
      
      BASE32=el4_u4_i386_base
      PATCH32=el4_u4_i386_patch
      ADDONS32=el4_i386_addons
      LATEST32=el4_i386_latest
      
      BASE64=el4_u4_x86_64_base
      PATCH64=el4_u4_x86_64_patch
      ADDONS64=el4_x86_64_addons
      LATEST64=el4_x86_64_latest
      
      REP_BASE=/var/www/html/yum/EnterpriseLinux/EL4/4/base
      REP_PATCH=/var/www/html/yum/EnterpriseLinux/EL4/4/patch
      REP_ADDONS=/var/www/html/yum/EnterpriseLinux/EL4/addons
      REP_LATEST=/var/www/html/yum/EnterpriseLinux/EL4/latest
      
      MAXPKG=1000
      
      for CHANNEL in `${UP2DATE} --show-channels`
      do
        case ${CHANNEL} in
          ${BASE32})   cd ${REP_BASE}/${ARCH32}   ;;
          ${PATCH32})  cd ${REP_PATCH}/${ARCH32}  ;;
          ${ADDONS32}) cd ${REP_ADDONS}/${ARCH32} ;;
          ${LATEST32}) cd ${REP_LATEST}/${ARCH32} ;;
          ${BASE64})   cd ${REP_BASE}/${ARCH64}   ;;
          ${PATCH64})  cd ${REP_PATCH}/${ARCH64}  ;;
          ${ADDONS64}) cd ${REP_ADDONS}/${ARCH64} ;;
          ${LATEST64}) cd ${REP_LATEST}/${ARCH64} ;;
        esac
        ${UP2DATE} --showall --channel ${CHANNEL} | xargs -n $MAXPKG ${UP2DATE} --nox --get --download
                                                  
      --channel ${CHANNEL} --tmpdir=. find . -type f -not -name "*rpm" -exec rm -f {} \; done
    3. 设置执行权限
    4. chmod 755 /root/rep_populate.sh
      
    5. 运行该脚本。它将从订阅的通道下载所有可用的程序包
  9. 运行 createrepo
    • i386
    •    
      createrepo /var/www/html/yum/EnterpriseLinux/EL4/4/base/i386
      createrepo /var/www/html/yum/EnterpriseLinux/EL4/4/patch/i386
      createrepo /var/www/html/yum/EnterpriseLinux/EL4/addons/i386
      createrepo /var/www/html/yum/EnterpriseLinux/EL4/latest/i386
      
    • x86_64
    • createrepo /var/www/html/yum/EnterpriseLinux/EL4/4/base/x86_64
      createrepo /var/www/html/yum/EnterpriseLinux/EL4/4/patch/x86_64
      createrepo /var/www/html/yum/EnterpriseLinux/EL4/addons/x86_64
      createrepo /var/www/html/yum/EnterpriseLinux/EL4/latest/x86_64
      
  10. 运行 yum-arch
    • i386
    • yum-arch /var/www/html/yum/EnterpriseLinux/EL4/4/base/i386
      yum-arch /var/www/html/yum/EnterpriseLinux/EL4/4/patch/i386
      yum-arch /var/www/html/yum/EnterpriseLinux/EL4/addons/i386
      yum-arch /var/www/html/yum/EnterpriseLinux/EL4/latest/i386
      
    • x86_64
    • yum-arch /var/www/html/yum/EnterpriseLinux/EL4/4/base/x86_64
      yum-arch /var/www/html/yum/EnterpriseLinux/EL4/4/patch/x86_64
      yum-arch /var/www/html/yum/EnterpriseLinux/EL4/addons/x86_64
      yum-arch /var/www/html/yum/EnterpriseLinux/EL4/latest/x86_64
      
  11. 启动 Web 服务器
  12. chkconfig httpd on
    /etc/init.d/httpd start
    

客户端设置

  1. 导入 GPG 键
  2. rpm --import /usr/share/rhn/RPM-GPG-KEY
    
  3. 配置 up2date 使用 yum 信息库。编辑 /etc/sysconfig/rhn/sources。将行
  4. up2date default
    
    注释为
    #up2date default
    

    并添加以下几行。使用托管 yum 信息库的计算机的主机名替换 <repository_server>。按需注释和取消注释个别信息库。

    • i386
    • yum el4_latest http://<repository_server>/yum/EnterpriseLinux/EL4/latest/i386/
      #yum el4_addons http://<repository_server>/yum/EnterpriseLinux/EL4/addons/i386/
      #yum el4_u4_base http://<repository_server>/yum/EnterpriseLinux/EL4/4/base/i386/
      #yum el4_u4_patch http://<repository_server>/yum/EnterpriseLinux/EL4/4/patch/i386/
      
    • x86_64
    • yum el4_latest http://<repository_server>/yum/EnterpriseLinux/EL4/latest/x86_64/
      #yum el4_addons http://<repository_server>/yum/EnterpriseLinux/EL4/addons/x86_64/
      #yum el4_u4_base http://<repository_server>/yum/EnterpriseLinux/EL4/4/base/x86_64/
      #yum el4_u4_patch http://<repository_server>/yum/EnterpriseLinux/EL4/4/patch/x86_64/
      
  5. 以下是使用 yum 客户端的用户所需的步骤
    1. 安装 python-urlgrabber(如果尚未安装)
      1. 如果进行了注释,则取消注释 /etc/sysconfig/rhn/sources 中开头为如下所示的行:
      2. #yum el4_addons [...]
        
      3. 运行 up2date 安装 python-urlgrabber。
      4. up2date -i python-urlgrabber
        
      5. 如果需要,取消注释 /etc/sysconfig/rhn/sources 中的行

    2. 用以下内容替换 /etc/yum.repos.d/ULN-Base.repo。请注意,默认情况下只启用 el4_latest 通道
    3. 使用托管 yum 信息库的计算机的主机名替换 <repository_server>

      [el4_latest]
      name=Enterprise Linux - $basearch - latest
      baseurl=http://<repository_server>/yum/EnterpriseLinux/EL4/latest/$basearch/
      gpgcheck=1
      enabled=1
      
      [el4_addons]
      name=Enterprise Linux - $basearch - addons
      baseurl=http://<repository_server>/yum/EnterpriseLinux/EL4/addons/$basearch/
      gpgcheck=1
      enabled=0
      
      [el4_u4_base]
      name=Enterprise Linux $releasever - $basearch - base
      baseurl=http://<repository_server>/yum/EnterpriseLinux/EL4/$releasever/base/$basearch/
      gpgcheck=1
      enabled=0
      
      [el4_u4_patch]
      name=Enterprise Linux $releasever - $basearch - patch
      baseurl=http://<repository_server>/yum/EnterpriseLinux/EL4/$releasever/patch/$basearch/
      gpgcheck=1
      enabled=0
      
  6. 您现在可以使用 up2date 和 yum (如果配置了)从您的本地 yum 信息库安装和更新文件了。例如:
  7. up2date -u
    
    yum update