CENTOS6.4搭建本地YUM源

1、先安装APACHE,并修改配置文件,/etc/httpd/conf/httpd.conf,如下:

DocumentRoot "/var/www/yum"
<Directory "/var/www/yum">

mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak

 

2、建立发布目录

mkdir -p /var/www/yum/centos/6/x86_64

可以拷贝一些RPM包到目录里面

 mount /dev/cdrom /mnt

cp /mnt/Packages/* /var/www/yum/centos/6/x86_64/

 

3、安装配置createrepo

yum -y install createrepo

createrepo -pdo /var/www/yum/centos/6/x86_64/ /var/www/yum/centos/6/x86_64/

生成repodata

[[email protected] repodata]# pwd
/var/www/yum/centos/6/x86_64/repodata
[[email protected] repodata]# ls
7dd7f45cd489f96ae011111441d18943b300a10b3c37539637c2799e7317c7de-primary.xml.gz
958b83242731892b050917ce77ac5730a83dbf5d3954e624a424ea76d8d4f652-filelists.xml.gz
bb4b090ae777edb0f972c1e2cf1b0986df67494e7c8c98f5c258db68faf86f96-other.sqlite.bz2
d6e9bfa75692c1f3ea8c2dd3d32001375daf51dd00bbe4415c5449102ea47519-filelists.sqlite.bz2
da4e1916e9f2350b168320b468eeba42261c20e0dfa52b144e8d295720dbe680-other.xml.gz
ffae55737c9151dae64c3256c5db4c771c8cb9f3298a5b4f331f683571457283-primary.sqlite.bz2
repomd.xml

重启httpd服务

此时访问http服务器:

 

4、配置客户端的访问

[[email protected] yum.repos.d]# pwd
/etc/yum.repos.d
[[email protected] yum.repos.d]# ls
60.repo  bak
[[email protected] yum.repos.d]# cat 60.repo 
[60]
name=60
baseurl=http://193.168.120.60/centos/6/x86_64/
enabled=1
gpgcheck=0
gpgkey=

此时yum客户端已经能正常使用yum安装软件

 

5、YUM服务器更新软件包

配置不删除YUM服务器作为YUM客户端的时候在互联网上下载过的RPM包

[[email protected] packages]# cat /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
主要就是关注前两行

例如安装ZIP

yum install zip.x86_64 -y

安装完会在缓存目录保存RPM文件

[[email protected] packages]# pwd
/var/cache/yum/x86_64/6/base/packages
[[email protected] packages]# ll
总用量 260
-rw-r--r-- 1 root root 264988 11月 10 2015 zip-3.0-1.el6_7.1.x86_64.rpm

 

拷到发布目录, cp zip-3.0-1.el6_7.1.x86_64.rpm /var/www/yum/centos/6/x86_64/

更新createrepo --update /var/www/yum/centos/6/x86_64/

更新以后,此时下游的客户端也能通过yum安装这个软件了

 

[[email protected] yum.repos.d]# yum install zip.x86_64 -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Package zip-3.0-1.el6.x86_64 already installed and latest version
Nothing to do
[[email protected] yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: 60
Cleaning up Everything
Cleaning up list of fastest mirrors
[[email protected] yum.repos.d]# yum install zip.x86_64 -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
60                                                                                                                 | 2.9 kB     00:00     
60/primary_db                                                                                                      | 3.3 MB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package zip.x86_64 0:3.0-1.el6 will be updated
---> Package zip.x86_64 0:3.0-1.el6_7.1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================
 Package                      Arch                            Version                                   Repository                   Size
==========================================================================================================================================
Updating:
 zip                          x86_64                          3.0-1.el6_7.1                             60                          259 k

Transaction Summary
==========================================================================================================================================
Upgrade       1 Package(s)

Total download size: 259 k
Downloading Packages:
zip-3.0-1.el6_7.1.x86_64.rpm                                                                                       | 259 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : zip-3.0-1.el6_7.1.x86_64                                                                                               1/2 
  Cleanup    : zip-3.0-1.el6.x86_64                                                                                                   2/2 
  Verifying  : zip-3.0-1.el6_7.1.x86_64                                                                                               1/2 
  Verifying  : zip-3.0-1.el6.x86_64                                                                                                   2/2 

Updated:
  zip.x86_64 0:3.0-1.el6_7.1                                                                                                              

Complete!

 

以后的包也可以加进来

#!/bin/bash
a=`find /var/cache/yum/x86_64/ -name "*.rpm*"`
for a1 in ${a[@]}
do
scp $a1 [email protected]:/var/www/yum/centos/7/
done

 

[[email protected] 7]# createrepo --update /var/www/yum/centos/7