建立yum源 RHEL, CentOS, Fedora等适用,平时使用RHEL系列


用Redhat系的Linux OS(RHEL, CentOS 和 Fedora等)时,使用yum工具来管理软件包是很有必要的,当管理很多的系统或者不方便连接外部yum源时,建立一个内部使用的yum源也是很重要的。平时使用RHEL系列的OS

比较多(目前是RHEL6.4),在2年前就建立了内部使用的yum源,偶尔也需要将其更新到最新的版本,所以还是重复做一下建立yum源的步骤。这里简单记录以下如何建立yum源吧,其实也很简单。

准备工作:安装必须要的软件(如createrepo),准备yum源用到的rpm包复制RPM包到特定的目录下在目录下运行createrepo命令将yum源的目录作为http或ftp服务暴露出来在客户端系统上,配置yum源,一般是在 /etc/yum.repo.d/ 目录中建立test.repo这样文件,在里面配置使用的yum源的URL.配置好yum源后,可以运行“yum repolist”看一下效果,也可以“yum install $your-software”来使用。

写了个简单的脚本来建立yum源,如下:

#!/bin/bash
# set up YUM repository
# yum install createrepo # install 'createrepo' tool
base_dir=/home/yum/pub/6Server
# mkdir -p $base_dir/{SRPMS,i386,x86_64} # create dir if needed
for i in "SRPMS i386 x86_64"
do
# cp /your-src/*.rpm $base_dir/$i/ # you may copy RPMs to the destination
pushd $base_dir/$i > /dev/null 2>&1
createrepo .
popd >/dev/null 2>&1
done

使用yum源的系统上,关于yum源的配置文件,如下:

# put this .repo file into /etc/yum.repo.d/ directory.

[rhel$releasever]
name=Red Hat Enterprise Linux $releasever
baseurl=http://mydomain.com/yum/$releasever/$basearch
enabled=1
gpgcheck=0

[rhel6_optional]
name=Red Hat Enterprise Linux rhel6_optional
baseurl=http://mydomain.com/yum/$releasever_optional/$basearch
enabled=1
gpgcheck=0

注意:在我的64位的RHEL6.4上,$releasever被解析为6Server,$basearch被解析为x86_64.

FROM:http://smilejay.com/2013/06/set-up-yum-repo/

相关内容