首先安装createrepo包
[root@linuxserver2 os_rpms_rhel5.7_x86_64]# rpm -ivh createrepo-0.4.11-3.el5.noarch.rpm warning: createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:createrepo ########################################### [100%] |
然后创建repo源
[root@linuxserver2 repo]# createrepo -g os_rpms_rhel5.7_x86_64/rpms/repodata/comps-rhel5-server-core.xml os_rpms_rhel5.7_x86_64/rpms/ Error: groupfile /repo/os_rpms_rhel5.7_x86_64/rpms/os_rpms_rhel5.7_x86_64/rpms/repodata/comps-rhel5-server-core.xml cannot be found.
createrepo [options] directory-of-packages
Options: -u, --baseurl <url> = optional base url location for all files -o, --outputdir <dir> = optional directory to output to -x, --exclude = files globs to exclude, can be specified multiple times -q, --quiet = run quietly -n, --noepoch = don't add zero epochs for non-existent epochs (incompatible with yum and smart but required for systems with rpm < 4.2.1) -g, --groupfile <filename> to point to for group information (precreated) (<filename> relative to directory-of-packages) -v, --verbose = run verbosely -c, --cachedir <dir> = specify which dir to use for the checksum cache -C, --checkts = don't generate repo metadata, if their ctimes are newer than the rpm ctimes. -i, --pkglist = use only these files from the directory specified -h, --help = show this help -V, --version = output version -p, --pretty = output xml files in pretty format. --update = update existing metadata (if present) -d, --database = generate the sqlite databases. --skip-stat = skip the stat() call on a --update, assumes if the name is the same then the file is the same.
[root@linuxserver2 repo]# createrepo -g /repo/os_rpms_rhel5.7_x86_64/rpms/repodata/comps-rhel5-server-core.xml os_rpms_rhel5.7_x86_64/rpms/ 3261/3261 - openldap-clients-2.3.43-12.el5_6.7.x86_64.rpm rpm Saving Primary metadata Saving file lists metadata Saving other metadata |
执行结果之后,就可以通过yum安装rpm包了。
但是这个命令可能只是临时生效,yum clean all之后,无法通过yum安装了。
再执行上面的命令也不生效了。暂时不知道原因。
另外的方法:
在/etc/yum.repos.d目录下,新建*.repo配置文件,格式如下:
[root@linuxserver2 yum.repos.d]# cat os_5.7_x86_64.repo [RHEL5.7] name=rhel_5.7_x86_64_LJ baseurl=file:///repo/os_rpms_rhel5.7_x86_64/rpms/ enabled=1 gpgcheck=1 gpgkey=file:///repo/os_rpms_rhel5.7_x86_64/RPM-GPG-KEY-redhat-release |
[root@linuxserver2 yum.repos.d]# cat epel5_x86_64.repo [EPEL5] name=epel5_x86_64 baseurl=file:///repo/epel5_x86_64/epel/ enabled=1 gpgcheck=1 gpgkey=file:///repo/epel5_x86_64/RPM-GPG-KEY-EPEL-5 |
这里添加了两个配置文件,然后执行清空缓存命令之后,查看repo
[root@linuxserver2 yum.repos.d]# yum clean all Loaded plugins: product-id, security, subscription-manager Updating Red Hat repositories. Cleaning up Everything [root@linuxserver2 yum.repos.d]# yum repolist Loaded plugins: product-id, security, subscription-manager Updating Red Hat repositories. EPEL5 | 3.7 kB 00:00 EPEL5/primary_db | 3.4 MB 00:00 RHEL5.7 | 1.1 kB 00:00 RHEL5.7/primary | 1.1 MB 00:00 RHEL5.7 3261/3261 repo id repo name status EPEL5 epel5_x86_64 6,781 RHEL5.7 rhel_5.7_x86_64_LJ 3,261 repolist: 10,042 |