1、yum源配置(网络):
1.1先备份原有的yum源:
1 [root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.back
1.2下载新的yum源(阿里):
1 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2 或者
3 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
1.3清除原有yum缓存:
1 [root@localhost ~]# yum clean all
1.4生成新的缓存:
1 [root@localhost ~]# yum makecache
2、yum源配置(本地):
2.1下载ISO文件
从CentOS的官网下载CentOS的完整版iso文件,并上传到Linux文件系统中,例如/opt/tools/。
2.2为ISO创建一个挂载目录
1 mkdir /mnt/vcdrom
2.3将ISO文件挂载到挂载目录
1 mount -o loop -t iso9660 /opt/tools/CentOS-7-x86_64-bin-DVD1.iso /mnt/vcdrom
2.4移除或备份原yum源Centos-Base.repo文件
1 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.back
2.5配置Centos-Media.repo文件
1 [root@localhost ~]# cat /etc/yum.repos.d/CentOS-Media.repo
2 [c7-media]
3 name=CentOS-$releasever - Media
4 baseurl=file:///mnt/vcdrom/ #将baseurl修改为DVD的挂载目录
5 gpgcheck=0 #关闭密钥检测
6 enabled=1 #启用仓库
7 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
2.6清除原有yum缓存:
1 [root@localhost ~]# yum clean all
2.7生成新的缓存:
1 [root@localhost ~]# yum makecache
2.8编写脚本开机自动挂载镜像
1 [root@localhost ~]#vim /opt/shell/mymount.sh
2 #!/bin/bash
3 #
4 mount -o loop -t iso9660 /opt/tools/CentOS-6.7-x86_64-bin-DVD1.iso /mnt/vcdrom
2.9修改脚本权限:
1 [root@localhost ~]#chmod 777 /opt/shell/mymount.sh
2.10修改/etc/rc.local配置文件,在文件最后一行加上 /opt/shell/mymount.sh
1 [root@localhost ~]#vim /etc/rc.local
2 /opt/shell/mymount.sh
2.11重启服务器测试:
1 [root@localhost ~]# reboot