redhat yum服务器搭建

yum基本概念

yum是Yellow dogUpdater Modified的简称,起初是由yellow dog这一发行版的开发者Terra Soft研发,用python写成,那时还叫做yup(yellow dog updater),后经杜克大学的Linux@Duke开发团队进行改进,遂有此名。yum的宗旨是自动化地升级,安装/移除rpm包,收集rpm包的相关信息,检查依赖性并自动提示用户解决。yum的关键之处是要有可靠的repository,顾名思义,这是软件的仓库,它可以是http或ftp站点,也可以是本地软件池,但必须包含rpm的header, header包括了rpm包的各种信息,包括描述,功能,提供的文件,依赖性等.正是收集了这些 header并加以分析,才能自动化地完成余下的任务。

repository 是用 yum-arch 或者 createrepo命令创建的,也可以用别人已有的 repository 作为镜像。

Yum 有以下特点:

1)        *可以同时配置多个资源库(Repository)

2)        *简洁的配置文件(/etc/yum.conf)

3)        *自动解决增加或删除rpm包时遇到的倚赖性问题

4)        *使用方便

5)        *保持与RPM数据库的一致性

YUM的基本工作流程如下:

         服务器端:在服务器上面存放了所有的RPM软件包,然后以相关的功能去分析每个RPM文件的依赖性关系,将这些数据记录成文件存放在服务器的某特定目录内。

         客户端:如果需要安装某个软件时,先下载服务器上面记录的依赖性关系文件(可通过WWW或FTP方式),通过对服务器端下载的纪录数据进行分析,然后取得所有相关的软件,一次全部下载下来进行安装。

2、yum 软件包安装

2.1 Yum包确认

[oracle@xml-ora1 ~]$ rpm -q rpm

rpm-4.4.2.3-18.el5

         用rpm –q 查询软件包是否已经安装,如果没有安装则需要先下载或者使用光盘里的rmp包进行安装

2.2 Yum包下载安装

可以用wget 直接从http://yum.baseurl.org/download/网上下载,或者光盘自带的rpm包来进行安装。

3、yum操作配置说明

3.1 yum基本操作指令

yum 的基本操作包括软件的安装(本地,网络),升级(本地,网络),卸载,另外还有一定的查询功能。设定好了本地的yum之后,就可以很方便的进行安装。

[oracle@xml-ora1 ~]$ yum --help

usage: yum [options] COMMAND

List of Commands:

check-update   Check for available package updates(列出所有可更新的软件清单)

clean          Remove cached data(清除yum缓存)

deplist        List a package's dependencies(列出指定软件包所有依赖的软件清单)

downgrade      downgrade a package

erase          Remove a package or packages fromyour system(删除指定已安装的软件包)

groupinfo      Display details about a package group(列出组件包含的软件清单)

groupinstall   Install the packages in a group on yoursystem(安装组件)

grouplist      List available package groups(列出所有可安装的组件清单)

groupremove    Remove the packages in a group from yoursystem(清除组件)

help           Display a helpful usage message(列出yum所有指令说明)

info           Display details about a package orgroup of packages(获取所有或者指定包的详细信息)

info-security  Returns security data for the packageslisted, that affects your system

install        Install a package or packages on yoursystem(仅安装所有或者指定的软件)

list           List a package or groups of packages(列出所有或者指定的软件清单)

list-security   Returnssecurity data for the packages listed, that affects your system

localinstall    Installa local RPM(本地安装rpm软件包)

makecache     Generate the metadata cache(生成数据缓存)

provides       Find what package provides the givenvalue(列出软件包提供哪些文件)

reinstall       reinstalla package(重新安装指定软件包)

repolist       Display the configured softwarerepositories(显示软件仓库的配置)

resolvedep     Determine which package provides the givendependency(哪个包提供依赖)

search         Search package details for the givenstring(根据关键字模糊查找软件包)

shell          Run an interactive yum shell(运行交互式的yum shell)

update         Update a package or packages on yoursystem(安装所有或所有可更新软件)

update-minimal    Works like update, but goes to the 'newest'package match which fixes a problem that affects your system

upgrade        Update packages taking obsoletes intoaccount(大规模的版本升级,与yum update不同的是,连旧的淘汰的包也升级)

remove                 Remove a package or packages on your system (删除指定已安装的软件)

