有时候可能会因为工作需要,会在本地创建yum源以方便安装有复杂依赖关系的软件安装包,或是为了方便局域网内其他服务器安装更新程序

一、安装createrepo

    1.由于创建yum需要createrepo程序,所以创建之前可以检测本机上是否已经安装了createrepo程序

        # rpm -q createrepo

    2.如果没有安装可自行下载安装,安装createrepo需要以下三个程序包

        createrepo

        deltarpm

        python-deltarpm

    3.也可以通过创建国内yum源,来安装createrepo,可以轻松的解决其之间的依赖关系

[root@linux updates]# yum install createrepoSetting up Install ProcessResolving Dependencies--> Running transaction check---> Package createrepo.noarch 0:0.9.9-22.el6 will be installed--> Processing Dependency: python-deltarpm for package: createrepo-0.9.9-22.el6.noarch--> Running transaction check---> Package python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed--> Processing Dependency: deltarpm = 3.5-0.5.20090913git.el6 for package: python-deltarpm-3.5-0.5.20090913git.el6.x86_64--> Running transaction check---> Package deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved==================================================================================================================== Package                      Arch                Version                                 Repository           Size====================================================================================================================Installing: createrepo                   noarch              0.9.9-22.el6                            163-OS               96 kInstalling for dependencies: deltarpm                     x86_64              3.5-0.5.20090913git.el6                 163-OS               71 k python-deltarpm              x86_64              3.5-0.5.20090913git.el6                 163-OS               27 kTransaction Summary====================================================================================================================Install       3 Package(s)Total download size: 194 kInstalled size: 520 kIs this ok [y/N]: yDownloading Packages:(1/3): createrepo-0.9.9-22.el6.noarch.rpm                                                    |  96 kB     00:07     (2/3): deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm                                           |  71 kB     00:04     (3/3): python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm                                    |  27 kB     00:01     --------------------------------------------------------------------------------------------------------------------Total                                                                                12 kB/s | 194 kB     00:16     Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction  Installing : deltarpm-3.5-0.5.20090913git.el6.x86_64                                                          1/3   Installing : python-deltarpm-3.5-0.5.20090913git.el6.x86_64                                                   2/3   Installing : createrepo-0.9.9-22.el6.noarch                                                                   3/3   Verifying  : python-deltarpm-3.5-0.5.20090913git.el6.x86_64                                                   1/3   Verifying  : createrepo-0.9.9-22.el6.noarch                                                                   2/3   Verifying  : deltarpm-3.5-0.5.20090913git.el6.x86_64                                                          3/3 Installed:  createrepo.noarch 0:0.9.9-22.el6                                                                                  Dependency Installed:  deltarpm.x86_64 0:3.5-0.5.20090913git.el6             python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6            Complete![root@linux updates]#

二、创建本地yum源

    1、将安装光盘包中的httpd*程序复制到/tmp/httpd目录下

        #mkdir /tmp/httpd

        # mount /dev/sr0 /mnt/cd

        # cp mnt/cd/Packages/httpd* /tmp/httpd

        # cd /tmp/httpd

    2、使用createrepo创建yum源

[root@linux httpd]# createrepo /tmp/httpd/    //创建yum源Spawning worker 0 with 5 pkgsWorkers FinishedGathering worker resultsSaving Primary metadataSaving file lists metadataSaving other metadataGenerating sqlite DBsSqlite DBs complete   //创建完成[root@linux httpd]# lshttpd-2.2.15-39.el6.centos.x86_64.rpm        httpd-manual-2.2.15-39.el6.centos.noarch.rpmhttpd-devel-2.2.15-39.el6.centos.i686.rpm    httpd-tools-2.2.15-39.el6.centos.x86_64.rpmhttpd-devel-2.2.15-39.el6.centos.x86_64.rpm  repodata

注:创建完成后会在其目录下生产一个repodata文件夹

[root@linux repodata]# ls2739576ea0b7fc7093c70c8a99fda0bbd55139adf14046c6f6c0f132948cced9-other.xml.gz6ae304f284396ef2c9c45281b66f24aaa721281b4af80f07505996cfb6277b19-filelists.sqlite.bz2afe26ec861be2ac48498fc7416b762991a29244494c37040eb1e7b2b1ae95c77-primary.sqlite.bz2c4886b02cca505fb78991113b2517cabfa674393c7f973699e87fcf6a5342b1e-filelists.xml.gzcb9b6fc78f755fd87f461beb816145912555657db3f8455df700332c0fb31686-primary.xml.gze6e56919253a8059bac51e7178dadd98b26de2272abb743026be5ba60ef42b4a-other.sqlite.bz2repomd.xml

    3、在/etc/yum.repo.d/目录下创建repo文件

# vim /etc/yum.repos.d/local.repo [local-httpd]name=Local httpdbaseurl=file:///tmp/httpd/        //注意此处本地是三个“/”gpgcheck=0enable=1

    4、验证是否创建成功

清除本机yum源缓存

[root@linux repodata]# yum clean allCleaning repos: local-httpdCleaning up Everything[root@linux repodata]# rm -rf /var/cache/yum/*

查看本例yum源列表

