基于httpd配置搭建本地yum仓库

实验配置环境:CentOS 7
仓库主机:192.168.245.180
测试主机:192.168.245.181
防火墙及selinux关闭

1、基于ISO镜像构建 YUM 本地源

首先将光驱iso镜像加载至虚拟机CD/DVD,创建挂在目录mkdir -p /mnt/cdrom

[root@master ~] mkdir -p /mnt/cdrom
[root@master ~] mount /dev/cdrom /mnt/cdrom/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@master ~] cd /mnt/cdrom/
[root@master cdrom] ls
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

2、创建repo文件

[root@master ~] mv /etc/yum.repos.d/* /tmp/  #只是为了试验效果,实际可不必移除
[root@master ~] cd /etc/yum.repos.d/
[root@master yum.repos.d]# cat centos-local.repo 
[loca-repo]
name=local-repo
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=0
注:repo文件必须以".repo"结尾

3、安装httpd并启动

[root@master ~] yum -y install httpd
[root@master ~] systemctl start httpd
[root@master ~] netstat -nlpt | grep 80  #查看80端口是否开启
tcp6       0      0 :::80                   :::*                    LISTEN      23757/httpd         
[root@master ~]# ln -s /mnt/cdrom/ /var/www/html/centos  #创建软连接指向挂载的镜

4、测试主机配置

[root@node1 ~]# mv /etc/yum.repos.d/* /tmp/  #只是为了试验效果,实际可不必移除
[root@node1 ~]# cat /etc/yum.repos.d/centos-local-http.repo
[http-repos]
name=http-repos 
baseurl=http://192.168.98.134/centos
gpgcheck=0
enabled=1 
[root@node1 ~]# yum repolist
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
http-repos                                                              | 3.6 kB  00:00:00     
(1/2): http-repos/group_gz                                              | 166 kB  00:00:00     
(2/2): http-repos/primary_db                                            | 5.9 MB  00:00:00     
源标识                                       源名称                                       状态
http-repos                                   http-repos                                   9,911
repolist: 9,911

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