Linux配置YUM源

RHEL 7(CentOS 7)配置本地YUM源

6/19/2018 10:23:46 PM

介绍:

在Redhat(CentOS)系统中,安装软件,需要解决软件安装的相互依赖关系,目前进行软件安装可以有三种方法,编译安装(Make),rpm包安装(源码包安装),和yum源安装。其中yum方法安装最简单,因为它可以自动解决软件包之间的依赖关系。这里使用已经下载的RedHat 软件安装包作为本地YUM源,来进行软件安装。

一、常用yum源

yum源可以来源于多种文件服务器:

http:// Web服务器
https:// 带STL加密的Web服务器
ftp:// FTP服务器
file:// 本地文件

常用的国内镜像yum源站点:

阿里源 https://mirrors.aliyun.com/centos/7.3.1611/os/x86_64/

清华大学 https://mirror.tuna.tsinghua.edu.cn/centos/7.3.1611/os/x86_64/

网易源 http://mirrors.163.com/centos/7.3.1611/os/x86_64/

yum的配置文件

cachedir=/var/cache/yum/$basearch/$releasever #yum下载后的缓存目录
keepcache=0    #是否缓存,0为不缓存,1为缓存
debuglevel=2
logfile=/var/log/yum.log  #yum的安装日志
exactarch=1
obsoletes=1
gpgcheck=1  #默认是否进行gpg校验,0为不校验,1校验
plugins=1
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

推荐使用阿里源或是清华源,同时使用者也可以根据所在地区选择连接速度快的的网络YUM源

注意:有repodata的目录的子目录为yum源的路径

3.repo文件介绍,命名为rhel.repo,如下配置:

[reponame]   #源名称,必填
name=rhel  #源描述,可以不填,但是会有提示
baseurl=file:///media/cdrom      #本地的光盘文件,可以有多个地址。必填
https://mirrors.aliyun.com/centos/7.3.1611/os/x86_64/
gpgcheck=1                    #是否开启校验,在yum.conf中已经定义它默认值为1
enabled=1                     #是否禁用此yum源,默认为
gpgkey=file:///media/cdrom/RPM-GPG-KEY-redhat-release
#如果开启yum源包校验,则需要导入RPM公钥,此处只是在系统没有导入rpm公钥时候进行安装
#这里相当于rpm --import RPM-GPG-KEY-redhat-release

[aliyun_epel]   #这是Redhat的扩展包
name=ailiyun_yum_epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/x86_64
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7
gpgcheck=1

所以,在配置yum源时候,最少只需要两行即可,[reponame]和baseurl:

一、创建挂载目录 mkdir /media/cdrom

二、切换到yum源中的配置目录cd /etc/yum.conf.d/

[root@linuxprobe ~]# cd /etc/yum.repos.d/
[root@linuxprobe yum.repos.d]# pwd
/etc/yum.repos.d

三、新建一个repo文件,命名为rhel.repo,如下配置:

[root@linuxprobe cdrom]# vim /etc/yum.repos.d/rhel.repo 

[rhel]
name=rhel
baseurl=file:///media/cdrom
enabled=1
gpgcheck=1
gpgkey=file:///media/cdrom/RPM-GPG-KEY-redhat-release

四、编辑/etc/fstab 配置文件,使其可以开机自动挂载

[root@linuxprobe ~]# vim /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed Mar 28 15:53:20 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=73a8b686-25cf-46e8-9f48-278f3850bafe /                       xfs     defaults        1 1
UUID=00f26059-fff8-4cdd-ba62-78b7aa0e0ec6 /boot                   xfs     defaults        1 2
UUID=4ae8d4f5-c99d-4e26-9b19-dbab3912d882 /home                   xfs     defaults        1 2
UUID=7af91647-5a8d-45fe-bce4-1423efde1ff5 swap                    swap    defaults        0 0
/dev/cdrom /media/cdrom iso9660 defaults 0 0      #挂载的CD镜像

五、清空原来yum缓存 yum clean all

[root@linuxprobe ~]# yum clean all 
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: rhel
Cleaning up everything

六、构建本地Yum源的缓存 yum makecache

[root@linuxprobe ~]# yum makecache 
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel                                                        | 4.1 kB  00:00:00     
(1/4): rhel/group_gz                                        | 136 kB  00:00:00     
(2/4): rhel/primary_db                                      | 3.6 MB  00:00:00     
(3/4): rhel/filelists_db                                    | 3.2 MB  00:00:00     
(4/4): rhel/other_db                                        | 1.4 MB  00:00:00     
Metadata Cache Created

七、测试Yum源是否可用

[root@linuxprobe ~]# yum install -y elinks.x86_64 
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package elinks.x86_64 0:0.12-0.36.pre6.el7 will be installed
--> Finished Dependency Resolution
..............
Running transaction
  Installing : elinks-0.12-0.36.pre6.el7.x86_64                                1/1 
  Verifying  : elinks-0.12-0.36.pre6.el7.x86_64                                1/1 

Installed:
  elinks.x86_64 0:0.12-0.36.pre6.el7                                               

Complete!

八、yum常见命令

yum命令选项

--nogpgcheck:禁止进行gpgcheck
-y: 自动回答为“yes”
-q:静默模式
--disablerepo=repoidglob:临时禁用此处指定的repo
--enablerepo=repoidglob:临时启用此处指定的repo
--noplugins:禁用所有插件

yum源列表

yum repolist [all|enabled|disabled]:显示仓库列表
yum grouplist:显示包组
yum list {available|installed|updates} :显示包列表
yum list vsftpd* 显示和vsftpd匹配的包

yum安装卸载

yum install package
yum restall package:重做
yum update package:更新包
yum check-update
yum remove package1 [package2] 卸载软件包

包组的安装基本和包的安装类似,只是在install,restall等操作前加上group即可。比如:yum -y groupinstall “Development Tools”,如果有空格,要使用双引号包括。

如果在安装系统时候,没有安装桌面,则可以使用此命令安装:yum -y groupinstall “GNOME Desktop”即可安装图形界面

yum查询

yum info 查看程序包信息
yum provides feature1
yum search xxx :搜索带有某个关键字的安装包

yum 缓存

yum makecache :构建缓存
yum clean all:清除所有缓存

yum 历史

yum history:显示yum操作历史,是按照/var/log/yum.log进行的查找
yum history info 6查看第六条信息
yum history undo 6:撤销第六步,如果第六步是安装,则执行此命令,将删除第六步所安装的程序,。如果第六步是卸载,那么执行此命令,则进行安装卸载掉的程序
yum history redo 6:重做第六步

参考:https://blog.csdn.net/qq_27754983/article/details/73693061

猜你喜欢

转载自blog.csdn.net/AMimiDou_212/article/details/80775023