linux 配置网络yum源

简述

yum光盘源默认只能本机使用,局域网其它服务器无法使用yum光盘源,如果想使用的话,需要在每台服务器上构建yum本地源,这种方案不可取,需要构建http局域网yum源解决,可以通过createrepo创建本地yum源端,repo极为repository

一、基于http配置yum源

构建http局域网yum源方法及步骤如下:

1、挂载光盘镜像文件至/mnt

mount /dev/cdrom    /mnt/

2、拷贝/mnt/Packages目录下所有软件包到/var/www/html/centos/

mkdir -p /var/www/html/centos/

cp -R /mnt/Packages/* /var/www/html/centos/

3、使用createrepo创建本地源,执行如下命令会在Centos目录生成repodata目录

yum install createrepo* -y

createrepo /var/www/html/centos/

4、利用http发布yum本地源

本地yum源通过createrepo搭建完毕,需要借助http web服务器发布/var/www/html/centos/中所有软件,yum或者rpm安装http web服务器,并启动httpd服务

yum install httpd httpd-devel -y :安装httpd web服务

useradd apache -g apache  :创建apache用户和组

systemctl restart httpd.server :重启httpd服务

setenforce 0         :关闭selinux应用安全策略

systemctl stop firewalld.service :停止防火墙

5、在yum客户端,创建/etc/yum.repos.d/httpd.repo文件

[base]

name="CentOS7 HTTPD YUM"

baseurl=http://192.168.10.133/centos/

enabled=1

gpgcheck=0

[updates]

name="CentOS7 HTTPD YUM"

baseurl=http://192.168.10.133/centos/

enabled=1

gpgcheck=0

6、在yum客户端上执行如下命令

yum clean all      :清空yum cache

yum install ntpdate -y   :安装ntpdate软件

 

二、yum源端软件包扩展

默认使用ISO镜像文件中的软件包构建的http yum源,缺少很多软件包。如果服务器需要挂载移动硬盘,mount挂载移动硬盘需要ntfs-3g软件包支持,而本地光盘镜像中没有改软件包,此时需要往yum源端添加ntfs-3g软件包,添加方法如下:

1、切换到centos目录,官网下载ntfs-3g软件包

cd /var/www/html/centos/

wget -c https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/n/ntfs-3g-2017.3.23-11.el7.x86_64.rpm

wget -c https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/n/ntfs-3g-devel-2017.3.23-11.el7.x86_64.rpm

2、createrepo命令更新软件包,如需增加其他软件包,同样把软件下载到本地,然后通过createrepo更新即可

createrepo --update centos/

3、客户端yum验证,安装ntfs-3g软件包

yum clean all

yum install ntfs-3g -y

 

三、同步外网yum源

  在企业实际应用场景中,仅仅靠光盘里面的 RPM 软件包是不能满足需要,我们可以把外网的 YUM 源中的所有软件包同步至本地,可以完善本地 YUM 源的软件包数量及完

整性。 

  获取外网 YUM 源软件常见方法包括 rsync、wget、reposync,三种同步方法的区别 Rsync 方式需要外网 YUM 源支持 RSYNC 协议,Wget 可以直接获取,而 Reposync可以同步几乎所有的 YUM 源,下面以 Reporsync 为案例,同步外网 YUM 源软件至本地,步骤如下:

1、下载CentOS7 repo文件到/etc/repos.d/

wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

yum clean all

2、通过reposync命令工具获取外网yum源所有软件包,-r指定repolist id,默认不加-r表示获取外网所有yum软件包,-p参数表示指定下载软件的路径

reposync -r base -p /var/www/html/centos/      

reposync -r updates -p /var/www/html/centos/

3、通过reposync工具下载完成所有的软件包之后,需要执行createrepo更新本地yum仓库

createrepo /var/www/html/centos/

posted @ 2021-08-16 16:55  香饼  阅读(907)  评论(0编辑  收藏  举报