CentOS7通过http方式搭建本地yum源

1.创建yum软件保存目录
*mkdir /var/www/html/yum/

这里插一句
将磁盘上的iso文件挂载到一个目录上的方法
用mount -o loop /mnt/
/1.iso /opt/cdrom 命令

2. 修改yum配置文件

先备份yum配置文件,修改yum配置文件中yum软件包保存目录并开启rmp包缓存功能

1 [[email protected] ~]# cp /etc/yum.conf /etc/yum.conf.bak 
2 [[email protected] ~]# vim /etc/yum.conf
3 [main] 
4 #cachedir=/var/cache/yum/$basearch/$releasever
5 cachedir=/www/share/yum/$basearch/$releasever 
6 keepcache=1

3.安装createrepo和http

createrepo 命令用于创建yum源(软件仓库),即为存放于本地特定位置的众多rpm包建立索引,描述各包所需依赖信息,并形成元数据
[[email protected] ~]# yum install createrepo httpd -y

4.创建http共享目录,添加虚拟主机
vim /etc/httpd/conf.d/yum.conf #注意权限#

#http yum

Alias /yum /var/www/html/yum
<Directory "/var/www/html/yum">
Options Indexes FollowSymLinks
  IndexOptions NameWidth=* DescriptionWidth=* FoldersFirst
  IndexOptions SuppressIcon HTMLTable Charset=UTF-8 SuppressHTMLPreamble
  Order allow,deny
  Allow from all
  Require all granted
</Directory> 

CentOS7通过http方式搭建本地yum源5. 启动http服务
[[email protected] ~]# systemctl enable httpd.service && systemctl restart httpd.service
[[email protected] ~]# netstat -antp|grep ‘httpd’

浏览器访问192.168.92.60/yum ,能访问即正常。或者使用curl http://IP/yum 访问

6.客户端创建YUM软件仓库

vim /etc/yum.repos.d/local.repo

[base]
name=CentOS-$releasever
enabled=1
failovermethod=priority
baseurl=http://172.16.0.157/yum
gpgcheck=1
gpgkey=http://172.16.0.157/yum/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-$releasever
enabled=1
failovermethod=priority
baseurl=http://172.16.0.157/yum
gpgcheck=1
gpgkey=http://172.16.0.157/yum/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever
enabled=1
failovermethod=priority
baseurl=http://172.16.0.157/yum
gpgcheck=1
gpgkey=http://172.16.0.157/yum/RPM-GPG-KEY-CentOS-7

CentOS7通过http方式搭建本地yum源
7.在客户端验证,注意防火墙等安全策略和目录权限

yum group list
CentOS7通过http方式搭建本地yum源