Linux學習筆記之搭建私有yum倉庫與內網鏡像站服務器

搭建私有YUM倉庫

私有yum倉庫環境
系統版本:centos7.4
IP:172.16.0.1 #最好能夠訪問公網

私有yum倉庫服務端配置

第一步:創建使用yum倉庫存放路徑
[root@tencent ~]# mkdir /home/mirros/private -p

第二步:安裝必要軟件(yumdownloader這個命令在yum-utils工具裏,用來下載軟件包,但不需要安裝)
[root@tencent ~]# yum install createrepo yum-utils -y

第三步:上傳已經打包好的rpm包到/home/mirros/private
[root@tencent ~]# cd /home/mirros/private
lrzsz

#或則進入到該目錄,將軟件下載到此目錄,但是不安裝
[root@tencent ~]# yumdownloader openssl-*

第四步:初始化repodata索引文件(每次新放入一個rpm都需要更新索引,避免無法識別新加的)
[root@tencent ~]# createrepo -pdo /home/mirrors/private/ /home/mirrors/private/

#添加rpm包後的更新命令
[root@tencent ~]# createrepo --update /home/mirrors/private/

第五步:開啓http服務
[root@tencent ~]# cd /home/mirros/
[root@tencent ~]# python -m SimpleHTTPServer 80

客戶端配置

在使用私有源時,軟件包與base其他源一樣時,建議先禁用其他源。


[root@tencent ~]# cd /etc/yum.repos.d
[root@tencent ~]# vim Centos-private.repo

[private]
name=private
baseurl=http://172.16.0.1/private
enable=1  #1表示啓用,沒有此參數也表示啓用
gpgcheck=0

#重新建立緩存,並安裝軟件
[root@tencent ~]# yum clean all && yum makecache
[root@tencent ~]# yum install openssl-*

鏡像站環境

系統版本:centos7.4 IP:172.16.0.1  #要能訪問公網
centos及epel官方源,中國站(中科大鏡像站)http://mirrors.ustc.edu.cn
centos日常使用的軟件源介紹(base,extras,updates)
注意:中科大的rsync,每個ip同時只能同步兩條(注:其他鏡像源未嘗試)

內網鏡像服務器配置

第一步:安裝軟件
[root@tencent ~]# yum install rsync

第二步:同步軟件源
[root@tencent ~]# mkdir /home/mirrors/centos/7 -p
#同步centos7的base源
[root@tencent ~]# rsync -av rsync://mirrors.ustc.edu.cn/centos/7/os /home/mirrors/centos/7
#同步centos7的extras源
[root@tencent ~]# rsync -av rsync://mirrors.ustc.edu.cn/centos/7/extras /home/mirrors/centos/7
#同步centos7的updates源
[root@tencent ~]# 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官方維護的,但是包含很多軟件)
[root@tencent ~]# mkdir /home/mirrors/epel/7 -p
[root@tencent ~]# rsync -av rsync://mirrors.ustc.edu.cn/epel/7/ /home/mirrors/epel/7

第四步:要長期使用需要將上面同步命令,寫入定期執行文件,定期同步更新
可以將上述命令作爲一個shell腳本,然後採用contrab定期執行該腳本

第五步:啓動http服務
[root@tencent ~]# cd /home/mirrors
[root@tencent ~]# python -m SimpleHTTPServer 80

客戶端配置

第一步:將/etc/yum.repos.d/目錄下的官方源進行備份,並創建一個自己建立的鏡像源,如下
[root@tencent ~]# vim /etc/yum.repos.d/ccc.repo

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


第二:客戶端安裝epel源
#在安裝extras源後,默認是自帶並啓用的
[root@tencent ~]# yum install epel* -y

#編輯/etc/yum.repos.d/epel.repo文件
[root@tencent ~]# vim /etc/yum.repos.d/epel.repo

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://172.16.0.1/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://172.16.0.1/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://172.16.0.1/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
[root@tencent ~]# yum clean all && yum makecache

第二步:安裝軟件
[root@tencent ~]# yum install tree -y

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章