options:

  -h,--help          show this help messageand exit

  -t,--tolerant        be tolerant of errors (遇到错误继续运行yum)

 -C                run entirelyfrom cache, don't update cache(完全从缓冲区的程序包运行yum,缓冲区默认为/var/yum/cache)

 -c  [config file]     config file location(使用不同默认/etc/yum.conf之外的配置文件)

 -R  [minutes]       maximum command wait time(设置以分钟计算的等待时间)

 -d  [debug level]    debugging output level(代替/etc/yum.conf中的调试级别)

 --showduplicates     showduplicates, in repos, in list/search commands

 -e  [error level]     error output level(设置错误消息的级别。配置脚本级别设置为0)

  -q,--quiet           quiet operation(静默安装,不提示信息)

  -v,--verbose         verbose operation(查看rpm版本)

 -y                  answer yes forall questions(设置自动回答选项为y)

 --version            show Yumversion and exit(显示 YUM版本信息并退出)

 --installroot=[path]    set install root(设置为root安装)

--enablerepo=[repo]  enableone or more repositories (wildcards allowed)(启用软件仓库)

 --disablerepo=[repo]  disable oneor more repositories (wildcards allowed)(禁用软件仓库)

  -x[package], --exclude=[package]   excludepackage(s) by name or glob

 --disableexcludes=[repo]  disableexclude from main, for a repo or for everything

 --obsoletes           enableobsoletes processing during updates

 --noplugins           disable Yumplugins(禁掉yum插件)

 --nogpgcheck          disable gpgsignature checking(禁掉GPG验证检查)

 --disableplugin=[plugin]  disableplugins by name( 用名称禁掉插件)

 --enableplugin=[plugin]   enableplugins by name( 用名称启用插件)

 --skip-broken         skippackages with depsolving problems( 忽略包的依赖问题)

 --color=COLOR         controlwhether color is used(设置是否启用颜色)

 --security            Includesecurity relevant packages

 --cve=CVE             Includepackages needed to fix the given CVE

 --bz=BZ               Includepackages needed to fix the given BZ

 --advisory=ADVISORY   Includepackages needed to fix the given advisory

 Plugin Options:

yum list的特殊用法:

列出所有可更新的软件清单

命令:yum list updates

列出所有已安装的软件包

命令:yum list installed

列出已安装但不在资源库的软件包

命令:yum list extras

yum info 特殊用法:

列出所有软件包的信息

命令:yum info

列出所有可更新的软件包信息

命令:yum info updates

列出所有已安裝的软件包信息

命令:yum info installed

列出所有已安裝但不在YumRepository內的软件包信息

命令:yum info extras

清除YUM缓存特殊用法:

yum 会把下载的软件包和header存储在cache中,而不会自动删除。如果我们觉得它们占用了磁盘空间,可以使用yum clean指令进行清除,更精确的用法是yum clean headers清除header,yum clean packages清除下载的rpm包。

清除缓存目录(/var/cache/yum)下的软件包

命令:yum clean packages

清除缓存目录(/var/cache/yum)下的headers

命令:yum clean headers

清除缓存目录(/var/cache/yum)下旧的headers

命令:yum clean oldheaders

清除缓存目录(/var/cache/yum)下的软件包及旧的headers

命令:yum clean, yum cleanall (= yum clean packages; yum clean oldheaders)

3.2 /etc/yum.conf配置文件详解

yum的配置一般有两种方式,一种是直接配置/etc目录下的yum.conf文件,另外一种是在/etc/yum.repos.d目录下增加.repo文件。

yum的配置文件:

[root@xml-oms yum]# cat /etc/yum.conf

[main]

cachedir=/var/cache/yum      #yum下载的RPM包的缓存目录

keepcache=0                               #缓存是否保存,1保存,0不保存

debuglevel=2                               #调试级别(0-10),默认为2

logfile=/var/log/yum.log           #yum的日志文件所在的位置

distroverpkg=redhat-release  #yum会根据软件包判断你的发行版本,默认是redhat-release,也可以是安装的任何针对自己发行版的rpm包。

tolerant=1                                    #表示yum是否容忍命令行发生与软件包有关的错误,比如要安装1,2,3三个包,其中3此前已经安装了,如果你设为1,则yum不会出现错误信息。

exactarch=1                                 #是否只升级和你安装软件包cpu体系一致的包,如果设为1,则如你安装了一个i386的内核,则yum不会用i686的包来升级。

obsoletes=1                                 #update的参数,相当于upgrade,是否允许更新陈旧的RPM包

