部署内网yum源
思路: 使用当前服务器同步外网源到本地,将下载的软件包重新生成repodata文件,使用httpd共享给其他内网机器使用,本次仅整理笔记,未配置squid代理,生成环境也可只开通当前机器访问外网源的80端口权限
reposync参数说明
reposync参数: Options:
-h, --help 显示此帮助消息并退出
-c CONFIG, --config=CONFIG 要使用的配置文件(默认为/etc/yum.conf)
-a ARCH, --arch=ARCH 像运行指定的arch一样(默认值:current arch,注意:不会覆盖$releasever。 x86_64是一个 i * 86的超集。)
--source 在源包上运行
-r REPOID, --repoid=REPOID 指定repo id来查询,可以指定多个次(默认全部启用)
-e CACHEDIR, --cachedir=CACHEDIR 用于存储元数据的目录
-t, --tempcache 使用临时目录存储/访问yum-cache
-d, --delete 删除存储库中不再存在的本地包
-p DESTDIR, --download_path=DESTDIR 下载包的路径:默认为当前目录
--norepopath 不要将reponame添加到下载路径。只可以 在同步单个存储库时使用(默认为 添加reponame)
-g, --gpgcheck 删除未通过GPG签名检查的软件包
-u, --urls 只列出要下载的URL,不要下载
-n, --newest-only 仅下载per-repo的最新软件包
-q, --quiet 尽可能少地输出
-l, --plugins 启用yum插件支持
-m, --downloadcomps 下载comps.xml
--download-metadata 下载所有非默认元数据
--allow-path-traversal允许存储在其repo目录之外的包 同步(UNSAFE,小心使用!)
配置系统环境
#查看系统版本
[root@centos7 ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
#关闭selinux
[root@centos7 ~]# setenforce 0
setenforce: SELinux is disabled
[root@centos7 ~]# vim /etc/selinux/config
SELINUX=disabled
#关闭防火墙
[root@centos7 ~]# systemctl disable firewalld --now
配置yum源
#第一个源
[root@centos7 ~]# cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#第二个源
[root@centos7 ~]# cat /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
#生成yum缓存
[root@centos7 ~]# yum makecache
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
元数据缓存已建立
搭建本地yum源
#安装所需软件包
[root@centos7 ~]# yum -y install createrepo httpd
#启动服务
[root@centos7 ~]# systemctl enable httpd --now
#创建存储目录
[root@centos7 ~]# mkdir -p /var/www/html/centos/7/x86/
#查看源标识
[root@centos7 ~]# yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
源标识 源名称 状态
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,752
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 512
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 3,863
repolist: 28,199
#执行命令测试
[root@centos7 ~]# reposync -n --repoid=base --repoid=epel --repoid=extras --repoid=updates -p /var/www/html/centos/7/x86/
#创建索引文件
[root@centos7 ~]# createrepo /var/www/html/centos/7/x86/base/
[root@centos7 ~]# createrepo /var/www/html/centos/7/x86/epel/
[root@centos7 ~]# createrepo /var/www/html/centos/7/x86/extras/
[root@centos7 ~]# createrepo /var/www/html/centos/7/x86/updates/
测试
本次未下载,正式部署可测试一下,如果受umask影响,就把文件权限修改成apache.apache
创建计划任务
#创建同步脚本
[root@centos7 ~]# cat /opt/update_repo.sh
#!/bin/bash
reposync -n --repoid=base --repoid=epel --repoid=extras --repoid=updates -p /var/www/html/centos/7/x86/
createrepo --update /var/www/html/centos/7/x86/base/
createrepo --update /var/www/html/centos/7/x86/epel/
createrepo --update /var/www/html/centos/7/x86/extras/
createrepo --update /var/www/html/centos/7/x86/updates/
[root@centos7 ~]# chmod +x /opt/update_repo.sh
#创建计划任务
[root@centos7 ~]# cat /var/spool/cron/root
0 2 * * * bash /opt/update_repo.sh
[root@centos7 ~]# crontab -l
0 2 * * * bash /opt/update_repo.sh

浙公网安备 33010602011771号