第六节、设置本地/局域网网络YUM源

2017-11-28  本文已影响0人  妄语莫言

利用光盘设置本地局域网yum源

备注

注意目录名称是/etc/yum.repos.d,实验时因为把目录改成yum.repos.d导致本地源无法生效,因为配置文件里的路径没找到
可以通过yum repolist检测支持的更新点,yum list查看支持安装的软件列表
另外一般linux系统的光盘里包含大部分的软件包,但是因为DVD光盘容量有限,只能将重要的程序放在DVD1中,部分扩展程序放在DVD2中,因此最好去官网下载两张盘上传到服务器中合并之后再作为共享源,以保证源中软件包的完整性。

[root@yumserver etc]# yum repolist
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
repo id                                                repo name                                            status
yum                                                    rhel                                                 6,367
repolist: 6,367
利用yum命令去源中查找有无对应的软件包yum search soft_name
[root@mini ~]# yum search httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
============================================== N/S Matched: httpd ==============================================
httpd.x86_64 : Apache HTTP Server
httpd-devel.i686 : Development interfaces for the Apache HTTP server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server
mod_dnssd.x86_64 : An Apache HTTPD module which adds Zeroconf support

软件包yum源位置/etc/yum.repos.d,默认安装玩系统后会自动配置一些官方的yum源,只要可以上网就能自动安装各类软件,但是为了适应部分内网机器无法上网的情况就需要配置本地的yum源。
更改yum源前先备份原先的文件mv /etc/yum.repos.d /etc/yum.repos.d.bak
然后重新创建目录mkdir /etc/yum.repos.d

方法一、直接创建yum源配置文件
[root@yumserver yum.repos.d]# vim centos.repo
[yum]                               #名称
name=rhel                       #名字
baseurl=file:///mnt/cdrom #源文件的url地址
enabled=1                        #启用该源
gpgcheck=0                     #不启用密钥校对

创建对应的光盘挂载目录并把光盘挂载上去

[root@yumserver yum.repos.d]# mkdir -p  /mnt/cdrom
[root@yumserver yum.repos.d]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@yumserver yum.repos.d]# ls /mnt/cdrom/
CentOS_BuildTag  GPL       Packages                  RPM-GPG-KEY-CentOS-6           RPM-GPG-KEY-CentOS-Testing-6
EFI              images    RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Debug-6     TRANS.TBL
EULA             isolinux  repodata                  RPM-GPG-KEY-CentOS-Security-6

清除本地的yum缓存yum clean all

方法二、设置网络源

直接利用nginx或者apache http服务发布网站,把文件放到软件的发布目录,然后其他机器远程访问,一般httpd为例,http默认的发布目录是/var/www/html/,这里使用ngnix服务器,配置IP192.168.15.131,访问端口8088.默认发布目录/data/nginx/html,这里将光盘内容下载到目录/data/CentOS6.5,为了方便直接链接到发布目录html,设置软链接到光盘目录格式为ln -s 源文件 目标文件
ln -s /data/CentOS6.5/ /data/nginx/html/
直接访问网址http://192.168.15.131:8088/CentOS6.5/可以查看到光盘目录内容。
在局域网上其他客户机上备份yum源目录,新建源配置文件centos.repo

[root@yumserver yum.repos.d]# vim centos.repo
[yum]                               #名称
name=centos6.5                     #名字
baseurl=http://192.168.15.131:8088/CentOS6.5/  #源文件的url地址
enabled=1                        #启用该源
gpgcheck=0                     #不启用密钥校对

清除yum缓存后查看repolist

[root@mini yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: yum
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@mini yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
yum                                                                                      | 4.0 kB     00:00     
yum/primary_db                                                                           | 4.4 MB     00:00     
repo id                                             repo name                                             status
yum                                                 centos6.5                                             6,367
repolist: 6,367

至此网络源配置成功

备注:对于光盘中没有的软件包需要先去网上下载放到光盘源的Packages目录中然后更新软件包依赖文件

首先安装仓库生成软件yum install createrepo
更新软件包的依赖关系createrepo --uodate /data/CentOS6.5/

RHEL系统YUM仓库配置
#因为版权问题网上没有现成的红帽YUM仓库只能使用光盘挂载本地
[root@localhost ~]# mkdir -p /media/cdrom
[root@localhost ~]#  vim /etc/fstab
/dev/cdrom  /media/cdrom  iso9660 defaults 0 0
[root@localhost ~]#  mount -a
[root@localhost ~]# vim /etc/yum.repos.d/rhel.repo
[RHEL]    #标识符
name=rhel   #仓库名
baseurl=file:///media/cdrom    #本地路径
enabled=1    #启用
gpgcheck=0 #禁止校验
上一篇下一篇

猜你喜欢

热点阅读