gpgcheck=1                                  #是否检查GPG(GNU Private Guard),一种密钥方式签名

plugins=1                                      #是否允许使用插件,默认是1允许

exclude=selinux*          #屏蔽不想更新的RPM包,可用通配符,多个RPM包之间使用空格分离。

retries=1                                       #网络连接发生错误后的重试次数,如果设为0,则会无限重试

pkgpolicy=newest                  #包的策略。一共有两个选项,newest和last,这个作用是如果你设置了多个repository,而同一软件在不同的repository中同时存在,yum应该安装哪一个,如果是newest,则yum会安装最新的那个版本。如果是last,则yum会将服务器id以字母表排序,并选择最后的那个服务器上的软件安装。一般都是选newest。

# Note: yum-RHN-plugin doesn't honor this.

metadata_expire=1h                #用于指定信息库数据库的有效期,单位为秒。

# Default.

# installonly_limit = 3                #允许保留多少个内核包

# PUT YOUR REPOS HERE OR IN separate filesnamed file.repo

# in /etc/yum.repos.d

3.3 /etc/yum.repos.d/中的文件

该目录的默认版本中只有1个文件。这个repo文件是Linux中yum源(软件仓库)的配置文件,通常一个repo文件定义了一个或者多个软件仓库的细节内容,例如我们将从哪里下载需要安装或者升级的软件包,repo文件中的设置内容将被yum读取和应用。

[root@dataserver01 ~]# ll /etc/yum.repos.d/*

-rw-r--r-- 1 root root 561 Mar 10  2010 /etc/yum.repos.d/rhel-debuginfo.repo

[oracle@dataserver01 ~]$ cat/etc/yum.repos.d/rhel-debuginfo.repo

[rhel-debuginfo]

name=Red Hat Enterprise Linux $releasever -$basearch - Debug

baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/$basearch/Debuginfo/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-debuginfo-beta]

name=Red Hat Enterprise Linux $releaseverBeta - $basearch - Debug

baseurl=ftp://ftp.redhat.com/pub/redhat/linux/beta/$releasever/en/os/$basearch/Debuginfo/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

所有服务器设置都应该遵循如下格式:

[serverid]

name=name $releasever – $basearch  

baseurl=url://

url://

enabled=

gpgcheck=

gpgkey=

参数说明:

serverid: 用于指定一个仓库,用于区别各个不同的repository,必须是一个唯一的名称。

mirrorlist:镜像站点列表,寻找可用的repository,mirrorlist和baseurl两者仅用一个即可。

baseurl:    当mirrorlist注释掉后,这个选项就是服务设置中最重要的部分,必须设置正确。其中的url: 支持的协议有 http://ftp:// file://三种。baseurl后可以跟多个url,你可以自己改为速度比较快的镜像站,但baseurl只能有一个,其中url指向的目录必须是这个repository header目录的上一级,也支持$releasever $basearch这样的变量。

name:   是对repository的描述,定义了软件仓库的名称,一般没什么作用。支持像$releasever$basearch这样的变量。

$releasever:变量定义了发行版本,通常是8,9,10等数字

$basearch:变量定义了系统的架构,可以是i386、x86_64、ppc等值。cpu的基本体系组,如i686和athlon同属i386。

failovermethode: 有两个选项roundrobin和priority,意思分别是有多个url可供选择时,yum选择的次序,roundrobin是随机选择,如果连接失 败则使用下一个,依次循环,priority则根据url的次序从第一个开始。如果不指明,默认是roundrobin。

enable:   用于指定是否使用本仓库,默认值为1,即可用

gpgcheck:    这个选项表示这个repo中下载的rpm将进行gpg的校验,已确定rpm包的来源是有效和安全的.

gpgkey:    定义用于校验的gpg密钥,可用手动导入密钥。

3.4 导入密钥

导入每个reposity的GPG key,yum可以使用gpg对包进行校验,确保下载包的完整性,所以我们先要到各个repository站点找到gpg key,一般都会放在首页的醒目位置,一些名字诸如 RPM-GPG-KEY.txt之类的纯文本文件,把它们下载,然后用rpm --importxxx.txt命令将它们导入,最好把发行版自带GPG-KEY也导入,rpm --import /usr/share/doc/redhat-release-*/RPM-GPG-KEY官方软件升级用的上。

查看官方密钥:

[oracle@dataserver01 ~]$ find / -type f -name"RPM-GPG-KEY*"

