自建yum倉庫,分別為網路源和本地源
阿新 • • 發佈:2020-07-16
僅以部落格形式記錄linux所學,不足之處繼續優化
在windows上安裝軟體時我們一般需要將軟體從網頁上下載下來,然後安裝。在linux,想要安裝軟體,方法比較多。
1,如果是軟體所在位置來看,有本地,或者其他yun伺服器。
2,按照軟體包的檔案形式來看有原始碼包和rpm軟體包。
rpm包安裝有直接的rpm包安裝或者現在為了解決rpm包安裝時的依賴問題的yum(dnf)安裝。yum安裝本質上還是底層呼叫rpm包安裝。
接下來為第一種情況來配置yum源,在yum安裝軟體包時,yum時根據系統的yum源的配置來安裝軟體的。yum源所指是本地的檔案就是本地源,指向其他伺服器就是網路源。
在yum安裝軟體時就會去yum所指的檔案路徑中去尋找軟體,找不到就會報錯。
yum源配置檔案主要有2個。
/etc/yum.conf:為所有倉庫提供公共配置
/etc/yum.repos.d/*.repo 這裡面的*.repo檔案。為倉庫的指向提供配置
[root@localhost html]# vim /etc/yum.conf [main] cachedir=/var/cache/yum/$basearch/$releasever #yum下載的RPM包的快取目錄 keepcache=0 #快取是否儲存,1儲存,0不儲存 debuglevel=2 #除錯級別(0-10),預設為2(具體除錯級別的應用,我也不瞭解)logfile=/var/log/yum.log #yum的日誌檔案所在的位置 exactarch=1 #在更新的時候,是否允許更新不同版本的RPM包,比如是否在i386上更新i686的RPM包 obsoletes=1 #這是一個update的引數,具體請參閱yum(8),簡單的說就是相當於upgrade,允許更新陳舊的RPM包 gpgcheck=1 #是否檢查GPG(GNUPrivateGuard),一種金鑰方式簽名 plugins=1 #是否允許使用外掛,預設是0不允許,但是我們一般會用yum-fastestmirror這個外掛 installonly_limit=5 #允許保留多少個核心包 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release # This is the default, if you make this bigger yum won't see if the metadata # is newer on the remote and so you'll "gain" the bandwidth of not having to # download the new metadata and "pay" for it by yum not having correct # information. # It is esp. important, to have correct metadata, for distributions like # Fedora which don't keep old packages around. If you don't like this checking # interupting your command line usage, it's much better to have something # manually check the metadata once an hour (yum-updatesd will do this). # metadata_expire=90m # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d #說明.repo放在/etc/yum.repos.d/下
[root@localhost 7]# cat /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever - Base #yum源名字,寫什麼無所謂。 mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra #說明yum源位置 #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ gpgcheck=1 #這個選項表示這個repo中下載的rpm將進行gpg的校驗,已確定rpm包的來源是有效和安全的
enabled=1 ##這個選項表示這個repo中定義的源是啟用的,0為禁用 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS- #定義用於校驗的gpg金鑰
一般在.repo檔案中設定baseurl就是yum源位置
本地源一般是baseurl=///file:xxxx
網路源一般是baseurl=http://
https://
ftp://
下面填2段程式碼,分別是我設定的本地源和網路源。
其中本地源是將光碟映象掛載到系統中
[base] name = cdrom base baseurl = file:///misc/cd gpgcheck = 0
網路源是aliyun源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #可以直接下載遠端的aliyun源進行覆蓋原有的yum源 # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
yum源建立之後如果想要立刻使用,需要清空之前yum源的快取,重新建立新yum源快取
yum clean all #清空快取
yum makecache #建立新快取
yum repolist #檢視yum源列表