[root@linux repodata]# yum repolistrepo id                                                repo name                                              statuslocal-httpd                                            Local httpd                                            5repolist: 5[root@linux repodata]# yum list availableAvailable Packageshttpd-devel.i686                                    2.2.15-39.el6.centos                                 local-httpdhttpd-devel.x86_64                                  2.2.15-39.el6.centos                                 local-httpdhttpd-manual.noarch                                 2.2.15-39.el6.centos                                 local-httpd[root@linux repodata]#

根据已经创建的本地yum源安装httpd程序

[root@linux httpd]# yum install httpdSetting up Install ProcessResolving Dependencies--> Running transaction check---> Package httpd.x86_64 0:2.2.15-39.el6.centos will be installed--> Finished Dependency ResolutionDependencies Resolved==================================================================================================================== Package              Arch                  Version                                Repository                  Size====================================================================================================================Installing: httpd                x86_64                2.2.15-39.el6.centos                   local-httpd                825 kTransaction Summary====================================================================================================================Install       1 Package(s)Total download size: 825 kInstalled size: 2.9 MIs this ok [y/N]: yDownloading Packages:Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction  Installing : httpd-2.2.15-39.el6.centos.x86_64                                                                1/1   Verifying  : httpd-2.2.15-39.el6.centos.x86_64                                                                1/1 Installed:  httpd.x86_64 0:2.2.15-39.el6.centos                                                                               Complete![root@linux httpd]#

5.启动httpd       

[root@linux repodata]# service httpd restartStopping httpd:                                            [FAILED]Starting httpd: httpd: apr_sockaddr_info_get() failed for linuxhttpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName                                                           [  OK  ][root@linux repodata]#

6、为了能够让局域网内其他机器能够访问到此WEB,同时还需要关闭iptables服务:

    # service iptables stop        //如果不关闭其他机器可能无法访问此WEB

三、根据已经安装的http创建http yum源

    1、复制光盘中的mysql安装包到httpd目录下

[root@linux html]# cp /mnt/cd/Packages/mysql-5.1.73-3.el6_5.x86_64.rpm  /var/httpd/html/[root@linux html]# lsindex.html.bak  mysql-5.1.73-3.el6_5.x86_64.rpm

    2、创建yum源

[root@linux html]# createrepo /var/www/html/Spawning worker 0 with 1 pkgsWorkers FinishedGathering worker resultsSaving Primary metadataSaving file lists metadataSaving other metadataGenerating sqlite DBsSqlite DBs complete[root@linux html]# lsindex.html.bak  mysql-5.1.73-3.el6_5.x86_64.rpm  repodata

    3、创建repo文件

 上述工作一切就绪后,就可以在局域网内其他机器上编辑repo文件了

# vim /etc/yum.repos.d/mysql.repo

[Mysql]name=httpd--Mysql--installbaseurl=http://192.168.67.131/gpgcheck=0enable=1

    4、清除yum缓存并查看列表

    

[root@linux html]# yum clean allCleaning repos: Mysql local-httpdCleaning up Everything[root@linux html]# rm -rf /var/cache/yum/*[root@linux html]# yum repolistMysql                                                                                        | 2.9 kB     00:00     Mysql/primary_db                                                                             | 3.3 kB     00:00     local-httpd                                                                                  | 2.9 kB     00:00 ... local-httpd/primary_db                                                                       | 7.2 kB     00:00 ... repo id                                           repo name                                                   statusMysql                                             httpd--Mysql--install                                       1local-httpd                                       Local httpd                                                 5repolist: 6[root@linux html]#

    5、查看可安装但为安装的yum源内的程序

[root@linux html]# yum list availableAvailable Packageshttpd-devel.i686                                    2.2.15-39.el6.centos                                 local-httpdhttpd-devel.x86_64                                  2.2.15-39.el6.centos                                 local-httpdhttpd-manual.noarch                                 2.2.15-39.el6.centos                                 local-httpdmysql.x86_64                                        5.1.73-3.el6_5                                       Mysql      [root@linux html]#

    6、使用yum安装mysql    

[root@linux html]# yum install mysqlSetting up Install ProcessResolving Dependencies--> Running transaction check---> Package mysql.x86_64 0:5.1.73-3.el6_5 will be installed--> Finished Dependency ResolutionDependencies Resolved==================================================================================================================== Package                 Arch                     Version                             Repository               Size====================================================================================================================Installing: mysql                   x86_64                   5.1.73-3.el6_5                      Mysql                   894 kTransaction Summary====================================================================================================================Install       1 Package(s)Total download size: 894 kInstalled size: 2.4 MIs this ok [y/N]: yDownloading Packages:mysql-5.1.73-3.el6_5.x86_64.rpm                                                              | 894 kB     00:00     Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction  Installing : mysql-5.1.73-3.el6_5.x86_64                                                                      1/1   Verifying  : mysql-5.1.73-3.el6_5.x86_64                                                                      1/1 Installed:  mysql.x86_64 0:5.1.73-3.el6_5                                                                                     Complete![root@linux html]#

OK   通过创建的http YUM源已经成功创建完成

如果不足之处还请各位斧正..........