[oracle@dataserver01 ~]$ ll/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-*

-rw-r--r-- 1 root root 1175 Mar 10  2010 /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-auxiliary

-rw-r--r-- 1 root root 1706 Mar 10  2010 /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta

-rw-r--r-- 1 root root 1990 Mar 10  2010/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-former

-rw-r--r-- 1 root root 1164 Mar 10  2010 /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

-rw-r--r-- 1 root root  885 Mar 10 2010 /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-rhx

导入密钥:

[oracle@dataserver01 ~]$

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*

或者

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-beta

4、挂载光盘搭建本地YUM服务器

4.1 服务器端挂载光盘

[root@xml-ora1 mnt]# mount /dev/cdrom/mnt/cdrom/

mount: block device /dev/cdrom iswrite-protected, mounting read-only

[root@xml-ora1 mnt]# ll /mnt/cdrom/

total 3770

dr-xr-xr-x 3 root root   8192 Mar 22 2010 Cluster

dr-xr-xr-x 3 root root   8192 Mar 22 2010 ClusterStorage

-r--r--r-- 8 root root   8445 Sep 3  2008 EULA

-r--r--r-- 3 root root   8445 Mar 10 2010 eula.en_US

-r--r--r-- 8 root root  18416 Dec 1  2006 GPL

dr-xr-xr-x 4 root root   2048 Mar 22 2010 images

dr-xr-xr-x 2 root root   2048 Mar 22  2010 isolinux

4.2 客户端修改yum源

yum的一切配置信息都储存在一个叫yum.conf的配置文件中,通常位于/etc目录下,是整个yum系统的核心。先copy原yum源文件备份,然后用vim编辑yum文件并保存:

[root@xml-ora1 cdrom]# cp/etc/yum.repos.d/rhel-debuginfo.repo /etc/yum.repos.d/rhel-debuginfo.repo.bak

[root@xml-ora1 cdrom]# vi/etc/yum.repos.d/rhel-debuginfo.repo

[root@xml-ora1 cdrom]# more/etc/yum.repos.d/rhel-debuginfo.repo

[Cluster]

name=Red Hat Enterprise Linux $releasever -$basearch - Cluster

baseurl=file:///mnt/cdrom/Cluster

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[ClusterStorage]

name=Red Hat Enterprise Linux $releasever -$basearch - ClusterStorage

baseurl=file:///mnt/cdrom/ClusterStorage

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[Server]

name=Red Hat Enterprise Linux $releasever -$basearch - Server

baseurl=file:///mnt/cdrom/Server

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[VT]

name=Red Hat Enterprise Linux $releasever -$basearch - VT

baseurl=file:///mnt/cdrom/VT

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

配置文件社会自说明:

1)        [ ]内的是仓库的名称

2)        name是仓库的描述或者说资源名称

3)        baseurl 仓库的位置,Yum源的目录获取路径

4)        enabled 是否启用这个仓库,1为起用,0为禁用,本地设为1

5)        gpgcheck 是否检查GPG签名(用来验证要安装的包是不是REDHAT官方的)

4.3 客户端测试光盘Yum源使用

出现如下信息,说明配置成功:

[root@xml-ora1 etc]# yum grouplist

Setting up Group Process

Installed Groups:

  Administration Tools

  Legacy Software Development

  Legacy Software Support

  Mail Server

  Network Servers

  Server Configuration Tools

  System Tools

  Text-based Internet

   XWindow System

Available Groups:

  Authoring and Publishing

  Cluster Storage

  Clustering

  DNS Name Server

  Development Libraries

  Development Tools

  Editors

  Engineering and Scientific

  FTP Server

  GNOME Desktop Environment

  GNOME Software Development

  Games and Entertainment

  Graphical Internet

  Graphics

  Java Development

  KDE (K Desktop Environment)

  KDE Software Development

  KVM

  Legacy Network Server

  MySQL Database

  News Server

  Office/Productivity

  OpenFabrics Enterprise Distribution

  PostgreSQL Database

  Printing Support

  Sound and Video

  Web Server

  Windows File Server

   XSoftware Development

  Xen

Done

5、Copy光盘搭建本地YUM服务器

5.1 建立yum服务器目录

创建一个存放放RPM所有安装包的目录,位置自定义:

[root@xml-oms /]# mkdir -p /u01/yum

5.2 copy光盘内容到yum服务器

挂载光盘:

