YUM 本地源默认只能本机使用,局域网其他服务器无法使用 YUM 光盘源,如果想使用的话,需要在每台服务器上构建 YUM 本地源,所以需要构建 HTTP 局域网 YUM 源解决,可以通过 CreateRepo 创建本地 YUM 源端,repo 即为 Repository。



目录:
1. 基于 HTTP 构建 YUM 网络源 2. YUM 源端软件包扩展
3. 同步外网 YUM 源



基于 HTTP 构建 YUM 网络源

步骤:

  1. 挂载光盘镜像文件至/mnt
mount /dev/cdrom /mnt/
  1. 拷贝/mnt/Packages 目录下所有软件包至/var/www/html/centos/
mkdir -p /var/www/html/centos/

cp -R /mnt/Packages/* /var/www/html/centos/
  1. 使用 Createrepo 创建本地源,执行如下命令会在 Centos 目录生成 repodata 目录
yum	install	createrepo*	-y 

cd /var/www/html

createrepo	centos/

生成的repodata目录内容

[root@localhost repodata]# ls
318c9ea8899e2f554cebed8055428d09a1618da9018e596f3af7b73f04caac8e-primary.xml.gz
889867557baca0aa02d00feaeaf63d48f27505015687fc1ecb1e9ffa34c5ff6e-primary.sqlite.bz2
d683b9a986e59a7b0347c34b28137c89611b4013d1f569f22e79f014e83bfb74-other.sqlite.bz2  repomd.xml
65666f9c4ae025e8363f203bc436b6f8810ca6eeb92a9674945e9401846f400b-filelists.xml.gz 
9df0dccbf380d7af65397d20846942062c7e270dd81a6c36824dd360caad464f-filelists.sqlite.bz2 
ef04b6dc0b5b437bed9e05a44e5f9978d62781d640ebcf09dc4098a806c774fd-other.xml.gz
  1. 利用 HTTP 发布 YUM 本地源

本地 YUM 源通过 CreateRepo 搭建完毕, 需要借助 HTTP WEB 服务器发布
/var/www/html/centos/中所有软件,YUM 或者 RPM 安装 HTTP WEB 服务器,并启动 httpd服务

yum install httpd httpd-devel -y 安装 HTTP WEB 服务; 
useradd apache -g apache	创建 apache 用户和组; # yum 安装自动创建
systemctl restart httpd.service		重启 HTTPD 服务;
setenforce 0	临时关闭 SeLinux 应用级安全策略;
systemctl stop firewalld.service	停止防火墙;
ps -ef |grep httpd	查看 HTTPD 进程是否启动
  1. 在 YUM 客户端,创建/etc/yum.repos.d/http.repo 文件,写入如下内容
[base]
name="CentOS7 HTTP YUM"
baseurl=http://172.31.1.202/centos/
gpgcheck=0
enabled=1
 
[updates]
name="CentOS7 HTTP YUM"
baseurl=http://172.31.1.202/centos
gpgcheck=0
enabled=1
  1. 在 YUM 客户端上执行如下命令
yum clean all	清空 YUM Cache;

yum install memcached	-y	安装 MEMCACHED 软件

执行成功如下

centos7 arm版本yum网络源 centos7配置网络yum源http_centos7 arm版本yum网络源


回到目录


YUM 源端软件包扩展

默认使用 ISO 镜像文件中的软件包构建的 HTTP YUM 源,会发现缺少很多软件包,如果服务器需要挂载移动硬盘,Mount 挂载移动硬盘需要 ntfs-3g 软件包支持,而本地光盘镜像中没有该软件包,此时需要往 YUM 源端添加 ntfs-3g 软件包

添加方法如下:

  1. 切换至/var/www/html/centos 目录,官网下载 NTFS-3G 软件包
cd /var/www/html/centos/
wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/n/ntfs-3g-2017.3.23-11.el7.x86_64.rpm 
https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/n/ntfs-3g-devel-2017.3.23-11.el7.x86_64.rpm
  1. Createrepo 命令更新软件包,同理,如需新增其他软件包,同样把软件下载至本地,然后通过 createrepo 更新即可
[root@localhost centos]# createrepo --update /var/www/html/centos/
Spawning worker 0 with 2 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
  1. 客户端 YUM 验证,安装 NTFS-3G 软件包
[root@localhost ~]# yum install ntfs-3g* -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package ntfs-3g.x86_64 2:2017.3.23-11.el7 will be installed
---> Package ntfs-3g-devel.x86_64 2:2017.3.23-11.el7 will be installed
  1. 回到目录


同步外网 YUM 源

仅仅靠光盘里面的 RPM 软件包是不能满足需要,我们可以把外网的 YUM 源中的所有软件包同步至本地,可以完善本地 YUM 源的软件包数量及完整性。
获取外网 YUM 源软件常见方法包括 Rsync、Wget、Reposync,三种同步方法的区别Rsync 方式需要外网 YUM 源支持 RSYNC 协议,Wget 可以直接获取,而 Reposync 可以同步几乎所有的 YUM 源,下面以 Reporsync 为案例,同步外网 YUM 源软件至本地

步骤如下:

  1. 下载 CentOS7 REPO 文件至/etc/yum.repos.d/,并安装 reposync 命令工具
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
mv CentOS7-Base-163.repo /etc/yum.repos.d/centos.repo 
yum	clean all
yum install yum-utils createrepo –y
yum repolist
  1. 通过 reposync 命令工具获取外网 YUM 源所有软件包,-r 指定 repolist id,默认不加-r 表示获取外网所有YUM 软件包,-p 参数表示指定下载软件的路径
reposync -r	base -p /var/www/html/centos/

reposync -r	updates -p /var/www/html/centos/
  1. 通过 reposync 工具下载完所有的软件包之后,需要执行 createrepo 更新本地YUM 仓库
createrepo	/var/www/html/centos/
  1. 回到目录