zoukankan      html  css  js  c++  java
  • linux替换yum源及配置本地源

     linux系统安装后自带的bash源由于在国外,安装软件包的时候会非常慢,最好替换一下yum源。

    • ​关于yum源的简单介绍

    ​           yum的主要功能是更方便地添加,删除和更新rpmbao,它能自带解决包的依赖,(rpm包安装有很强的包的依赖性)yum可以同时配置多个源。

    •  配置yum信息  
    查看当前系统使用的源
    [root@localhost ~]# yum repolist
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * extras: mirror.bit.edu.cn
     * updates: mirror.bit.edu.cn
    repo id                                        repo name                                        status
    base/7/x86_64                                  CentOS-7 - Base                                  9,591
    extras/7/x86_64                                CentOS-7 - Extras                                  446
    updates/7/x86_64                               CentOS-7 - Updates                               2,416
    repolist: 12,453
    

      由于bash源在国外,有时安装应用会很慢,需要进行yum的修改,国内有安全可靠的yum源如阿里,网易,163等。现在配置阿里的yum源。阿里的yuan源镜像地址为:https://opsx.alibaba.com/mirror,首先下在该镜像站点中的yum,这里选择epel源。

    wget https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
    

      安装epel源

    [root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm 
    warning: epel-release-latest-7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:epel-release-7-11                ################################# [100%]

      此时看到epel源已经安装好了,如果我们不适用bash源,可以将bash源修改名称或者移走

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

      查看源

    1 [root@localhost ~]# yum repolist
    2 Loaded plugins: fastestmirror
    3 Loading mirror speeds from cached hostfile
    4  * epel: mirror01.idc.hinet.net
    5 repo id                       repo name                                                         status
    6 epel/x86_64                   Extra Packages for Enterprise Linux 7 - x86_64                    12,449
    7 repolist: 12,449

    此时已经配置好了epel源,接下来再添加本地源,当没有网络环境的时候可以使用本地源安装一些工具包。

    在linux系统中光盘文件为/dev/sr0,通常将该文件挂载在指定目录。下面进行挂载

    [root@localhost ~]# mkdir -p /media/cdrom
    [root@localhost ~]# mount /dev/sr0 /media/cdrom/
    mount: /dev/sr0 is write-protected, mounting read-only
    
    [root@localhost ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root  9.8G  1.1G  8.2G  12% /
    devtmpfs                 482M     0  482M   0% /dev
    tmpfs                    493M     0  493M   0% /dev/shm
    tmpfs                    493M  6.8M  486M   2% /run
    tmpfs                    493M     0  493M   0% /sys/fs/cgroup
    /dev/sda1                190M   94M   83M  54% /boot
    /dev/mapper/centos-data  7.6G   36M  7.2G   1% /data
    tmpfs                     99M     0   99M   0% /run/user/0
    /dev/sr0                 8.1G  8.1G     0 100% /media/cdrom

    挂载上后需要到/etc/yum.repos.d/中修改CentOS-Media.repo中的信息,该源文件本地源配置文件,打开内容如下:

    [c7-media]
    name=CentOS-$releasever - Media
    baseurl=file:///media/CentOS/
            file:///media/cdrom/
            file:///media/cdrecorder/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    修改文件内容后如下:

    [c7-media]
    name=CentOS-$releasever - Media
    baseurl=file:///media/cdrom/
    gpgcheck=0
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    再查看系统使用的源

    [root@localhost yum.repos.d]# yum repolist
    Loaded plugins: fastestmirror
    c7-media                                                                       | 3.6 kB  00:00:00     
    (1/2): c7-media/group_gz                                                       | 156 kB  00:00:00     
    (2/2): c7-media/primary_db                                                     | 5.7 MB  00:00:00     
    Loading mirror speeds from cached hostfile
     * epel: mirror01.idc.hinet.net
    repo id                       repo name                                                         status
    c7-media                      CentOS-7 - Media                                                   9,591
    epel/x86_64                   Extra Packages for Enterprise Linux 7 - x86_64                    12,449
    repolist: 22,040

    最后将源创建缓存以提高加载速度

    [root@localhost yum.repos.d]# yum makecach
    Loaded plugins: fastestmirror
    No such command: makecach. Please use /usr/bin/yum --help
    [root@localhost yum.repos.d]# yum makecache
    Loaded plugins: fastestmirror
    c7-media                                                                       | 3.6 kB  00:00:00     
    epel/x86_64/metalink                                                           | 5.6 kB  00:00:00     
    (1/5): c7-media/other_db                                                       | 2.5 MB  00:00:00     
    (2/5): c7-media/filelists_db                                                   | 6.7 MB  00:00:00     
    (3/5): epel/x86_64/prestodelta                                                 | 9.0 kB  00:00:00     
    (4/5): epel/x86_64/filelists_db                                                |  10 MB  00:00:21     
    (5/5): epel/x86_64/other_db                                                    | 3.0 MB  00:01:17     
    Loading mirror speeds from cached hostfile
     * epel: mirror01.idc.hinet.net
    Metadata Cache Created

    如果设置开机自动挂载本地源,需要在/etc/fstab添加/dev/sr0 自动挂载

    # /etc/fstab
    # Created by anaconda on Wed Mar 28 22:59:47 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
    #
    /dev/mapper/centos-root /                       ext4    defaults        1 1
    UUID=0cceaf55-a63f-4f0c-97c7-305c848781bc /boot                   ext4    defaults        1 2
    /dev/mapper/centos-data /data                   ext4    defaults        1 2
    /dev/mapper/centos-swap swap                    swap    defaults        0 0
    /dev/sr0                /media/cdrom            iso9660 defaults        0 0
    光盘文件类型为 iso9660
    ~

     

  • 相关阅读:
    HDU 5528 Count a * b 欧拉函数
    HDU 5534 Partial Tree 完全背包
    HDU 5536 Chip Factory Trie
    HDU 5510 Bazinga KMP
    HDU 4821 String 字符串哈希
    HDU 4814 Golden Radio Base 模拟
    LA 6538 Dinner Coming Soon DP
    HDU 4781 Assignment For Princess 构造
    LA 7056 Colorful Toy Polya定理
    LA 6540 Fibonacci Tree
  • 原文地址:https://www.cnblogs.com/anay/p/8666015.html
Copyright © 2011-2022 走看看