程序包管理之制作yum本地源

Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。

使用本地yum源有两种方式:第一直接使用光盘镜像,不过此方法仅限本机使用;第二种创建本地仓库,然后使用http或者nfs和ftp等方式向外部提供yum repository。

第一种:如何使用发行版光盘作为yum repository(以CentOS 6.8为例实验)

1.挂载光盘到制定挂载点:
    此处我们使用CentOS的自动挂载功能来实现:

[root@localhost ~]# cd /misc

[root@localhost misc]# cd cd

[root@localhost cd]# ls

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

2.新建yum repo配置文件:

[root@localhost cd]# cd /etc/yum.repos.d

[root@localhost yum.repos.d]# ls

base.repo

[root@localhost yum.repos.d]# cat base.repo #必须以.repo结尾

#

#

#

#

[base] #仓库的ID唯一不能重复

name=CentOS 7 #仓库功能的描述

baseurl=file:///misc/cd/ #repodata所在路径

enabled=1 #开启仓库,0是关闭,不写默认是1

gpgcheck=1 #是否检查gpg,1是检查,0是不检查

gpgkey=file:///etc/pki/rpm-gpg/ #gpgkey的路径

第二种:创建本地yum仓库

如果你是一名运维工程师,为了方便公司内部网络中的服务器安装软件,同时也节省网络带宽,此时就可以在公司内部创建一个yum仓库。

具体步骤:

1.在发行版光盘中寻找createrepo:

[root@localhost ~]# type createrepo
createrepo is hashed (/usr/bin/createrepo) #此处安装系统时已做安装

2.确定repository输出方式:

(1)本地输出:提供一个放置rpm包的本地路径;file的形式

(2)网络输出:提供一个文件服务器,配置好ftp或http服务;

ftp服务:

安装程序包:vsftpd

文件存放路径:/var/ftp/pub

启动服务:service vsftpd start

http服务:

安装程序包:httpd

文件存放路径:/var/www/html

启动服务:service httpd start

注意确保防火墙关闭;

我们此处以本地输出为例。

3.在准备好的目录中放置rpm程序包文件

可以通过cp命令将光盘中的程序包拷贝到以上输出目录当中。

[root@localhost ~]# mkdir yum

[root@localhost ~]# cp mogilefs/* yum

[root@localhost ~]# cp galera_cluster/* yum

#创建yum文件夹并做了仓库路径,将准备好的rpm包复制进yum目录当中

[root@localhost ~]# cd yum
[root@localhost yum]# ls
galera-25.3.9-1.rhel7.el7.centos.x86_64.rpm  MariaDB-5.5.46-centos7-x86_64-shared.rpm Perlbal-1.78-1.el6.noarch.rpm
jemalloc-3.6.0-1.el7.x86_64.rpm  MariaDB-5.5.46-centos7-x86_64-test.rpm   Perlbal-doc-1.78-1.el6.noarch.rpm
jemalloc-devel-3.6.0-1.el7.x86_64.rpmMariaDB-Galera-5.5.46-centos7-x86_64-server.rpm  perl-Danga-Socket-1.61-1.el6.rf.noarch.rpm
MariaDB-5.5.46-centos7-x86_64-client.rpm MariaDB-Galera-5.5.46-centos7-x86_64-test.rpmperl-MogileFS-Client-1.14-1.el6.noarch.rpm
MariaDB-5.5.46-centos7-x86_64-common.rpm MogileFS-Server-2.46-2.el6.noarch.rpmperl-Net-Netmask-1.9015-8.el6.noarch.rpm
MariaDB-5.5.46-centos7-x86_64-compat.rpm MogileFS-Server-mogilefsd-2.46-2.el6.noarch.rpm  perl-Perlbal-1.78-1.el6.noarch.rpm
MariaDB-5.5.46-centos7-x86_64-devel.rpm  MogileFS-Server-mogstored-2.46-2.el6.noarch.rpm
MariaDB-5.5.46-centos7-x86_64-server.rpm MogileFS-Utils-2.19-1.el6.noarch.rpm

4.对此目录运行createrepo命令即可

cd到yum目录执行createrepo;

[root@localhost ~]# createrepo yum
Spawning worker 0 with 6 pkgs
Spawning worker 1 with 6 pkgs
Spawning worker 2 with 5 pkgs
Spawning worker 3 with 5 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

