centos如何创建本地YUM源

centos如何创建本地YUM源

  • 前言
  • 一、创建本地yum源步骤
    • 1.将镜像.iso文件上传到服务器
    • 2.在根目录下新建一个iso目录用于挂在本地iso镜像
    • 3.使用命令将iso镜像挂在到iso目录
    • 4.备份原yum源配置文件
    • 5.创建本地yum源配置目录
    • 6.创建本地yum源配置文件
    • 7.在local.repo中填写如下内容
    • 8.更新yum源配置
    • 9.使用yum repolist后如看到以下内容说明配置成功。


前言

通常我们自己用的系统是可以联网的,但是一般生产环境都是内网,不可以上网,那么这时候可以创建本地yum源,安装一些基础的安装包。


一、创建本地yum源步骤

1.将镜像.iso文件上传到服务器

[root@localhost ~]# ls CentOS-7-x86_64-DVD-1708.iso
CentOS-7-x86_64-DVD-1708.iso

2.在根目录下新建一个iso目录用于挂在本地iso镜像

[root@localhost ~]# mkdir /iso
[root@localhost ~]# ls /
bin  boot  dev  etc  home  iso  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

3.使用命令将iso镜像挂在到iso目录

[root@localhost ~]# mount -o loop /root/CentOS-7-x86_64-DVD-1708.iso /iso
mount: /dev/loop0 is write-protected, mounting read-only

4.备份原yum源配置文件

[root@localhost ~]# mv /etc/yum.repos.d/ /etc/yum.repos.d.bak

5.创建本地yum源配置目录

代码如下(示例):

[root@localhost ~]# mkdir /etc/yum.repos.d

6.创建本地yum源配置文件

[root@localhost yum.repos.d]# vim local.repo	

7.在local.repo中填写如下内容

[CentOS7.5]
name=CentOS7.5-local
baseurl=file:///iso
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7	

8.更新yum源配置

[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: CentOS7.5
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.repos.d]# yum makecache
Loaded plugins: fastestmirror, langpacks
CentOS7.5                      | 3.6 kB     00:00
(1/4): CentOS7.5/group_gz        | 156 kB   00:00
(2/4): CentOS7.5/primary_db      | 3.1 MB   00:00
(3/4): CentOS7.5/filelists_db    | 3.1 MB   00:00
(4/4): CentOS7.5/other_db        | 1.2 MB   00:00
Determining fastest mirrors
Metadata Cache Created
	

9.使用yum repolist后如看到以下内容说明配置成功。

[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                                                                          repo name                                                                                              status
CentOS7.5                                                                                        CentOS7.5-local                                                                                        3,894
repolist: 3,894	

你可能感兴趣的:(centos,linux,服务器,运维,网络)