yum介绍
yum命令是在Fedora和RedHat以及SUSE中基于rpm的软件包管理器,它可以使系统管理人员交互和自动化地管理RPM软件包,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。
#
yum结构#
yum配置文件cat /etc/yum.conf
[main]cachedir=/var/cache/yum/$basearch/$releasever #yum下载后的缓存目录keepcache=0 #是否缓存,0为不缓存,1为缓存debuglevel=2logfile=/var/log/yum.log #yum的安装日志exactarch=1obsoletes=1gpgcheck=1 #默认是否进行gpg校验,0为不校验,1校验plugins=1installonly_limit=5bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yumdistroverpkg=centos-release......# PUT YOUR REPOS HERE OR IN separate files named file.repo# in /etc/yum.repos.d 说明repo放在/etc/yum.repo.d目录中,并且以.repo结尾proxy=http://your.proxy.com
#
yum镜像源说明#
镜像源存放地址/etc/yum.repos.d
#
基础镜像源/etc/yum.repos.d/CentOS-Base.repo
[base] #源名称,必填name=CentOS-$releasever - Base #源描述,可以不填,但是会有提示#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra #镜像服务器的地址列表,里面有很多的服务器地址baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ #本地的光盘文件,可以有多个地址。必填gpgcheck=1 #是否开启校验,在yum.conf中已经定义它默认值为1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #如果开启yum源包校验,则需要导入RPM公钥,此处只是在系统没有导入rpm公钥时候进行安装#这里相当于rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
注意:在配置repo时必须保证以下配置
[reponame]baseurl=http://xxxx
#
yum相关命令
yum search vim
查询软件包
yum install vim
安装软件包
yum remove vim
卸载软件包
#
常用安装软件镜像安装软件镜像有两个方法
- 是手动配置镜像信息
- 用
yum-config-manager
管理yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
#
配置nginx镜像源[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/7/$basearch/gpgcheck=0enabled=1 #当某个软件仓库被配置成 enabled=0 时,yum 在安装或升级软件包时不会将该仓库做为软件包提供源。使用这个选项,可以启用或禁用软件仓库
#
yum踩坑#
yum命令无法运行Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was14: HTTP Error 503 - Service UnavailableLoading mirror speeds from cached hostfile One of the configured repositories failed (Unknown), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid> or subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true Cannot find a valid baseurl for repo: updates/7/x86_64
#
原因mirrorlist.centos.org地址无法访问
#
解决方案注释 /etc/yum.repos.d/CentOS-Base.repo 中的mirrorlist配置放开baseurl 配置如果还是不可以修改vim /etc/resolv.conf 添加 nameserver 8.8.8.8 配置,最后service network restart 重启网络服务还是不行?第一步:备份你的原镜像文件,以免出错后可以恢复。mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup第二步:下载新的CentOS-Base.repo 到/etc/yum.repos.d/CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repoCentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo