搭建私有YUM仓库_及_内网镜像站

搭建私有YUM仓库(自己定制的rpm包)
私有yum仓库环境
系统版本:centos7.4 IP:192.168.1.47 #最好能上公网

私有yum仓库服务端配置

第一:创建使用yum仓库存放路径
  mkdir /home/mirros/siyou -p


第二:安装必要软件(yumdownloader这个命令在yum-utils工具里,用来下载软件包,但不安装)
  yum install createrepo yum-utils -y


第三:上传自己打包好的rpm包到/home/mirros/siyou
  cd /home/mirros/siyou
  lrzsz
  #或则进入到该目录,将软件下载到此目录,但是不安装
  yumdownloader openssl-*


第四:初始化repodata索引文件(每新放入一个rpm都需要更新索引,不让识别不到新加的)
  createrepo -pdo /home/mirrors/siyou/ /home/mirrors/siyou/
  #下面是添加rpm包后的更新命令
  createrepo --update /home/mirrors/siyou/


第五:提供http服务
  cd /home/mirros/
  python -m SimpleHTTPServer 80

客户端配置(在使用私有源时,软件包与base其他源一样时,建议先禁用其他源)

  cd /etc/yum.repos.d
  vim Centos-siyou.repo


[siyou]
name=siyou
baseurl=http://192.168.1.47/siyou
enable=1  #1表示启用,没有此参数也表示启用
gpgcheck=0


#重建缓存,并安装软件
  yum clean all && yum makecache
  yum install openssl-*

搭建内网镜像站(相当于开源镜像站)

镜像站环境
系统版本:centos7.4 IP:192.168.1.47 #要能上公网

centos及epel官方源,中国站(中科大镜像站)http://mirrors.ustc.edu.cn
centos日常使用的软件源介绍(base,extras,updates)
注意:中科大的rsync,每个ip同时只能同步两条

内网镜像服务器配置

第一:安装软件
  yum install rsync


第二:同步软件源
  #同步centos7的base源
  mkdir /home/mirrors/centos/7 -p
  rsync -av rsync://mirrors.ustc.edu.cn/centos/7/os /home/mirrors/centos/7


  #同步centos7的extras源
  rsync -av rsync://mirrors.ustc.edu.cn/centos/7/extras /home/mirrors/centos/7


  #同步centos7的updates源
  rsync -av rsync://mirrors.ustc.edu.cn/centos/7/updates /home/mirrors/centos/7


+++++++++++++++++++++++++++++
或则省去前面三步,直接同步centos7的官方源
  rsync -av rsync://mirrors.ustc.edu.cn/centos/7 /home/mirrors/centos


  #简单同步一个分支的所有信息
  rsync -av rsync://mirrors.ustc.edu.cn/centos/7.4.1708 /home/mirrors/centos/


第三:添加epel源同步(epel源是扩展的,不是centos官方维护的,但是包含很多软件)
  mkdir /home/mirrors/epel/7 -p
  rsync -av rsync://mirrors.ustc.edu.cn/epel/7/ /home/mirrors/epel/7




第四:要长期使用需要将上面同步命令,写入定期执行文件,定期同步更新




第五:启动http
  cd /home/mirrors
  python -m SimpleHTTPServer 80

客户端配置

第一:备份/etc/yum.repo/目录下的官方源,并创建一个自己的源,如下


  vim /etc/yum.repo/ccc.repo


[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://192.168.1.47/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=http://192.168.1.47/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=http://192.168.1.47/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7




第二:客户端怎么安装epel源
  #在安装extras源后,默认是自带并启用的
  yum install epel* -y


  #编辑/etc/yum.repo/epel.repo文件
  vim /etc/yum.repo/epel.repo


[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://192.168.1.47/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7


[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://192.168.1.47/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1


[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://192.168.1.47/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

客户端使用

第二:清除缓存,并重建makecache
  yum clean all && yum makecache


第三:安装软件
  yum install tree -y