内网环境下使用rpm包制作yum数据源及使用

内网环境下使用rpm包制作yum数据源及使用

在实际生产环境中,绝大多数服务器处于内网环境、基于最小化安装、光盘镜像挂载不方便(缺少)等原因,无法使用yum服务,本实验基于生产环境中出现的上述现象进行yum数据源制作及yum服务使用。

服务器环境

[root@ceshifwq ~]# cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core)
[root@ceshifwq ~]# uname -r
3.10.0-514.el7.x86_64
[root@ceshifwq ~]# ip a |awk 'NR==9{print $2}'|awk -F '/' '{print $1}'
10.0.7.190
[root@ceshifwq ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repolist: 0

客户端工具

文件传输软件:WinSCP
镜像文件:CentOS-7.7-x86_64-Everything-1908.iso

客户端操作

  1. 利用解压软件将镜像文件解压至本地
PS F:\AAAAISO\CentOS-7.8-x86_64-Everything-2003> dir
    目录: F:\AAAAISO\CentOS-7.8-x86_64-Everything-2003

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        2020-4-20     18:00                EFI
d-----        2020-4-20     18:00                images
d-----        2020-4-20     18:00                isolinux
d-----        2020-4-20     18:00                LiveOS
d-----        2020-4-20     17:42                Packages
d-----        2020-4-21     23:37                repodata
-a----        2020-4-20     17:55             29 .discinfo
-a----        2020-4-20     18:00            353 .treeinfo
-a----        2020-4-21     17:15             14 CentOS_BuildTag
-a----        2017-8-30     14:33            227 EULA
-a----        2015-12-9     22:35          18009 GPL
-a----        2015-12-9     22:35           1690 RPM-GPG-KEY-CentOS-7
-a----        2015-12-9     22:35           1690 RPM-GPG-KEY-CentOS-Testing-7
-a----        2020-4-22      0:55           2883 TRANS.TBL
PS F:\AAAAISO\CentOS-7.8-x86_64-Everything-2003> tree
文件夹 PATH 列表
卷序列号为 B8D4-6DEE
F:.
├─EFI
│  └─BOOT
│      └─fonts
├─images
│  └─pxeboot
├─isolinux
├─LiveOS
├─Packages
└─repodata
  1. 利用文件传输软件将Packages文件夹整体上传到服务器中

rpm数据库制作

[root@ceshifwq ~]# pwd
/root
[root@ceshifwq ~]# ls
anaconda-ks.cfg  Packages
[root@ceshifwq ~]# ls /root/Packages/ |wc -l
10070

createrepo命令安装

Packages包含光盘中所有的rpm包,利用createrepo命令生成新的repodata源数据,使yum服务可以使用该数据源。

  1. 安装createrepo命令
[root@ceshifwq ~]# ls /root/Packages/ | grep create
createrepo-0.9.9-28.el7.noarch.rpm
[root@ceshifwq Packages]# rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm 
error: Failed dependencies:
        deltarpm is needed by createrepo-0.9.9-28.el7.noarch
        libxml2-python is needed by createrepo-0.9.9-28.el7.noarch
        python-deltarpm is needed by createrepo-0.9.9-28.el7.noar
  1. 根据报错提示缺少上述依赖,确定依赖包存在于Packages
[root@ceshifwq Packages]# ls | grep deltarpm
deltarpm-3.6-3.el7.x86_64.rpm
python-deltarpm-3.6-3.el7.x86_64.rpm
[root@ceshifwq Packages]# ls | grep libxml2-python
libxml2-python-2.9.1-6.el7.4.x86_64.rpm
  1. 使用rpm命令同时安装缺少的所有rpm包(完整包名)
[root@ceshifwq Packages]# rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm deltarpm-3.6-3.el7.x86_64.rpm python-deltarpm-3.6-3.el7.x86_64.rpm libxml2-python-2.9.1-6.el7.4.x86_64.rpm
error: Failed dependencies:
        libxml2 = 2.9.1-6.el7.4 is needed by libxml2-python-2.9.1-6.el7.4.x86_64
  1. 如3步骤,出现二次依赖错误

  2. 查找对应的包(libxml2 = 2.9.1-6.el7.4)并安装

[root@ceshifwq Packages]# ls | grep libxml2
libxml2-2.9.1-6.el7.4.i686.rpm
libxml2-2.9.1-6.el7.4.x86_64.rpm
libxml2-devel-2.9.1-6.el7.4.i686.rpm
libxml2-devel-2.9.1-6.el7.4.x86_64.rpm
libxml2-python-2.9.1-6.el7.4.x86_64.rpm
libxml2-static-2.9.1-6.el7.4.i686.rpm
libxml2-static-2.9.1-6.el7.4.x86_64.rpm
[root@ceshifwq Packages]# rpm -ivh libxml2-2.9.1-6.el7.4.x86_64.rpm  --force --nodeps //忽略软件包及文件的冲突,不验证套件依赖性
Preparing...                          ################################# [100%]
Updating / installing...
   1:libxml2-2.9.1-6.el7.4            ################################# [100%] with file from package libxml2-2.9.1-6.el7_2.3.x86_64
  1. 再次进行3步骤命令
[root@ceshifwq Packages]# rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm deltarpm-3.6-3.el7.x86_64.rpm python-deltarpm-3.6-3.el7.x86_64.rpm libxml2-python-2.9.1-6.el7.4.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:deltarpm-3.6-3.el7               ################################# [ 25%]
   2:python-deltarpm-3.6-3.el7        ################################# [ 50%]
   3:libxml2-python-2.9.1-6.el7.4     ################################# [ 75%]
   4:createrepo-0.9.9-28.el7          ################################# [100%]
  1. 安装完毕,验证createrepo命令
[root@ceshifwq Packages]# createrepo --help
Usage: genpkgmetadata.py [options]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -q, --quiet           output nothing except for serious errors
  -v, --verbose         output more debugging info.
  --profile             output timing/profile info.
  -x EXCLUDES, --excludes=EXCLUDES
                        files to exclude
  --basedir=BASEDIR     basedir for path to directories
  -u BASEURL, --baseurl=BASEURL
                        baseurl to append on all files
  -g GROUPFILE, --groupfile=GROUPFILE
                        path to groupfile to include in metadata
  -s SUMTYPE, --checksum=SUMTYPE
                        specify the checksum type to use (default: sha256)
  -p, --pretty          make sure all xml generated is formatted
  -c CACHEDIR, --cachedir=CACHEDIR
                        set path to cache dir
  -C, --checkts         check timestamps on files vs the metadata to see if we
                        need to update
  -d, --database        create sqlite database files: now default, see --no-
                        database to disable
  --no-database         do not create sqlite dbs of metadata
  --update              use the existing repodata to speed up creation of new
  --update-md-path=UPDATE_MD_PATH
                        use the existing repodata  for --update from this path
  --skip-stat           skip the stat() call on a --update, assumes if the
                        filename is the same then the file is still the same
                        (only use this if you're fairly trusting or gullible)
  --split               generate split media
  -i PKGLIST, --pkglist=PKGLIST
                        use only the files listed in this file from the
                        directory specified
  -n INCLUDEPKG, --includepkg=INCLUDEPKG
                        add this pkg to the list - can be specified multiple
                        times
  -o OUTPUTDIR, --outputdir=OUTPUTDIR
                        <dir> = optional directory to output to
  -S, --skip-symlinks   ignore symlinks of packages
  --changelog-limit=CHANGELOG_LIMIT
                        only import the last N changelog entries
  --unique-md-filenames
                        include the file's checksum in the filename, helps
                        with proxies (default)
  --simple-md-filenames
                        do not include the file's checksum in the filename
  --retain-old-md=RETAIN_OLD_MD
                        keep around the latest (by timestamp) N copies of the
                        old repodata
  --distro=DISTRO       distro tag and optional cpeid:
                        --distro'cpeid,textname'
  --content=CONTENT_TAGS
                        tags for the content in the repository
  --repo=REPO_TAGS      tags to describe the repository itself
  --revision=REVISION   user-specified revision for this repository
  --deltas              create delta rpms and metadata
  --oldpackagedirs=OLDPACKAGE_PATHS
                        paths to look for older pkgs to delta against
  --num-deltas=NUM_DELTAS
                        the number of older versions to make deltas against
  --read-pkgs-list=READ_PKGS_LIST
                        output the paths to the pkgs actually read useful with
                        --update
  --max-delta-rpm-size=MAX_DELTA_RPM_SIZE
                        max size of an rpm that to run deltarpm against (in
                        bytes)
  --workers=WORKERS     number of workers to spawn to read rpms
  --compress-type=COMPRESS_TYPE
                        which compression type to use

rpm数据库制作

[root@ceshifwq ~]# createrepo -po /root/Packages/ /root/Packages/
Spawning worker 0 with 10017 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

yum服务搭建及使用

  1. 正常的yum服务搭建
[root@ceshifwq ~]# vi /etc/yum.repos.d/yum.repo
[yum]
name=yum
baseurl=file:///root/Packages
enabled=1
gpgcheck=0
  1. yum服务测试
[root@ceshifwq ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                                                  repo name                                                            status
yum                                                                      yum                                                                  10,017
repolist: 10,017
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值