Centos 7 搭建本地yum源(離線yum倉庫)

來源:互聯網
上載者:User

Centos 7 搭建本地yum源(離線yum倉庫)
系統配置

  • 作業系統:Centos7
  • 軟體:
1. 建立yum倉庫目錄
mkdir -p /app/yum/centos6.6/x86_64
2. 安裝createrepo軟體

線上安裝

yum -y install createrepo

離線安裝 下載路徑

http://rpmfind.net/linux/rpm2html/search.php?query=createrepo 依賴軟體 http://rpmfind.net/linux/RPM/mageia/cauldron/armv5tl/media/core/release/createrepo-0.10.4-1.mga6.noarch.html

3. 初始化repodata索引檔案

createrepo -pdo /app/yum/centos6.6/x86_64 /app/yum/centos6.6/x86_64

4. 提供yum服務
# 可以用Apache或nginx提供web服務,但用Python的http模組更簡單,適用於內網環境cd /app/yum/centos6.6/x86_64 python -m SimpleHTTPServer 80 &>/dev/null &可以通過瀏覽器輸入本機IP查看。
5. 添加新的rpm包
# 只下載軟體不安裝yumdownloader pcre-devel openssl-devel createrepo --update /app/yum/centos6.6/x86_64/   # 每加入一個rpm包就要更新一下

平時yum安裝軟體時不刪除安裝包

# cat /etc/yum.conf keepcache=1# 安裝包儲存目錄cachedir=/var/cache/yum/$basearch/$releasever# /var/cache/yum/x86_64/6/base/packages
6. 用戶端配置
# cd /etc/yum.repos.d[root@B yum.repos.d]# vi oldboy.repo[oldboy]name=Serverbaseurl=http://10.0.0.5enable=1gpgcheck=0[root@YUM ~]# yum --enablerepo=oldboy --disablerepo=base,extras,updates,epel list # 指定使用oldboy庫上面是臨時使用內網yum源,想永久並簡單使用yum -y install lrzsz命令,就需要修改設定檔將預設的repo檔案關閉。[root@oldboy ~]# cd /etc/yum.repos.d/[root@oldboy yum.repos.d]# vim CentOS-Base.repo# 在每一個啟動的源加上# enabled=0   #改為1就啟用,沒有此參數也是啟用。[base]…………enabled=0[updates]…………enabled=0[extras]…………enabled=0# 還有其他開啟的倉庫就使用這個辦法關閉。
7. 鏡像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包只佔用了21G,全部同步需要300G左右。# 同步base源,小技巧,我們安裝系統的光碟片鏡像含有部分rpm包,大概3G,這些就不用重新下載。/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/os/x86_64/ /data/yum_data/centos/6/os/x86_64//usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/extras/x86_64/ /data/yum_data/centos/6/extras/x86_64//usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/updates/x86_64/ /data/yum_data/centos/6/updates/x86_64/# epel源/usr/bin/rsync -av --exclude=debug rsync://mirrors.ustc.edu.cn/epel/6/x86_64/ /data/yum_data/epel/6/x86_64/學生使用內網yum源方法# 可以自建一個內網dns,如果沒有,可使用hosts解析。echo '192.168.0.200 mirrors.aliyun.com' >>/etc/hosts結果展示[root@KVM data]# du -sh yum_data    21G     yum_data[root@KVM data]# tree -L 3 yum_data/yum_data/├── centos│   ├── 6│   │   ├── extras│   │   ├── os│   │   └── updates│   └── RPM-GPG-KEY-CentOS-6├── epel│   └── 6│       └── x86_64

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.