本地yum仓库与局域网yum仓库配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了本地yum仓库与局域网yum仓库配置相关的知识,希望对你有一定的参考价值。

一、CentOS本地源设置

1.备份并删除原始的repo源文件

[[email protected] yum.repos.d]# tar -jcv -f CentOS.repo.tar.bz3 CentOS-*
CentOS-Base.repo
CentOS-Debuginfo.repo
CentOS-Media.repo
CentOS-Vault.repo
[[email protected] yum.repos.d]# ll
total 21
-rw-r--r--  2 root root 2294 Oct 30 19:06 CentOS-Base.repo
-rw-r--r--. 2 root root  638 Feb 25  2013 CentOS-Debuginfo.repo
-rw-r--r--  2 root root  630 Oct 30 19:03 CentOS-Media.repo
-rw-r--r--  2 root root 1579 Oct 30 19:12 CentOS.repo.tar.bz2
-rw-r--r--. 2 root root 3664 Feb 25  2013 CentOS-Vault.repo

[[email protected] yum.repos.d]# rm -f CentOS-*
[[email protected] yum.repos.d]# ll
total 5
-rw-r--r-- 2 root root 1579 Oct 30 19:12 CentOS.repo.tar.bz2

2.新建repo文件

[[email protected] yum.repos.d]# vi Centos-Base.repo
[local_server]
#定义库名
name=This is a local repo
#定义描述
baseurl=file:///media/cdrom
#定义源路径,可多个
enable=1
#是否启用源,1真0假
gpgcheck=1
#是否检查key,若不检查则无需定义key
"Centos-Base.repo" 6L, 89C written

3.清除所有缓存

