自建yum仓库,分别为网络源和本地源
仅以博客形式记录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(GNU Private Guard),一种密钥方式签名 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源列表