[root@xml-oms cdrom]# mkdir -p /mnt/cdrom/

[root@xml-oms cdrom]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom iswrite-protected, mounting read-only

获取RPM包源,将ISO中的Server目录复制到本机需要安装YUM仓库的目录下:

[root@xml-oms ~]# cp -r /mnt/cdrom/Server/  /u01/yum.

5.3 createrepo工具安装

yum 使用存储在每一个rpm包里的header信息摘要去完成它的工作,而这个摘要信息由'createrepo'程序创建,没有安装这个软件进行信息收集,系统是无法查询找到的。

安装createrepo工具,然后用这个工具生成YUM通用数据库。

[root@xml-oms Server]# rpm -q create*

package createrepo-0.4.11-3.el5.noarch.rpmis not installed

[root@xml-oms ~]# rpm -ivh/u01/yum/Server/createrepo-0.4.11-3.el5.noarch.rpm

warning:/u01/yum/Server/createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature:NOKEY, key ID 37017186

Preparing...               ########################################### [100%]

  1:createrepo            ########################################### [100%]

5.4 createrepo创建yum仓库

进入创建的YUM仓库目录/u01/yum,重建仓库信息配置文件(/u01/yum/目录下)

[root@xml-oms ~]# cd /u01/yum/

[root@xml-oms ~]# createrepo /u01/yum/

1534/3116 -Server/tomcat5-servlet-2.4-api-javadoc-5.5.23-0jpp.7.el5_3.2.x86_64.2385/3116 -Server/jakarta-commons-collections-testframework-3.2-2jpp.3.x86_64.r2679/3116 -Server/jakarta-commons-collections-testframework-javadoc-3.2-2jpp.3.3116/3116 -Server/libFS-1.0.0-3.1.i386.rpm                                    

Saving Primary metadata

Saving file lists metadata

Saving other metadata

5.5 客户端配置yum源

基于之前已经建立的YUM仓库,这里配置YUM客户端,进入/etc/yum.repos.d,创建yum.repo文件(满足*.repo即可),这里采用备份原配置文件,直接修改:

[root@xml-oms yum]# cd /etc/yum.repos.d

[root@xml-oms yum.repos.d]# ll

total 12

-rw-r--r-- 1 root root 561 Mar 10  2010 rhel-debuginfo.repo

[root@xml-oms yum.repos.d]# cp rhel-debuginfo.repo  rhel-debuginfo.repo.bak

[root@xml-oms yum.repos.d]# ll

total 12

-rw-r--r-- 1 root root 561 Mar 10  2010 rhel-debuginfo.repo

-rw-r--r-- 1 root root 561 Nov 19 17:39rhel-debuginfo.repo.bak

yum.repo文件配置信息修改为如下:

[root@xml-oms yum.repos.d]# vi rhel-debuginfo.repo

[Server]

name=Server

baseurl=file:///u01/yum/Server

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

5.6 测试YUM仓库配置是否成功

测试之前,最好把YUM的所有缓存清除一下

[root@xml-oms yum.repos.d]# yum clean all

Loaded plugins: rhnplugin, security

Cleaning up Everything

[root@xml-oms yum.repos.d]# yum grouplist

Loaded plugins: rhnplugin, security

This system is not registered with RHN.

RHN support will be disabled.

[root@xml-oms yum.repos.d]# yum install vsftpd

[root@xml-oms yum.repos.d]# yum remove vsftpd

6、FTP方式搭建远程YUM服务器(推荐)

6.1 建立yum服务器目录

创建一个存放放RPM所有安装包的目录,位置自定义:

[root@xml-oms /]# mkdir -p /u01/yum

6.2 copy光盘内容到yum服务器

挂载光盘:

[root@xml-oms cdrom]# mkdir -p /mnt/cdrom/

[root@xml-oms cdrom]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom iswrite-protected, mounting read-only

获取RPM包源,将ISO中的Server目录复制到本机需要安装YUM仓库的目录下:

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/Server//u01/yum

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/ClusterStorage//u01/yum/

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/VT/ /u01/yum/

[root@xml-oms yum]# pwd

/u01/yum

6.3 安装FTP服务器

 [root@xml-omsyum.repos.d]# rpm -ivh/u01/yum/Server/vsftpd-2.0.5-16.el5_4.1.x86_64.rpm

warning:/u01/yum/Server/vsftpd-2.0.5-16.el5_4.1.x86_64.rpm: Header V3 DSA signature:NOKEY, key ID 37017186