[[email protected] yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: local_server
Cleaning up Everything
Cleaning up list of fastest mirrors

4.重建本地缓存

[[email protected] yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
local_server                                                                                                                   | 5.0 kB     00:00 ... 
local_server/group_gz                                                                                                          | 210 kB     00:00 ... 
local_server/filelists_db                                                                                                      | 5.8 MB     00:00 ... 
local_server/primary_db                                                                                                        | 4.5 MB     00:00 ... 
local_server/other_db                                                                                                          | 2.0 MB     00:00 ... 
Metadata Cache Created

5.测试

[[email protected] yum.repos.d]# yum install bind-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bind-utils.i686 32:9.8.2-0.17.rc1.el6 will be installed
--> Processing Dependency: bind-libs = 32:9.8.2-0.17.rc1.el6 for package: 32:bind-utils-9.8.2-0.17.rc1.el6.i686
--> Processing Dependency: liblwres.so.80 for package: 32:bind-utils-9.8.2-0.17.rc1.el6.i686
--> Processing Dependency: libisccfg.so.82 for package: 32:bind-utils-9.8.2-0.17.rc1.el6.i686
--> Processing Dependency: libisccc.so.80 for package: 32:bind-utils-9.8.2-0.17.rc1.el6.i686
--> Processing Dependency: libisc.so.83 for package: 32:bind-utils-9.8.2-0.17.rc1.el6.i686
--> Processing Dependency: libdns.so.81 for package: 32:bind-utils-9.8.2-0.17.rc1.el6.i686
--> Processing Dependency: libbind9.so.80 for package: 32:bind-utils-9.8.2-0.17.rc1.el6.i686
--> Running transaction check
---> Package bind-libs.i686 32:9.8.2-0.17.rc1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
 Package                           Arch                        Version                                      Repository                           Size
======================================================================================================================================================
Installing:
 bind-utils                        i686                        32:9.8.2-0.17.rc1.el6                        local_server                        180 k
Installing for dependencies:
 bind-libs                         i686                        32:9.8.2-0.17.rc1.el6                        local_server                        882 k

Transaction Summary
======================================================================================================================================================
Install       2 Package(s)

Total download size: 1.0 M
Installed size: 2.7 M
Is this ok [y/N]: y
Downloading Packages:
------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                  23 MB/s | 1.0 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 32:bind-libs-9.8.2-0.17.rc1.el6.i686                                                                                               1/2 
  Installing : 32:bind-utils-9.8.2-0.17.rc1.el6.i686                                                                                              2/2 
  Verifying  : 32:bind-utils-9.8.2-0.17.rc1.el6.i686                                                                                              1/2 
  Verifying  : 32:bind-libs-9.8.2-0.17.rc1.el6.i686                                                                                               2/2 

Installed:
  bind-utils.i686 32:9.8.2-0.17.rc1.el6                                                                                                               

Dependency Installed:
  bind-libs.i686 32:9.8.2-0.17.rc1.el6                                                                                                              
Complete!

#二、局域网yum源配置

1.所需工具
createrepo:仓库文件创建工具
httpd,ftp:传输工具

2.环境准备
server:ikulin 10.10.10.1
client:localhost 10.10.10.3
linux:centos7

3.server拷贝光盘rpm包到本地http目录

[[email protected] media]$ cp -r Packages/ /var/www/html/yum

4.server生成创建仓库

[[email protected] yum]$ createrepo .
Spawning worker 0 with 2398 pkgs
Spawning worker 1 with 2398 pkgs
Spawning worker 2 with 2398 pkgs
Spawning worker 3 with 2397 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

5.server启动httpd服务

[[email protected] html]$ sudo systemctl restart httpd

6.client配置repo源

[[email protected] yum.repos.d]# cat CentOS-Base.repo 
[C7]
name=CentOS7
baseurl=http://10.10.10.1/yum
gpgcheck=0

7.client清除所有缓存

[[email protected] yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: C7
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors

8.client重建本地缓存(失败)

8.1.故障1,防火墙设置问题

[[email protected] yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
http://10.10.10.1/yum/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to 10.10.10.1:80; No route to host"
Trying other mirror.
^Chttp://10.10.10.1/yum/repodata/repomd.xml: [Errno 14] curl#56 - "Callback aborted"

故障排除:

  1. 故障提示没有route无法连接到server,但在server上测试访问为ok,连通性测试为ok,判断为防火墙拦截了访问请求
  2. 检查c/s的selinux、iptables为关闭,但centos7开始,默认的防火墙为firewalld,查询状态为开启
  3. 关闭server的firewalld服务后出现故障2

8.2.故障2,http目录权限设置问题

[[email protected] yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
http://10.10.10.1/yum/repodata/repomd.xml: [Errno 14] HTTP Error 403 - Forbidden

故障排除:

  1. 故障提示访问拒绝,使用curl访问服务器ok,向下级目录访问被拒绝,判断为目录或文件访问权限设置不正确
  2. 检查yum下仓库数据目录repodata的权限为744,非所属用户访问只拥有只读权限,而目录必须拥有执行权限才能进入
  3. 修改repodata目录权限为745
    [[email protected] yum]$ ll -d  rep*
    drwxr--r-- 2 root root 4096 Feb 16 22:47 repodata
    [[email protected] yum]$ sudo chmod 745 repodata/
    [[email protected] yum]$ ll -d  rep*
    drwxr--r-x 2 root root 4096 Feb 16 22:47 repodata

    8.3.client本地缓存重建完成

[[email protected] ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: C7
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
[[email protected] ~]# du -h /var/cache/yum/
0   /var/cache/yum/x86_64/7/C7/gen
0   /var/cache/yum/x86_64/7/C7/packages
0   /var/cache/yum/x86_64/7/C7
0   /var/cache/yum/x86_64/7/base/gen
0   /var/cache/yum/x86_64/7/base/packages
8.0K    /var/cache/yum/x86_64/7/base
0   /var/cache/yum/x86_64/7/extras/gen
0   /var/cache/yum/x86_64/7/extras/packages
0   /var/cache/yum/x86_64/7/extras
0   /var/cache/yum/x86_64/7/updates/gen
0   /var/cache/yum/x86_64/7/updates/packages
0   /var/cache/yum/x86_64/7/updates
12K /var/cache/yum/x86_64/7
12K /var/cache/yum/x86_64
12K /var/cache/yum/

[[email protected] yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
C7                                                                                                                             | 2.9 kB  00:00:00     
(1/3): C7/primary_db                                                                                                           | 5.7 MB  00:00:00     
(2/3): C7/filelists_db                                                                                                         | 6.6 MB  00:00:00     
(3/3): C7/other_db                                                                                                             | 2.4 MB  00:00:00     
Determining fastest mirrors
Metadata Cache Created
[[email protected] yum.repos.d]# du -h /var/cache/yum
85M /var/cache/yum/x86_64/7/C7/gen
0   /var/cache/yum/x86_64/7/C7/packages
99M /var/cache/yum/x86_64/7/C7
0   /var/cache/yum/x86_64/7/base/gen
0   /var/cache/yum/x86_64/7/base/packages
8.0K    /var/cache/yum/x86_64/7/base
0   /var/cache/yum/x86_64/7/extras/gen
0   /var/cache/yum/x86_64/7/extras/packages
0   /var/cache/yum/x86_64/7/extras
0   /var/cache/yum/x86_64/7/updates/gen
0   /var/cache/yum/x86_64/7/updates/packages
0   /var/cache/yum/x86_64/7/updates
99M /var/cache/yum/x86_64/7
99M /var/cache/yum/x86_64
99M /var/cache/yum

9.测试验证

[[email protected] yum.repos.d]# yum search wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
================================================================= N/S matched: wget ==================================================================
wget.x86_64 : A utility for retrieving files using the HTTP or FTP protocols

  Name and summary matches only, use "search all" for everything.

以上是关于本地yum仓库与局域网yum仓库配置的主要内容,如果未能解决你的问题,请参考以下文章

linux局域网搭建yum仓库(本地(file)网络(ftphttp))

Centos7 配置yum软件仓库

yum 本地仓库搭建

通过ftp创建本地yum仓库

局域网内配置yum源仓库

如何配置Yum仓库?