zoukankan      html  css  js  c++  java
  • linux配置yum源

    yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。基於RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。

    --1.1 实验环境

    RHEL6:虚拟机

    --1.2 挂载光驱

    (在VMware虚拟机下,可共享主机本地磁盘上的解压后的镜像文件,直接copy里面的Packages目录到/opt/rpm/local_repo/) [root@redhat6 yum.repos.d]# mount /dev/cdrom /mnt    

    mount: block device /dev/sr0 is write-protected, mounting read-only 备注:将光盘 ISO 文件挂载到目录 /mnt 

    卸载:umount /mnt

    ========

    如果是iso镜像文件,挂载方式如下:

    #mkdir -p /opt/rpm/local_repo/

    #mount -o loop -t iso9660 /tmp/rhel-server-6.3-x86_64-dvd.iso   /mnt --之后,可在/mnt目录下看到iso镜像里的所有文件。

    把/mnt/Packages下的所有rpm名拷贝到/opt/rpm/local_repo

    --1.3 创建本地目录,用来 copy 光盘包

    [root@redhat6 local_repo]# mkdir -p /opt/rpm/local_repo

    --1.4 copy RPM 包到指定目录

    [root@redhat6 log]# cd /mnt/Packages/

    [root@redhat6 Packages]# cp * /opt/rpm/local_repo

    --1.5 安装 createrepo 包

    [root@redhat6 local_repo]# rpm -ivh createrepo-0.9.8-4.el6.noarch.rpm

    warning: createrepo-0.9.8-4.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY error: Failed dependencies:         deltarpm is needed by createrepo-0.9.8-4.el6.noarch        

    python-deltarpm is needed by createrepo-0.9.8-4.el6.noarch You have new mail in /var/spool/mail/root

    --1.5.1根据提示,安装需要的包

     [root@redhat6 local_repo]# rpm -ivh deltarpm-3.5-0.5.20090913git.el6.i686.rpm

    warning: deltarpm-3.5-0.5.20090913git.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing...                ########################################### [100%]    1:deltarpm               ########################################### [100%]

    [root@redhat6 local_repo]# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm

    warning: python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing...                ########################################### [100%]    1:python-deltarpm        ########################################### [100%]

    [root@redhat6 local_repo]# rpm -ivh createrepo-0.9.8-4.el6.noarch.rpm

    warning: createrepo-0.9.8-4.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing...                ########################################### [100%]    1:createrepo             ########################################### [100%]          备注:createrepo 包安装成功   

    --1.6 创建 repo 数据库  

    [root@redhat6 local_repo]# createrepo -d /opt/rpm/local_repo

    1944/2804 - MAKEDEV-3.24-6.el6.i686.rpm                                       

      iso-8859-1 encoding on Ville Skytt?ville.skytta@iki.fi> - 2.8.2-2

    2804/2804 - perl-Archive-Extract-0.38-119.el6_1.1.i686.rpm      Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete     

    ===============

    补充说明:

    使用-g参数指定分组文件:-g GROUPFILE, --groupfile=GROUPFILE 如果不加该参数,yum group list...不可用;分组文件在iso镜像文件里的repodata目录下,一般是这种格式:xxx-comps-xxx.xml

                 -d, --database create sqlite database files: now default, see --no-database to disable

    所以要使用该命令来创建repo数据库:createrepo -g /../xxxxx-comps-Server.x86_64.xml  /opt/rpm/local_repo   //-d参数可以不要

    ===============       

    备注:这个步骤需要点时间。 (配置完成)

    --1.7 编写 /etc/yum.repos.d/local_repo.repo 文件

       文件 /etc/yum.repos.d/local_repo.repo   内容如下。

     [rhel-source]
    name=Red Hat Enterprise Linux Local repo  
    ##仓库描述
    baseurl=file:///opt/rpm/local_repo        
    ##软件仓库位置
    enabled=1                                 
    ##是否启用
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release  
    ##签名秘钥

    =======================================

    关于gpgkey的值说明:应该填写什么值要到/etc/pki/rpm-gpg目录下去查看。根据自己安装的操作系统来填写相应的值。

    或者简单粗暴的方法是把配置文件里gpgcheck=0,不要做签名检查。但是不安全,建议生产环境还是要gpgcheck=1。然后导入rpm包的公钥,之后再安装红帽签名的rpm包时就不会报错了。

    [root@localhost rpm-gpg]# pwd
    /etc/pki/rpm-gpg
    [root@localhost rpm-gpg]# ls
    RPM-GPG-KEY RPM-GPG-KEY-fedora RPM-GPG-KEY-fedora-test RPM-GPG-KEY-oracle

    ========================================================================================================

    补充:三条命令完成YUM源配置

    如果是自己在虚拟机里测试,配置yum源最简单的方法是使用yum-config-manager工具(在RHEL7系统中)。

    # mount /dev/cdrom /mnt
    # yum-config-manager --add-repo="file:///mnt"
    # vi /etc/yum.repos.d/mnt.repo
        gpgcheck=0 

    [root@rhel2 ~]# mount /dev/cdrom /mnt #插入光驱,并挂载到/mnt目录下
    [root@rhel2 ~]# cd /etc/yum.repos.d/
    [root@rhel2 yum.repos.d]# rm -rf *   #把原来的yum配置文件删除,或者不删除也没关系,这里主要是为了演示
    [root@rhel2 yum.repos.d]# ll
    total 0
    [root@rhel2 yum.repos.d]# yum-config-manager --add-repo="file:///mnt"   #引号里为YUM repo路径。如果是其它路径,比如http或ftp路径,注意修改。
    Loaded plugins: langpacks, product-id
    adding repo from: file:///mnt
    
    [mnt]
    name=added from: file:///mnt
    baseurl=file:///mnt
    enabled=1
    
    [root@rhel2 yum.repos.d]# ll   #之后会自动生成mnt.repo文件
    total 4
    -rw-r--r--. 1 root root 67 Nov 16 00:40 mnt.repo
    [root@rhel2 yum.repos.d]# vi mnt.repo 
    
    [mnt]
    name=added from: file:///mnt
    baseurl=file:///mnt
    enabled=1
    gpgcheck=0    #默认是没有这一行的,需要手动添加。之后就可以使用yum命令来安装软件包了。生产环境建议gpgcheck=1,然后使用下面的命令导入签名文件。
    
    "mnt.repo" 6L, 77C written
    [root@rhel2 yum.repos.d]# ll /etc/pki/rpm-gpg/   #下面这些是红帽系统自身的RPM包的公钥。如果是生产环境中,需要把gpgchec修改为1,然后用命令导入这些RPM签名公钥文件。
    total 20
    -rw-r--r--. 1 root root 3375 Jun 29 02:36 RPM-GPG-KEY-redhat-beta
    -rw-r--r--. 1 root root 1990 Jun 29 02:36 RPM-GPG-KEY-redhat-legacy-former
    -rw-r--r--. 1 root root 1164 Jun 29 02:36 RPM-GPG-KEY-redhat-legacy-release
    -rw-r--r--. 1 root root  885 Jun 29 02:36 RPM-GPG-KEY-redhat-legacy-rhx
    -rw-r--r--. 1 root root 3211 Jun 29 02:36 RPM-GPG-KEY-redhat-release
    [root@rhel2 yum.repos.d]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-*   #建议导入所有
    [root@rhel2 yum.repos.d]# 
    [root@localhost ~]# yum clean all  --清除一下缓存
    Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
    This system is not registered with an entitlement server. You can use subscription-manager to register.
    Cleaning repos: mnt_cdrom
    Cleaning up everything
    Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
    [root@localhost ~]# yum repolist --查看repolist
    Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
    This system is not registered with an entitlement server. You can use subscription-manager to register.
    mnt_cdrom                                                                                                                   | 4.1 kB  00:00:00     
    (1/2): mnt_cdrom/group_gz                                                                                                   | 137 kB  00:00:00     
    (2/2): mnt_cdrom/primary_db                                                                                                 | 4.0 MB  00:00:00     
    repo id                                                     repo name                                                                        status
    mnt_cdrom                                                   added from: file:///mnt/cdrom                                                    4,986
    repolist: 4,986
    [root@localhost ~]# 

    二 、yum 源测试

    yum的命令形式一般是如下:

    yum [options] [command] [package ...]

    其中的[options]是可选的,选项包括-h(帮助),-y(当安装过程提示选择全部为"yes"),-q(不显示安装的过程)等等。[command]为所要进行的操作,[package ...]是操作的对象。

    概括了部分常用的命令包括:

    自动搜索最快镜像插件:   yum install yum-fastestmirror

    安装yum图形窗口插件:    yum install yumex

    查看可能批量安装的列表: yum grouplist

    1 安装 yum install 全部安装 yum install package1 安装指定的安装包package1 yum groupinsall group1 安装程序组group1

    2 更新和升级 yum update 全部更新 yum update package1 更新指定程序包package1 yum check-update 检查可更新的程序 yum upgrade package1 升级指定程序包package1 yum groupupdate group1 升级程序组group1

    3 查找和显示 yum info package1 显示安装包信息package1 yum list 显示所有已经安装和可以安装的程序包 yum list package1 显示指定程序包安装情况package1 yum groupinfo group1 显示程序组group1信息yum search string 根据关键字string查找安装包

    4 删除程序 yum remove | erase package1 删除程序包package1 yum groupremove group1 删除程序组group1 yum deplist package1 查看程序package1依赖情况

    5 清除缓存 yum clean packages 清除缓存目录下的软件包 yum clean headers 清除缓存目录下的 headers yum clean oldheaders 清除缓存目录下旧的 headers yum clean, yum clean all (= yum clean packages; yum clean oldheaders) 清除缓存目录下的软件包及旧的headers  be disabled. Setting up Insta

    《FROM:http://francs3.blog.163.com/blog/static/40576727201221644041342/

    四、错误处理:

    [root@localhost rpm-gpg]# yum install ksh  --执行yum安装测试时发生错误,如下:
    已加载插件:langpacks
    http://public-yum.oracle.com/repo/OracleLinux/OL7/UEKR3/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: public-yum.oracle.com; 未知的错误"
    正在尝试其它镜像。


    One of the configured repositories failed (Latest Unbreakable Enterprise Kernel for Oracle Linux 7Server (x86_64)),
    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. Disable the repository, 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 ol7_UEKR3

    4. 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=ol7_UEKR3.skip_if_unavailable=true

    failure: repodata/repomd.xml from ol7_UEKR3: [Errno 256] No more mirrors to try.
    http://public-yum.oracle.com/repo/OracleLinux/OL7/UEKR3/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: public-yum.oracle.com; 未知的错误"

    错误分析:从上面可看出,在执行Yum安装时应该没有用到我们配置文件 /etc/yum.repos.d/local_repo.repo.

    查看/etc/yum.repos.d目录:

    [root@localhost yum.repos.d]# ls
    local_repo.repo public-yum-ol7.repo
    [root@localhost yum.repos.d]# pwd
    /etc/yum.repos.d
    [root@localhost yum.repos.d]# mv public-yum-ol7.repo public-yum-ol7.repo_bak  --把原来的配置文件备份

    安装测试:--正常

    [root@localhost yum.repos.d]# yum install ksh
    已加载插件:langpacks
    正在解决依赖关系
    --> 正在检查事务
    ---> 软件包 ksh.x86_64.0.20120801-19.el7 将被 安装
    --> 解决依赖关系完成

    依赖关系解决

    ===================================
    Package 架构 版本 源 大小
    ====================================
    正在安装:
    ksh x86_64 20120801-19.el7 oracle-linux-source 878 k

    事务概要
    =========================================
    安装 1 软件包

    总下载量:878 k
    安装大小:3.1 M
    Is this ok [y/d/N]:

    ……

    ==========步骤说明======================================

    第1步:在虚拟机软件里选中光盘iso镜像

    第2步:将光盘设备挂载到/media/cdrom目录

    # mkdir -p /media/cdrom

    # mount /dev/cdrom /media/cdrom

    第3步:把Packages目录拷贝到其它地方,并创建yum库

    #cp -rf /media/cdrom/Packages /opt/local_repo/

    #createrepo -d /opt/local_repo/Packages

    第4步:使用Vim编辑器创建Yum仓库的配置文件

    #vi /etc/yum.repos.d/rhel6.repo
    [rhel6]
    name=rhel6
    baseurl=file:///opt/local_repo/Packages
    enabled=1
    gpgcheck=0
    

     ==================

    RHEL7-配置本地YUM源:

    http://www.unixarena.com/2015/04/how-to-create-the-yum-repository-on-rhel-7.html

    [root@localhost ~]# yum clean allLoaded plugins: langpacks, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.Cleaning repos: mnt_cdromCleaning up everythingMaybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos[root@localhost ~]# yum repolist Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.mnt_cdrom                                                                                                                   | 4.1 kB  00:00:00     (1/2): mnt_cdrom/group_gz                                                                                                   | 137 kB  00:00:00     (2/2): mnt_cdrom/primary_db                                                                                                 | 4.0 MB  00:00:00     repo id                                                     repo name                                                                        statusmnt_cdrom                                                   added from: file:///mnt/cdrom                                                    4,986repolist: 4,986[root@localhost ~]# 

  • 相关阅读:
    黑马程序员-block代码块和protocol协议
    黑马程序员-内存管理之autorelease和ARC机制
    黑马程序员-内存管理之set方法内存管理, property参数,循环引用。
    黑马程序员-内存管理之引用计数器
    黑马程序员-构造方法
    黑马程序员-@property,@synthesize使用细节和id
    黑马程序员—OC点语法和成员变量作用域
    黑马程序员-c语言指针的学习
    黑马程序员-OC基本语法
    NSSearchPathForDirectoriesInDomains用法 (转)
  • 原文地址:https://www.cnblogs.com/rusking/p/4248946.html
Copyright © 2011-2022 走看看