Preparing...                ###########################################[100%]

  1:vsftpd                ########################################### [100%]

[root@xml-oms yum.repos.d]# chkconfig --list vsftpd

vsftpd          0:off   1:off  2:off   3:off   4:off  5:off   6:off

[root@xml-oms yum.repos.d]# chkconfig vsftpd on

[root@xml-oms yum.repos.d]# chkconfig --list vsftpd

vsftpd          0:off   1:off  2:on    3:on    4:on   5:on    6:off

[root@xml-oms yum.repos.d]# service vsftpd status

vsftpd is stopped

[root@xml-oms yum.repos.d]# service vsftpd start

Starting vsftpd for vsftpd: [  OK  ]

[root@xml-oms yum.repos.d]# service vsftpd status

vsftpd (pid 15673) is running...

6.4 将FTP目录指向yum服务器目录

这里使用将ftp目录指向yum服务器目录,在/etc/vsftpd/vstpd.conf末尾添加以下参数即可。或者可以移动系统盘中的RPM文件到FTP中,或者建立链接目录到yum服务器目录。

[root@xml-oms ~]# vi /etc/vsftpd/vsftpd.conf

……

vsftpd_log_file=/var/log/vsftpd.log

use_localtime=YES

anon_root=/u01/yum

[root@xml-oms yum.repos.d]# service vsftpd restart

Shutting down vsftpd: [  OK  ]

Starting vsftpd for vsftpd: [  OK  ]

在windows下测试ftp连通和有效性:

C:UsersAdministrator>ftp 172.16.10.173

连接到 172.16.10.173。

220 (vsFTPd 2.0.5)

用户(172.16.10.173:(none)): anonymous

331 Please specify the password.

密码:

230 Login successful.

ftp> ls

200 PORT command successful. Consider usingPASV.

150 Here comes the directory listing.

Server

Repodata

6.5 createrepo工具安装

yum 使用存储在每一个rpm包里的header信息摘要去完成它的工作,而这个摘要信息由'createrepo'程序创建,没有安装这个软件进行信息收集,系统是无法查询找到的。

安装createrepo工具,然后用这个工具生成YUM通用数据库。

[root@xml-oms Server]# rpm -q create*

package createrepo-0.4.11-3.el5.noarch.rpmis not installed

[root@xml-oms ~]# rpm -ivh/u01/yum/Server/createrepo-0.4.11-3.el5.noarch.rpm

warning:/u01/yum/Server/createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature:NOKEY, key ID 37017186

Preparing...               ########################################### [100%]

  1:createrepo            ########################################### [100%]

6.6 createrepo重建仓库

         在RHEL 5中每个目录下的repodata目录下都有一个repomd.xml,该文件中就记录了rpm包的依赖关系,还有一个comps-rhel5-*.xml文件,这个文件主要记录分组情况,建立yum仓库时,需要先重建该文件。

重建Server:

[root@xml-oms repodata]# cd /u01/yum/Server/repodata/

[root@xml-oms repodata]# pwd

/u01/yum/Server/repodata

[root@xml-oms repodata]# ls

comps-rhel5-server-core.xml  other.xml.gz    repomd.xml

filelists.xml.gz             primary.xml.gz  TRANS.TBL

[root@xml-oms repodata]#

createrepo -g /u01/yum/Server/repodata/comps-rhel5-server-core.xml/u01/yum/Server

2679/3116 -jakarta-commons-collections-testframework-javadoc-3.2-2jpp.3.x86_64.3116/3116 -libFS-1.0.0-3.1.i386.rpm                                           

Saving Primary metadata

Saving file lists metadata

Saving other metadata

重建VT:

[root@xml-oms yum]# cd /u01/yum/VT/repodata/

[root@xml-oms repodata]# pwd

/u01/yum/VT/repodata

[root@xml-oms repodata]#createrepo -g/u01/yum/VT/repodata/comps-rhel5-vt.xml /u01/yum/VT/

2/71 - celt051-0.5.1.3-0.el5.i386.rpm                                           

Error opening package -Virtualization-ta-IN-5.2-11.noarch.rpm

21/71 -Virtualization-kn-IN-5.2-11.noarch.rpm                                 

Error opening package -Virtualization-pa-IN-5.2-11.noarch.rpm

71/71 - Virtualization-pt-BR-5.2-11.noarch.rpm                                 

