环境:python
YUM仓库 192.168.1.221nginx
客户端 192.168.1.245web
一.建立yum仓库目录,安装createrepo软件数据库
~]# mkdir -p /apps/localrepo/x86_64/vim
~]# yum install createrepo -ycentos
二.初始化repodata索引文件浏览器
~]# createrepo -pdo /apps/localrepo/x86_64/ /apps/localrepo/x86_64/缓存
#目录下会生成repodata并还会生成子文件repomd.xml和几个压缩包服务器
三.提供YUM服务app
#能够用Apache或nginx提供web服务,但用python的http模块更简单,适用于内网环境
~]# cd /apps/localrepo/x86_64/
~]# python -m SimpleHTTPServer 80 &>/dev/null &
#能够经过浏览器访问本机IP查看
四.能够本身添加想要的rpm包
~]# yum install rpm-build --downloadonly --downloaddir=/apps/localrepo/x86_64/repodata/ -y #只下载不安装rpm包
~]# createrepo --update /apps/localrepo/x86_64/ #每加入一个rpm包就用此命令更新一下YUM仓库
五.镜像YUM源
#上面只是将本身制做的rpm包,放入yum源。但还有一种企业需求,说的更具体一点,平时学生上课yum安装软件都是从公网下载的,占用带宽,所以在学校里搭建一个内网yum服务器,但又考虑到学生回家也要使用yum安装软件,若是yum软件的数据库文件repodata不同,就会有问题。所以我想到的解决方法就是直接使用公网yum源的repodata。
镜像同步公网yum源
上游yum源必需要支持rsync协议,不然不能使用rsync进行同步。
http://mirrors.ustc.edu.cn/status/
CentOS官方标准源:rsync://mirrors.ustc.edu.cn/centos/
epel源:rsync://mirrors.ustc.edu.cn/epel/
同步命令:
# 使用rsync同步yum源,为了节省带宽、磁盘和下载时间,我只同步了CentOS6的rpm包,这样全部的rpm包只占用了20+G,所有同步须要300G左右
~]# mkdir -p /apps/localrepo/x86_64/repodata/{os,extras,updates,epel}
~]# /usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/os/x86_64/ /apps/localrepo/x86_64/repodata/os
~]# /usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/extras/x86_64/ /apps/localrepo/x86_64/repodata/extras/
~]# /usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/updates/x86_64/ /apps/localrepo/x86_64/repodata/updates/
#同步epel源
~]# /usr/bin/rsync -av --exclude=debug rsync://mirrors.ustc.edu.cn/epel/6/x86_64/ /apps/localrepo/x86_64/repodata/epel/
#新增长了包更新一下YUM仓库
#复制本地RPM-KEY到新YUM库
~]# cp /etc/pki/rpm-gpg/RPM* /apps/localrepo/x86_64/repodata/
六.客户端配置
#操做前先将/etc/yum.repos.d/的repo文件所有备份到别的目录下
~]# cd /etc/yum.repos.d/
yum.repos.d]# vim local.repo #手动建立local.repo
[local]
name=Local
baseurl=http://192.168.1.221
enabled=1
gpgcheck=0
yum.repos.d]# vim CentOS-Base.repo #手动建立CentOS-Base.repo
[base]
name=os
baseurl=http://192.168.1.221/repodata/os/
gpgcheck=1
gpgkey=http://192.168.1.221/repodata/RPM-GPG-KEY-CentOS-6
enabled=0
[updates]
name=updates
baseurl=http://192.168.1.221/repodata/updates/
gpgcheck=1
gpgkey=http://192.168.1.221/repodata/RPM-GPG-KEY-CentOS-6
enabled=0
[extras]
name=extras
baseurl=http://192.168.1.221/repodata/extras/
gpgcheck=1
gpgkey=http://192.168.1.221/repodata/RPM-GPG-KEY-CentOS-6
enabled=0
#重建YUM数据库缓存
yum.repos.d]# yum clean all
yum.repos.d]# yum makecache