由于公司服务器禁止访问外网,不能访问外部镜像,所以搭建本地yum仓
一、因为要作为其他服务器访问的yum仓库,需要安装http服务
yum -y install httpd
开启服务:service httpd start
停止服务:service httpd stop
查看状态:service httpd status
二、在URL路径的起始位置建立镜像源目录,作为等会挂载的目录
[root@gallagher html]# pwd /var/www/html
[root@gallagher html]# ll
drwxr-xr-x 2 root root 6 Jul 17 15:27 repository
如果创建成功可以直接在服务器输入:http://39.98.137.12*/repository
三、下载对应的CentOS镜像源
[root@gallagher opt]# pwd
/opt
[root@gallagher opt]# ll
-rw-rw-r-- 1 root root 4781506560 Jul 17 10:47 CentOS-7-x86_64-DVD-2003.iso
mount -o loop /opt/CentOS-7-x86_64-DVD-2003.iso /var/www/html/repository
//会提示:mount: /dev/loop0 is write-protected, mounting read-only 这个影响不大
//这个最好配置永久挂载:
[root@gallagher yum.repos.d]# vim /etc/fstab
添加如下配置:
/dev/loop0 /var/www/html/repository iso9660 defaults 0 0
[root@gallagher dev]# df //查看挂载状态
/dev/loop0 4669162 4669162 0 100% /var/www/html/repository
[root@gallagher yum.repos.d]# mkdir repo
[root@gallagher yum.repos.d]# ll
total 40
-rw-r--r--. 1 root root 1664 Aug 30 2017 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Aug 30 2017 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Aug 30 2017 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Aug 30 2017 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Aug 30 2017 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Aug 30 2017 CentOS-Sources.repo
-rw-r--r--. 1 root root 3830 Aug 30 2017 CentOS-Vault.repo
-rw-r--r--. 1 root root 951 Oct 3 2017 epel.repo
-rw-r--r--. 1 root root 1050 Oct 3 2017 epel-testing.repo
drwxr-xr-x 2 root root 6 Jul 17 13:32 repo
[root@gallagher yum.repos.d]# mv *.repo repo/
-rw-r--r-- 1 root root 175 Jul 17 13:34 local.repo
drwxr-xr-x 2 root root 229 Jul 17 13:33 repo
[root@gallagher yum.repos.d]# pwd
/etc/yum.repos.d
配置如下:
[localrepo] #仓库ID 标识
name=local disk for centos7.5 #仓库名称(描述) baseurl=file:///var/www///html///repository #仓库的URL 指定仓库位置 协议file:///路径 enabled=1 #开关,0为关,1为开 仓库是否启用
gpgcheck=0 #校验开关 检查是否被篡改
注意 不要将注释加到配置里面去了,否则会报错的 !!!!!!!!
[root@gallagher yum.repos.d]# yum clean all
[root@gallagher yum.repos.d]# yum makecache
[root@gallagher yum.repos.d]# yum list | wc -l
4491 //显示包的个数
[HttpRepo]
name=HttpRepo
baseurl=http://39.98.137.124/repository
enabled=1
gpgcheck=0
最后用脚本说明步骤:
mkdir -p /etc/yum.repos.d/repo
cd /etc/yum.repos.d && mv *.repo repo/
cat>>/etc/yum.repos.d/httprepo.repo<<-EOF
[HttpRepo]
name=HttpRepo
baseurl=http://39.98.137.124/repository
enabled=1
gpgcheck=0
EOF
yum clean all && yum makecache
yum list | wc -l