搭建局域網YUM倉庫

 

環境: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

 

相關文章
相關標籤/搜索