Saving Primary metadata

Saving file lists metadata

Saving other metadata

重建Cluster:

[root@xml-oms repodata]# cd /u01/yum/Cluster

[root@xml-oms Cluster]# pwd

/u01/yum/Cluster

[root@xml-oms Cluster]# createrepo -g/u01/yum/Cluster/repodata/comps-rhel5-cluster.xml /u01/yum/Cluster

32/32 -Cluster_Administration-mr-IN-5.2-1.noarch.rpm                          

Saving Primary metadata

Saving file lists metadata

Saving other metadata

重建ClusterStorage:

[root@xml-oms Cluster]# cd /u01/yum/ClusterStorage/

[root@xml-oms ClusterStorage]# pwd

/u01/yum/ClusterStorage

[root@xml-oms ClusterStorage]#createrepo -g/u01/yum/ClusterStorage/repodata/comps-rhel5-cluster-st.xml/u01/yum/ClusterStorage/

39/39 -kmod-cmirror-0.1.22-3.el5.x86_64.rpm                                   

Saving Primary metadata

Saving file lists metadata

Saving other metadata

6.7 准备客户端yum配置文件

在每个客户端使用YUM时,必须需要修改配置文件/etc/yum.repos.d/*.repo。 这个文件名称可以随便定义,但是扩展名必须是repo。新建一个YUM配置文件ftp.repo,如下:

[root@xml-oms yum]# cp /etc/yum.repos.d/rhel-debuginfo.repo/etc/yum.repos.d/ftp.repo

[root@xml-oms yum]# ll /etc/yum.repos.d/

ftp.repo                 rhel-debuginfo.repo      rhel-debuginfo.repo.bak

[root@xml-oms yum]# vi /etc/yum.repos.d/ftp_rhel5.5x64.repo

[ftp-rhel5.5-base]

name=Redhat Enterprise 5.5x64

baseurl=ftp://172.16.10.173/Server

gpgcheck=0

enabled=1

[ftp-rhel5.5-vt]

name=Redhat Enterprise 5.5x64

baseurl=ftp://172.16.10.173/VT

gpgcheck=0

enabled=1

[ftp-rhel5.5-cluster]

name= Redhat Enterprise 5.5x64

baseurl=ftp://172.16.10.173/Cluster

gpgcheck=0

enabled=1

[ftp-rhel5.5-ClusterStorage]

name= Redhat Enterprise 5.5x64

baseurl=ftp://172.16.10.173/ClusterStorage

复制一份到ftp目录下,提供下载。

[root@xml-oms yum]# cp /etc/yum.repos.d/ftp_rhel5.5x64.repo /u01/yum/

6.8 客户端更新配置yum源

         这里客户可以有2中方式下载服务器的yum源文件,FTP下载或者wget:

[root@xml-ora1 yum.repos.d]# cd /etc/yum.repos.d

[root@xml-ora1 yum.repos.d]# pwd

/etc/yum.repos.d

[root@xml-ora1 yum.repos.d]# wgetftp://172.16.10.173/ftp_rhel5.5x64.repo

--2012-11-20 11:04:37--  ftp://172.16.10.173/ftp_rhel5.5x64.repo

           => `ftp_rhel5.5x64.repo'

Connecting to 172.16.10.173:21...connected.

Logging in as anonymous ... Logged in!

==> SYST ... done.    ==> PWD ... done.

==> TYPE I ... done.  ==> CWD not needed.

==> SIZE ftp_rhel5.5x64.repo ... 463

==> PASV ... done.    ==> RETR ftp_rhel5.5x64.repo ... done.

Length: 463

100%[======================================>]463         --.-K/s  in 0s     

2012-11-20 11:04:37 (20.1 MB/s) -`ftp_rhel5.5x64.repo' saved [463]

或者ftp:

[root@xml-ora1 ~]# ftp 172.16.10.173

6.9客户端yum测试

清除YUM缓存 ,测试:

[root@xml-ora1 yum.repos.d]# yum clean all

Cleaning up Everything

[root@xml-ora1 yum.repos.d]# yum check-update

ftp-rhel5.5-ClusterStorage                               | 1.1 kB     00:00    

ftp-rhel5.5-ClusterStorage/primary                       | 8.2 kB     00:00    

ftp-rhel5.5-ClusterStorage                                               39/39

ftp-rhel5.5-base                                         | 1.1kB     00:00    

ftp-rhel5.5-base/primary                                 | 1.1 MB     00:00    

ftp-rhel5.5-base                                                     3116/3116

ftp-rhel5.5-cluster                                      | 1.1kB     00:00    

ftp-rhel5.5-cluster/primary                              | 5.8 kB     00:00    

ftp-rhel5.5-cluster                                                      32/32

ftp-rhel5.5-vt                                           |1.1 kB     00:00    

ftp-rhel5.5-vt/primary                                   |  19 kB    00:00    

ftp-rhel5.5-vt:[#####################################################  ] 69/71[

注意,看到上面的ftp-rhel5.5-ClusterStorage信息说明是从我们的ftp源进行数据更新的。说明配置客户端源成功。

7、HTTP方式搭建远程YUM服务器

7.1 建立yum服务器目录

创建一个存放放RPM所有安装包的目录,位置自定义:

[root@xml-oms /]# mkdir -p /u01/yum

7.2 copy光盘内容到yum服务器

挂载光盘:

[root@xml-oms cdrom]# mkdir -p /mnt/cdrom/

[root@xml-oms cdrom]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom iswrite-protected, mounting read-only

获取RPM包源,将ISO中的Server目录复制到本机需要安装YUM仓库的目录下:

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/Server//u01/yum

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/ClusterStorage//u01/yum/

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/VT/ /u01/yum/

[root@xml-oms yum]# pwd

/u01/yum

7.3 安装httpd

[root@xml-oms yum]# rpm -ivh /mnt/cdrom/Server/httpd-*

httpd-2.2.3-43.el5.x86_64.rpm         httpd-devel-2.2.3-43.el5.x86_64.rpm

httpd-devel-2.2.3-43.el5.i386.rpm     httpd-manual-2.2.3-43.el5.x86_64.rpm

7.4 修改http.conf

http.conf是apache的主配置文件,为了避免启动报错。最好备份一下:

[root@localhost conf]# cp -p /etc/httpd/conf/httpd.conf/etc/httpd/conf/httpd.conf.bak

把 DocumentRoot 改成拷rpm包的目录,大约在281行

[root@localhost conf]#vi httpd/conf +281

 ---->  281 DocumentRoot "/u01/yum/Server"

7.5重启apahce服务

[root@localhost conf]# service httpd restart

Stopping httpd: [  OK  ]

Starting httpd: [  OK  ]

7.6 客户端配置

         在配置文件目录心中一个http.repo配置文件

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

/etc/yum.repos.d

[root@localhost yum.repos.d]# cat http.repo

[http-rhel5.5-base]

name=Redhat Enterprise 5.5x64

baseurl=http://172.16.10.173

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

7.7 软件安装测试

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

[root@localhost yum.repos.d]#yum install sendmail –y

8、RHEL5使用Cent-OS5的YUM源

由于CentOS-5是RHEL-5的免费版,可以使用CentOS-5的yum源来达到在RHEL-5下更新软件。

8.1 编辑YUM 配置文件

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

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

rhel-debuginfo.repo

[root@dataserver01 yum.repos.d]# pwd

/etc/yum.repos.d

[root@Server yum.repos.d]# vi centos5.repo

[base]

name=Red Hat Enterprise Linux $releasever-Base

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever5&arch=$basearch&repo=os

#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

baseurl=http://ftp.sjtu.edu.cn/centos/5/os/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#released updates

[update]

name=Red Hat Enterprise Linux $releasever-Updates

#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=updates

baseurl=http://ftp.sjtu.edu.cn/centos/5/updates/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#packages used/produced in the build butnot released

[addons]

name=Red Hat Enterprise Linux $releasever-Addons

#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=addons

baseurl=http://ftp.sjtu.edu.cn/centos/5/addons/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#additional packages that may be useful

[extras]

name=Red Hat Enterprise Linux $releasever-Extras

#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=extras

baseurl=http://ftp.sjtu.edu.cn/centos/5/extras/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

8.2 导入RPM-KEY

[root@dataserver01 yum.repos.d]#

rpm --importhttp://ftp.sjtu.edu.cn/centos/5/os/i386/RPM-GPG-KEY-CentOS-5

8.3 清理以下缓存测试

[root@dataserver01 yum.repos.d]# yum clean all

Loaded plugins: rhnplugin, security

Cleaning up Everything

[root@dataserver01 yum.repos.d]#yum list

原文地址:https://www.cnblogs.com/wqswjx/p/5496360.html