software 1.2 yum 管理 RPM 包

一、yum 管理

RPM包的安装虽然很方便和快捷,但是依赖性实在是很麻烦,尤其是库文件依赖,还要去rpmfind网站查找库文件到底属于哪个RPM包,从而导致RPM包的安装非常烦琐。

yum在线管理就可以自动处理RPM包的依赖性问题,从而大大简化RPM包的安装过程。但是需要注意:首先,yum安装安装的还是RPM包;其次,yum安装是需要有可用的yum服务器存在的,当然这个yum服务器可以在网上,也可以使用光盘在本地搭建。

yum源既可以使用网络yum源,也可以使用本地光盘作为yum源。

要使用网络yum源,那么你的主机必须是正常联网的。
当然,要使用yum进行RPM包安装,那么必须安装yum软件。

查看 yum 是否安装了

[root@ecs-21d3-0001 ~]# rpm -qa | grep yum
yum-plugin-fastestmirror-1.1.30-42.el6_10.noarch
yum-plugin-security-1.1.30-42.el6_10.noarch
yum-metadata-parser-1.1.2-16.el6.x86_64
yum-3.2.29-81.el6.centos.0.1.noarch
yum-utils-1.1.30-42.el6_10.noarch

至于搭建本地光盘 yum 源,用不上就不学了。

二、网络 yum 源服务器搭建

在主机网络正常的情况下,CentOS 的 yum 是可以直接使用的。
yum 源配置文件保存在 /etc/yum.repos.d/ 目录中,文件的扩展名一定是 “.repo”.
也就是说,yum 源 配置文件只要扩展名是 “
.repo” 就会生效。

-rw-r--r--  1 root root  187 Jul 30 23:16 CentOS-Base.repo
-rw-r--r--. 1 root root  647 Jun 26  2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  289 Jun 26  2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Jun 26  2018 CentOS-Media.repo
-rw-r--r--. 1 root root 8854 Jun 26  2018 CentOS-Vault.repo

默认情况下是 CentOS-Base.repo 文件生效。
查看这个文件

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

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#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://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

在 CentOS-Base.repo 文件中有 5 个 yum 源容器,这个分析一下 base 容器,其他容器都是类似的。

[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
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  • [base]:容器名称,一定要放在【】中
  • name:容器说明,可以随便写
  • mirrorlist:镜像站点,可以注释掉
  • baseurl:yum 源服务器的地址。默认是 CentOS 官方的 yum 源 服务器,是可以使用的。如果觉得慢,可以改成自己喜欢的 yum 源。
  • enabled:此容器是否生效,如果不写则默认为1,也就是生效。enable = 0 表示不生效。
  • gpgcheck:如果为1则表示 RPM 的数字证书生效,
  • gpgkey:数字证书的公钥文件保存位置。不用修改。

yum 源配置文件默认不需要进行任何修改就可以使用,只要网络可用就行。

三、修改 yum 源

官方 yum 源太慢了,就像 maven 仓库一样,我们一般都选择修改为国内镜像。

修改yum源,就是修改CentOS-Base.repo的内容,所以要先备份一下原来的:

mv CentOS-Base.repo CentOS-Base.repo.backup

我喜欢中科大,不管是centos还是Ubuntu。因为只有在中科大的时候我试成功了。(也可能是在另外两个有什么没发觉得错误呢)

1. 中科大

CentOS7
sudo wget -O CentOS-Base.repo https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=3
CentOS6
sudo wget -O CentOS-Base.repo https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=2
CentOS5
sudo wget -O CentOS-Base.repo https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=1

2. 阿里

CentOS7
sudo wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
CentOS6
sudo wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS5
sudo wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

3. 网易

CentOS7
sudo wget -O CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
CentOS6
sudo wget -O CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo

CentOS5
sudo wget -O CentOS-Base.repo http://mirrors.163.com/.help/CentOS5-Base-163.repo

四、命令

1. 查询

要安装某个软件,像我们之前说的要看看这个软件是否已经安装了,类似于 mysql -v 这样式的。这儿的查询只是查询 yum 服务器上是否有某个包。

  1. 查询可安装列表
[root@localhost yum.repos.d]# yum list
  1. 查询yum源服务器中是否包含某个软件包。
[root@localhost yum.repos.d]# yum list 包名
#查询单个软件包
例如:
[root@localhost yum.repos.d]# yum list samba
Available Packages
samba.i686              3.5.10-125.el6                   c6-media

2. 安装

[root@localhost yum.repos.d]# yum -y install 包名
选项:
    install     安装
    -y          自动回答yes。如果不加-y,那么每个安装的软件都需要手工回答yes
例如:
[root@localhost yum.repos.d]# yum -y install gcc
#使用yum自动安装gcc

3. 升级

[root@localhost yum.repos.d]# yum -y update 包名
#升级指定的软件包
选项:
    update:    升级
    -y:        自动回答yes

4. 卸载

[root@localhost yum.repos.d]# yum remove 包名
#卸载指定的软件包

注意:一般不要用 yum 来卸载,要执行yum的卸载,因为很有可能在卸载软件包的同时卸载的依赖包也是重要的系统文件,这就有可能导致系统崩溃。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值