本地yum源配置与卸载

目录

  • Centos8 yum源
    • 1、环境
    • 2、配置步骤
      • ❶创建挂载点
      • ❷挂载ISO镜像文件
      • ❸编写本地yum源仓库文件
      • ❹清空并重建cache
      • ❺写入配置文件
      • ❻测试
    • 3、卸载步骤
      • ❶切换至配置文件目录
      • ❷将本地yum源转存备份
      • ❸还原yum源
      • ❹安装测试
  • Centos7 yum源
    • 1、进入yum配置文件目录
    • 2、创建新配置文件
    • 3、按照参数路径挂载
    • 4、挂载信息写入配置文件
  • Centos6 yum源
    • 1、进入yum配置文件目录
    • 2、备份配置文件
    • 3、创建新的配置文件
    • 4、启用
  • 参考


Centos8 yum源

1、环境

运行环境:VMware16pro + centos8.3

2、配置步骤

❶创建挂载点

[root@centos1905 ~]# mkdir -p /mnt/cdrom

❷挂载ISO镜像文件

(1) VMware Workstation接入ISO镜像文件
(2) 进行光驱挂载

[root@centos1905 ~]# mount /dev/cdrom /mnt/cdrom
mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only.

(3)验证挂载

[root@centos1905 ~]# ls /mnt/cdrom/
AppStream  BaseOS  EFI  images  isolinux  media.repo  TRANS.TBL

❸编写本地yum源仓库文件

在编写之前,先将yum配置文件进行备份!

[root@centos1905 ~]# cd /etc/yum.repos.d/
[root@centos1905 yum.repos.d]# mkdir repo_bak 
[root@centos1905 yum.repos.d]# mv *.repo repo_bak/

编写本地yum仓库文件

[root@centos1905 yum.repos.d]# vi /etc/yum.repos.d/centos8.repo

[c8-media-AppStream]
name=AppStream
baseurl=file:///mnt/cdrom/AppStream
gpgcheck=0
enabled=1

[c8-media-BaseOS]
name=BaseOS
baseurl=file:///mnt/cdrom/BaseOS
gpgcheck=0
enabled=1

❹清空并重建cache

[root@centos1905 yum.repos.d]# yum clean all
0 files removed
[root@centos1905 yum.repos.d]# yum makecache
AppStream                                        58 MB/s | 5.2 MB     00:00    
BaseOS                                           44 MB/s | 2.2 MB     00:00    
Metadata cache created.

❺写入配置文件

[root@centos1905 yum.repos.d]# echo "/dev/cdrom  /mnt/cdrom iso9660 defaults 0 0" >> /etc/fstab

❻测试

[root@centos1905 yum.repos.d]# yum install gnome-tweaks
Last metadata expiration check: 0:01:09 ago on Sat 06 Mar 2021 01:31:00 PM CST.
Dependencies resolved.
================================================================================
 Package                          Arch   Version       Repository          Size
================================================================================
Installing:
 gnome-tweaks                     noarch 3.28.1-1.el8  c8-media-AppStream 331 k
Installing dependencies:
 gnome-shell-extension-user-theme noarch 3.28.1-8.el8  c8-media-AppStream  26 k

Transaction Summary
================================================================================
Install  2 Packages

Total size: 357 k
Installed size: 1.4 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : gnome-shell-extension-user-theme-3.28.1-8.el8.noarch   1/2 
  Installing       : gnome-tweaks-3.28.1-1.el8.noarch                       2/2 
  Running scriptlet: gnome-tweaks-3.28.1-1.el8.noarch                       2/2 
  Verifying        : gnome-shell-extension-user-theme-3.28.1-8.el8.noarch   1/2 
  Verifying        : gnome-tweaks-3.28.1-1.el8.noarch                       2/2 

Installed:
  gnome-tweaks-3.28.1-1.el8.noarch                                              
  gnome-shell-extension-user-theme-3.28.1-8.el8.noarch                          

Complete!

3、卸载步骤

❶切换至配置文件目录

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

❷将本地yum源转存备份

[root@centos1905 yum.repos.d]# mkdir local_yum
[root@centos1905 yum.repos.d]# mv centos8.repo local_yum/

❸还原yum源

[root@centos1905 yum.repos.d]# cd /etc/yum.repos.d/repo_bak
[root@centos1905 repo_bak]# mv *.repo /etc/yum.repos.d

❹安装测试

[root@centos1905 ~]# cd /etc/yum.repos.d/
[root@centos1905 yum.repos.d]# ls -al
total 20
drwxr-xr-x.   3 root root   42 Mar 11 11:31 .
drwxr-xr-x. 134 root root 8192 Mar 11 10:47 ..
-rw-r--r--.   1 root root  179 Mar 11 11:31 centos8.repo
drwxr-xr-x.   2 root root 4096 Mar  6 13:29 repo_bak
[root@centos1905 yum.repos.d]# mkdir local_yum
[root@centos1905 yum.repos.d]# mv centos8.repo local_yum/
[root@centos1905 yum.repos.d]# cd /etc/yum.repos.d/repo_bak
[root@centos1905 repo_bak]# mv *.repo /etc/yum.repos.d
[root@centos1905 repo_bak]# yum install mysql
CentOS-8 - AppStream                            543 kB/s | 6.3 MB     00:11    
CentOS-8 - Base                                 600 kB/s | 2.3 MB     00:03    
CentOS-8 - Extras                               2.5 kB/s | 9.2 kB     00:03 
略

Centos7 yum源

1、进入yum配置文件目录

  • cd /etc/yum.repos.d/

2、创建新配置文件

  • vim centos7.repo

3、按照参数路径挂载

  • mkdir -p /media/cdrom
  • mount /dev/cdrom /media/cdrom

4、挂载信息写入配置文件

  • vim /etc/fstab
  • mount -a
[root@localhost ~]# cd /etc/yum.repos.d/ 
[root@localhost yum.repos.d]# vim centos7.repo 
[centos7]
name=centos7
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0

[root@localhost yum.repos.d]# mkdir -p /media/cdrom 
[root@localhost yum.repos.d]# mount /dev/cdrom /media/cdrom 
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost yum.repos.d]# vim /etc/fstab
/dev/cdrom /media/cdrom iso9660 defaults 0 0

[root@localhost yum.repos.d]# mount -a
[root@localhost yum.repos.d]# yum install httpd

Centos6 yum源

运行环境:VMware16pro + centos6.6

1、进入yum配置文件目录

[root@www nginx-1.6.3]# cd /etc/yum.repos.d/

2、备份配置文件

[root@www yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak

3、创建新的配置文件

[root@www yum.repos.d]# vim 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-6.6 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.6/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#released updates 
[updates]
name=CentOS-6.6 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.6/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#additional packages that may be useful
[extras]
name=CentOS-6.6 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.6/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6.6 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.6/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-6.6 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.6/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6

4、启用

[root@www yum.repos.d]# yum clean all 
[root@www yum.repos.d]# yum makecache

参考

centos6配置yum源

你可能感兴趣的:(linux,centos,运维)