![](http://i.imgur.com/WwcruFd.png)

此处可以看到repodata文件夹已经创建成功

下面我们来测试创建的yum仓库是否可用

1.在本机/etc/yum.repos.d/目录中创建一个.repo结尾的文件,这里我们就叫test.repo,里面添加上如下内容:

[root@localhost yum]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# touch test.repo

程序包管理之制作yum本地源

 [root@localhost yum]# yum list

程序包管理之制作yum本地源

2.在本机上更新本地yum缓存

清理缓存:yum clean all

[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: test
Cleaning up everything
Cleaning up list of fastest mirrors

创建缓存:yum makecache

root@localhost yum.repos.d]# yum makecache Loaded plugins: fastestmirror, langpacks test| 2.9 kB 00:00:00 (1/3): test/filelistsdb| 67 kB 00:00:00 (2/3): test/otherdb| 4.0 kB 00:00:00 (3/3): test/primary_db | 25 kB 00:00:00 Determining fastest mirrors Metadata Cache Created

3.查询新的yum仓库内容

yum list all

[root@localhost yum.repos.d]# yum list all

Available Packages
MariaDB-Galera-server.x86_64 5.5.46-1.el7.centos  test 
MariaDB-Galera-test.x86_64   5.5.46-1.el7.centos  test 
MariaDB-client.x86_645.5.46-1.el7.centos  test 
MariaDB-common.x86_645.5.46-1.el7.centos  test 
MariaDB-compat.x86_645.5.46-1.el7.centos  test 
MariaDB-devel.x86_64 5.5.46-1.el7.centos  test 
MariaDB-server.x86_645.5.46-1.el7.centos  test 
MariaDB-shared.x86_645.5.46-1.el7.centos  test 
MariaDB-test.x86_64  5.5.46-1.el7.centos  test 
MogileFS-Server.noarch   2.46-2.el6   test 
MogileFS-Server-mogilefsd.noarch 2.46-2.el6   test 
MogileFS-Server-mogstored.noarch 2.46-2.el6   test 
MogileFS-Utils.noarch2.19-1.el6   test 
Perlbal.noarch   1.78-1.el6   test 
Perlbal-doc.noarch   1.78-1.el6   test 
galera.x86_6425.3.9-1.rhel7.el7.centostest 
jemalloc.x86_64  3.6.0-1.el7  test 
jemalloc-devel.x86_643.6.0-1.el7  test 
perl-Danga-Socket.noarch 1.61-1.el6.rftest 
perl-MogileFS-Client.noarch  1.14-1.el6   test 
perl-Net-Netmask.noarch  1.9015-8.el6 test 
perl-Perlbal.noarch  1.78-1.el6

4.安装应用

yum install [Packge_name]

[root@localhost yum.repos.d]# yum install Perlbal.noarch
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package Perlbal.noarch 0:1.78-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================
 Package  ArchVersion  Repository Size
===========================================================================================================================================
Installing:
 Perlbal  noarch  1.78-1.el6   test  5.7 k

Transaction Summary
===========================================================================================================================================
Install  1 Package

Total download size: 5.7 k
Installed size: 4.4 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : Perlbal-1.78-1.el6.noarch   1/1 
  Verifying  : Perlbal-1.78-1.el6.noarch   1/1 

Installed:
  Perlbal.noarch 0:1.78-1.el6  

Complete!

安装测试成功!

原创文章,作者:YOUNG,如若转载,请注明出处:http://www.178linux.com/38965

(0)
YOUNGYOUNG
上一篇 2016-08-24
下一篇 2016-08-24

相关推荐

  • bash脚本编程语言if语句,find文件查找和压缩工具及课后作业练习

    一.概述 使用read命令来接受输入 使用read来把输入值分配给一个或多个shell变量: -p指定要显示的提示 -t TIMEOUT read从标准输入中读取值,给每个单词分配一个变量 所有剩余单词都被分配给最后一个变量 read -p “Enter a filename:“ FILE 过程式编程语言: 顺序执行 选择执行 循环执行 条件选择if语句 选…

    Linux干货 2016-08-22
  • Find命令简介与使用

    用途:         find命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。 语法: find [OPTION]… [查找…

    Linux干货 2016-08-30
  • lvs nat模型调度双http服务且http上布置discuz

    实验的拓扑图: 实验方案: 我们先在real server上编译安装好http,然后,咋们切换到mysql服务器上安装mysql,在换到http主机上编译php的工作方式基于模块的,再把discuz资源放到http的资源访问目录下,且在双方http主机上布上rsync服务器,双反的主机也要加上inotify来实时关注http访问目录的资源变化,有变化就要数据…

    Linux干货 2015-10-22
  • 马哥教育网络班21期-第5周课程练习

    第5周课程练习 1、 显示/boot/grub/grub.conf中以至少一个空白字符开头的行; # grep "^[[:space:]]\+" /boot/grub/grub.conf 2、 显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; # egrep "…

    Linux干货 2016-08-02
  • 条件判断(if,case)和循环(for,until,while等)详解(附例题正解)

    脚本中的if条件判断和循环 在linux下,写脚本是我们必不可少的。在写脚本的过程中,if判断和各种的循环是我们常用的。这里,详细的说一下条件判断以及循环的使用。 条件判断:if 和 else 1.if shell程序中的条件分支是通过if条件语句来实现的,其格式一般为if -then -fi ,这样的是单分支语句,还有的一种就是if-then-else-f…

    Linux干货 2016-08-18
  • 网络基本概念介绍

    Linux网络属性管理 网络节点分布:广域网、城域网、局域网 按交换方式:线路交换、报文交换、分组交换 按网络拓扑结构:以太网,令牌环网、星型网络、树型网络、总线型网络、网状网络 Ethernet: CSMA/CD 载波侦探/多路访问/冲突检测机制 1.想发送信息的接点首先“监听”信道,看是否有信号在传输。如果信道空闲,就立即发送。2.如果信道忙,则继续监听…

    Linux干货 2016-07-29