Linux软件安装管理(三)-Yum在线安装

1、Yum源文件

路径:[root@localhost ~]# cd /etc/yum.repos.d/

这里写图片描述

说明:默认生效文件:CentOS-Base.repo ,其他几个文件不默认不生效

vim /etc/yum.repos.d/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

说明:

[base] 容器名称,一定要放在[]中
name 容器说明,可以自己随便写
mirrorlist 镜像站点,这个可以注释掉 ,mirrorlist和baseurl两者都可以有,或者有其一即可,根据实际情况进行选择
baseurl 我们的yum源服务器的地址。默认是CentOS官方的yum源服务器,是可以使用的,如果觉得慢可以改成你喜欢的yum源地址
enabled 此容器是否生效,如果不写或者写成enabled=1都是生效,enabled=0不生效
gpgcheck 1:rmp的数字证书生效 0:不生效,建议设置为1,进行官方检测
gpgkey 数字证书的公钥文件保存位置,不用修改

redhat中yum需要收费

2、搭建本地yum源

2-1光盘挂载
#建立挂载点
mkdir /mnt/cdrom
#挂载光盘
mount /dev/cdrome /mnt/cdrome
2-2使网络yum源失效,本地源生效

进入yum源配置目录

cd /etc/yum.repos.d/

修改yum源文件后缀名,使其生效

mv CentOS-Base.repo CentOS-Base.repo.bak

修改CentOS-Media.repo配置文件,使其生效

vim CentOS-Media.repo

# CentOS-Media.repo
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  CentOS-6.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c6-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c6-media [command]

[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/cdrom/   修改路径为光盘挂载点的路径
#        file:///media/cdrom/   定格注释掉,否则会报错
#        file:///media/cdrecorder/  定格注释掉,否则会报错
gpgcheck=1
enabled=1    修改为1,默认是0,使其生效
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
~                                                       

保存,退出。

检查配置是否生效

yum list

3、yum 命令

3-1 查询

查询所有可用软件列表

yum list

搜索服务器上所有和关键字相关的包

yum search 关键字
3-2 安装
yum -y install 包名 

选项:

install 安装
-y 自动回答yes
包全名只针对rpm包安装,yum安装使用包名

例如:安装c语言编译器

yum install -y gcc
3-3 yum 升级

升级是需要付出代价的。除非爆发安全大漏洞,否则不要经常升级。能不能做升级就不做升级。

yum -y update 包名

一定尽量不要执行 ,执行此命令会升级linux所有的软件包,包括内核

yum -y update
3-4 卸载
yum -y remove 包名

说明:

服务器使用最小化安装
用什么软件安装什么软件,尽量不卸载,因为软件有相互依赖,卸载后可能导致其他软件不可用。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值