局域网本地安装yum源

一、yum的工作原理
    说到yum源就必须说到linux系统中特有的依赖关系问题,yum就是为了解决依赖关系而存在的。yum源就相当是一个目录项,当我们使用yum机制安装软件时,若需要安装依赖软件,则yum机制就会根据在yum源中定义好的路径查找依赖软件,并将依赖软件安装好。YUM是“Yellow dog Updater, Modified”的缩写,是一个软件包管理器,YUM从指定的地方(相关网站的rpm包地址或本地的rpm路径)自动下载RPM包并且安装,能够很好的解决依赖关系问题。
    YUM的基本工作机制如下:
    服务器端:在服务器上面存放了所有的RPM软件包,然后以相关的功能去分析每个RPM文件的依赖性关系,将这些数据记录成文件存放在服务器的某特定目录内。客户端:如果需要安装某个软件时,先下载服务器上面记录的依赖性关系文件(可通过WWW或FTP方式),通过对服务器端下载的纪录数据进行分析,然后取得所有相关的软件,一次全部下载下来进行安装。
二、在本地建yum源或yum服务器
    一个yum源一般由base extras updates epel四个部分组分,前三个都很容易明白,这里说明下第四个
EPEL的全称叫 Extra Packages for Enterprise Linux 。EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、
Scientific Linux 等提供高质量软件包的项目。装上了 EPEL之后,就相当于添加了一个第三方源。
三、安装过程
首先在服务端运行 yum install createrepo yum-utils 
[root@server centos7]# pwd
/var/www/html/centos7
[root@server centos7]# ls 
base  epel  extras  updates

[root@server centos7]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

进入 /var/www/html/centos7目录,直接运行reposync同步base extras updates 三个部分的rpm包

[root@server ~]# reposync -r epel -p /var/www/html/
用epel作为本地yum源,用/home/root/ 作为yum仓库根目录
命令执行完毕后,会将阿里云中的epel源同步到本地/var/www/html中;在/var/www/html中自动创建epel目录用于存放rpm包;第一次同步是时间可能较长,大概1W多个rpm包。

利用createrepo命令建立索引文件

[root@server centos7]# createrepo ./base/
[root@server centos7]# createrepo ./extras/
[root@server centos7]# createrepo ./updates/

[root@server centos7]# createrepo ./epel/
在客户端目录 /etc/yum.repo.d中
mkdir repobak
mv *.repo ./repobak
[root@clusternode0x84 clusteruser]# cd /etc/yum.repos.d/
[root@clusternode0x84 yum.repos.d]# ls 
CentOS-Base.repo  extras-7.repo  repobak
[root@clusternode0x84 yum.repos.d]# cat CentOS-Base.repo 
[base]
name=local base
baseurl=http://serverip/centos7/base/
enabled=1
gpgcheck=0
[updates]
name=local updates
baseurl=http://serverip/centos7/updates/
enabled=1
gpgcheck=0
[extras]
baseurl=http://serverip/centos7/extras/
enabled=1
gpgcheck=0
[epel]
name=local epel
baseurl=http://serverip/centos7/epel/
enabled=1
gpgcheck=0

四、当使用linux下的httpd作为yum源的加载点时,注意将SELinux关闭,否则会报“repodata/repomd.xml: [Errno 14] HTTP
Error 403 - Forbidden”错误,当使用IIS作为yum源的加载点时,注意开放目录浏览功能,在MIME的类型中加入bz2,具体操作可在网上查询
 

猜你喜欢

转载自blog.csdn.net/lepton126/article/details/83507349