默认是: /var/cache/yum
也可以在 /etc/yum.conf 指定
cachedir=/var/cache/yum #存放目录
keepcache=1 #1为保存 0为不保存
metadata_expire=1800 #过期时间
CentOS本地yum源的搭建
第一步:
从rsync协议的yum源,同步脚本如下:
[[email protected] crontab]# cat yum_update.sh
#!/bin/bash
date=`date +%F`
echo $date > /var/log/yum_update.log
##########Centos
sour_URL=”rsync://centos.ustc.edu.cn/centos”
osList=”6.6″
os_Plant=”x86_64″
cmd=”rsync -avrt “
cmd=${cmd}${sour_URL}”/”${sour_Dir}”/”
outDir=”/home/himalayas/yum/centos/6/” ### if change ,please notice the line of epel、rpmforge、rpmfusion
for yumdir in os updates extras centosplus contrib;
do
test -d $outDir/$yumdir || mkdir -p $outDir/$yumdir
rsync -avrt $sour_URL/$osList/$yumdir/$os_Plant $outDir/$yumdir >> /var/log/yum_update.log &
done
##########epel
test -d /home/himalayas/yum/epel/6/x86_64 || mkdir -p /home/himalayas/yum/epel/6/x86_64
rsync -avrt –exclude=debug/ –exclude=repoview/ rsync://centos.ustc.edu.cn/fedora/epel/6/x86_64/ /home/himalayas/yum/epel/6/x86_64 >> /var/log/yum_update.log &
##########rpmforge
test -d /home/himalayas/yum/rpmforge/6/rpmforge/x86_64 || mkdir -p /home/himalayas/yum/rpmforge/6/rpmforge/x86_64
test -d /home/himalayas/yum/rpmforge/6/extras/x86_64 || mkdir -p /home/himalayas/yum/rpmforge/6/extras/x86_64
rsync -avrt rsync://mirror.cpsc.ucalgary.ca/dag/redhat/el6/en/x86_64/rpmforge/ /home/himalayas/yum/rpmforge/6/rpmforge/x86_64 >> /var/log/yum_update.log & ###4678
rsync -avrt rsync://mirror.cpsc.ucalgary.ca/dag/redhat/el6/en/x86_64/extras/ /home/himalayas/yum/rpmforge/6/extras/x86_64 >> /var/log/yum_update.log &
##########rpmfusion
test -d /home/himalayas/yum/rpmfusion/free/x86_64 || mkdir -p /home/himalayas/yum/rpmfusion/free/x86_64
test -d /home/himalayas/yum/rpmfusion/nofree/x86_64 || mkdir -p /home/himalayas/yum/rpmfusion/nofree/x86_64
rsync -avrt rsync://centos.ustc.edu.cn/fedora/rpmfusion/free/el/updates/6/x86_64/ /home/himalayas/yum/rpmfusion/free/x86_64 >> /var/log/yum_update.log &
rsync -avrt rsync://centos.ustc.edu.cn/fedora/rpmfusion/nonfree/el/updates/6/x86_64/ /home/himalayas/yum/rpmfusion/nofree/x86_64 >> /var/log/yum_update.log &
备注:
1,访问这个网址:centos.ustc.edu.cn/centos/ ,当版本更新之后所有的rpm包可能有6.5转到6.6的目录下,这个时候要手工更改变量:osList=”6.6″,然后最好手工执行一次,看是否可以同步更新。
2,可以用如下命令,查看对方rsync源的目录结构和所有rpm包
rsync -avrt rsync://centos.ustc.edu.cn/centos/6.6/os/x86_64
第二步:添加到crontab每天同步一次
00 00 * * * /bin/bash /kuxun/crontab/yum_update.sh
-
Centos6.4光盘或镜像文件
-
安装了Centos6.4系统的电脑
方法/步骤
-
放入Centos6.4的镜像光盘或找到镜像文件
mount –o loop –t iso9660 CentOS-6.0-i386-bin-DVD.iso
mount /dev/cdrom /media/cdrom
-
编辑repo文件:
cd /etc/yum..repos.d
(文件位置/etc/yum.repos.d/,后缀一定是.repo结束.为了使用自己搭建的yum源我这里删除了自带的(rm –f ./*)
-
编辑自己的repo文件
方法一:
[[email protected]]# vim local.repo (repo后缀)
[local_server](库名称)
name=Thisis a local repo (名称描述)
baseurl=file:///media/dvd(yum源目录,源地址)
enabled=1(是否启用该yum源,0为禁用)
gpgcheck=1 (检查GPG-KEY,0为不检查,1为检查)
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6(gpgcheck=0时无需配置)
保存退出!
-
方法二:使用createrepo命令创建yum仓库
1.将所有rpm文件拷贝到一个文件夹中 cp -rv /media/光盘/Packs/* /所建立的文件夹
2.通过rpm命令手动安装createrepo命令创建yum仓库 rpm -ivh createrepo
3.运行命令createrepo -v /rpm-directory
4.如果有分组信息,则在运行命令的时候使用-g参数置顶分组文件
makedir /localserver (建立本地文件夹)
mount /dev/cdrom /media/cdrom
cp -rv /media/cdrom/光盘/Packs/* /localserver
cd /localserver
rpm -ivh createrepo (若提示需要安装依赖包,根据提示安装即可)
createrepo -v /localserver/ (创建索引信息,repodate)
如若需要分组信息
cp /media/cdrom/光盘/repodate/*.comp /comps.xml
createrepo -g /comps.xml /localserver (开始创建分组信息)
然后编辑repo文件(同方法一编辑方法相同)
-
[[email protected] yum.repos.d]# yum clean all (清除缓存)
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: local_server
Cleaning up Everything
Cleaning up list of fastest mirrors
[[email protected] yum.repos.d]# yum makecache (建立新缓存)
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
local_server |4.0 kB 00:00 …
local_server/group_gz | 209kB 00:00 …
local_server/filelists_db | 4.8 MB 00:00 …
local_server/primary_db | 3.5 MB 00:00 …
local_server/other_db | 2.0MB 00:00 …
Metadata Cache Created
[[email protected] yum.repos.d]#
-
这下可以使用yum本地源了
Test: yuminstall –y sendmail
-
到此yum本地源安装结束
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/1816.html