在虚拟机上使用CentOS6的两个iso文件创建本地yum仓库和http仓库

yum客户端和服务器端都是本虚拟机

一、创建本地磁盘访问的yum仓库


条件和要求:

a.guest虚拟机需要添加2个光驱,分别装载CentOS6.4发行版的DVD1和DVD2

b.DVD1和DVD2的挂载目录分别是:/media/cdrom/下的os和extras,并设置开机挂载

c.使用CentOS-Media.repo作为yum客户端配置文件,将其他repo文件删掉或改名

d.分别安装各DVD上的包: zsh包在DVD1上、zsh-html包在DVD2上

执行步骤:

1.挂载光盘

[root@www ~]# mkdir -p /media/cdrom/{os,extras}

[root@www ~]# ls /dev/cdrom*
/dev/cdrom  /dev/cdrom1

[root@www ~]# vim /etc/fstab  #添加下面两行设置开机启动
/dev/cdrom    /media/cdrom/osiso9660defaults,ro0 0
/dev/cdrom1/media/cdrom/extrasiso9660 defaults,ro0 0
[root@www ~]# mount -a
[root@www ~]# mount
.....(略去)......
/dev/sr0 on /media/cdrom/os type iso9660 (ro)
/dev/sr1 on /media/cdrom/extras type iso9660 (ro)
#如果你的iso文件放在guest虚拟机的某个文件系统目录中,则需要使用如下配置
#/XXXX.iso /XXXiso9660 defaults,loop,ro0 0

#由于DVD上已经包含yum仓库的元数据,因此无需创建专门的yum仓库
[root@www ~]# cd /media/cdrom/os/
[root@www os]# ls repodata/
08faa81a545bb1157be476ada0524206d137084f50d285b9f7f875b3b02839df-other.sqlite.bz2
2727fcb43fbe4c1a3588992af8c19e4d97167aee2f6088959221fc285cab6f72-c6-x86_64-comps.xml
6ce81da964e0028da004fd4deb817a89d4db450a3d0af4a826d7c6abad0168a9-other.xml.gz
cb96727ddc89e5e1786456c6f2c08a81418296f949470311ee9c2ebb1a6ccc7d-c6-x86_64-comps.xml.gz
d221c3d1c22cc4e4c4dafc40aa2bf3d353d67882a0d98f7f88ad8215f2d48818-filelists.sqlite.bz2
df5b1510036696c30d69d32d0609c5bfb6f121083ff97bf98a7540c644f6e4ac-primary.sqlite.bz2
f050fc8b41b566153c15bb1d287e6c5a016809415bfce9ddc3540176ce8afdaf-filelists.xml.gz
f6f4019e1d7ff186c247c58d394a5faaab51e9ca1fb9c174c94a204588536d14-primary.xml.gz
repomd.xml
TRANS.TBL

2.配置yum客户端配置

[root@www os]# cd /etc/yum.repos.d
[root@www yum.repos.d] ls
CentOS-Media.repo

[root@www yum.repos.d]# vim CentOS-Media.repo
[root@www yum.repos.d]# cat CentOS-Media.repo
[c6-media]
name=CentOS-$releasever - Media - Local
baseurl=file:///media/cdrom/os     #可以在baseurl同时设置两个DVD的挂载目录
    file:///media/cdrom/extras
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

3.通过本地yum测试软件安装

#先清缓存
[root@www os]# yum clean all  
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: c6-media
Cleaning up Everything
Cleaning up list of fastest mirrors

#刷新yum源
[root@www os]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
 * c6-media: 
file:///media/cdrom/extras/repodata/repomd.xml: [Errno 14] Could not open/read file:///media/cdrom/extras/repodata/repomd.xml
Trying other mirror.
c6-media-local                                                                                   | 4.0 kB     00:00 ... 
c6-media-local/primary_db                                                                        | 4.4 MB     00:00 ... 
repo id                                             repo name                                                     status
c6-media-local                                      CentOS-6 - Media - Local                                      6,381
repolist: 6,381
#出现了Errno,不用管它,因为DVD2是附加盘而没有仓库目录repodata

4.测试安装DVD1和DVD2上的包

[root@www ~]# yum install -y zsh       
.....(略去)......

[root@www ~]# yum install -y zsh-html
.....(略去)......


OK,本地yum源创建成功

二、创建HTTP访问的yum仓库

条件和要求:

a.guest虚拟机需要添加2个光驱,分别装载CentOS6.4发行版的DVD1和DVD2

b.DVD1和DVD2的挂载目录分别是:/media/cdrom/下的os和extras

c.参考mirrors.aliyun.com的路径做HTTP仓库,www.tangsw.com为本虚拟机主机名。

      包含DVD1内容的yum仓库base-http路径: http://www.tangsw.com/centos/6/os/x86_64/下,主要目录为Packages和repodata

      包含DVD2内容的yum仓库extras-http路径 : http://www.tangsw.com/centos/6/extras/x86_64下,主要目录为Packages和repodata

          通过软连接实现将光盘包目录Packages映射到http服务器的数据目录Packages,让客户端能用yum下载rpm包来安装

           /media/cdrom/{os,extras}/Packages 映射到 /var/www/html/centos/6/{os,extras}/x86_64/Packages

d.使用CentOS-Media.repo作为yum的http客户端配置文件

e.分别安装各yum仓库上的包: zsh包在base-http上、zsh-html包在extras-http上

执行步骤:

1.挂载光盘(按“一、创建yum本地仓库”来做),安装后面用到的工具:createrepo命令、httpd包

2.准备一些建立yum仓库前的目录和文件

#创建仓库目录
[root@www ~]# mkdir -p /var/www/html/centos/6/{os,extras}/x86_64/repodata

#创建包目录
[root@www ~]# ln -s /media/cdrom/os/Packages/ /var/www/html/centos/6/os/x86_64/Packages
[root@www ~]# ln -s /media/cdrom/extras/Packages/ /var/www/html/centos/6/extras/x86_64/Packages

#复制公钥到包目录的父目录
[root@www ~]# cp /media/cdrom/os/RPM-GPG-KEY-CentOS-* /var/www/html/centos/6/os/x86_64
[root@www ~]# cp /media/cdrom/extras/RPM-GPG-KEY-CentOS-* /var/www/html/centos/6/extras/x86_64

#复制分组信息到仓库目录(只有DVD1,也就是base-http才有包组信息)
[root@www ~]# cp /media/cdrom/os/repodata/*comps.xml /var/www/html/centos/6/os/x86_64/repodata
[root@www ~]# cd /var/www/html/centos/6/os/x86_64/repodata
[root@www repodata]# ls
2727fcb43fbe4c1a3588992af8c19e4d97167aee2f6088959221fc285cab6f72-c6-x86_64-comps.xml
[root@www repodata]# mv 2727fcb43fbe4c1a3588992af8c19e4d97167aee2f6088959221fc285cab6f72-c6-x86_64-comps.xml c6-x86_64-comps.xml
[root@www repodata]# ls
c6-x86_64-comps.xml  #名字改短为了方便创建仓库的语句写短点

#目录结构如下
[root@www repodata]# cd /var/www/html/
[root@www html]# tree -L 5
.
└── centos
    └── 6
        ├── extras
        │   └── x86_64
        │       ├── Packages -> /media/cdrom/extras/Packages/
        │       ├── repodata
        │       ├── RPM-GPG-KEY-CentOS-6
        │       ├── RPM-GPG-KEY-CentOS-Debug-6
        │       ├── RPM-GPG-KEY-CentOS-Security-6
        │       └── RPM-GPG-KEY-CentOS-Testing-6
        └── os
            └── x86_64
                ├── Packages -> /media/cdrom/os/Packages/
                ├── repodata
                ├── RPM-GPG-KEY-CentOS-6
                ├── RPM-GPG-KEY-CentOS-Debug-6
                ├── RPM-GPG-KEY-CentOS-Security-6
                └── RPM-GPG-KEY-CentOS-Testing-6

3.创建仓库

#使用刚才的本地仓库安装创建仓库的createrepo命令
[root@www html]# yum install createrepo
.....(略去)......

#生成yum仓库base-http。元数据不放在Packages目录内(因为该目录为挂载iso内的目录,不能生成yum仓库源数据)
[root@www html]# cd /var/www/html/centos/6/os/x86_64
[root@www x86_64]# ls . repodata/
.:
Packages  RPM-GPG-KEY-CentOS-6        RPM-GPG-KEY-CentOS-Security-6
repodata  RPM-GPG-KEY-CentOS-Debug-6  RPM-GPG-KEY-CentOS-Testing-6
repodata/:
c6-x86_64-comps.xml
[root@www x86_64]# createrepo -u "http://www.tangsw.com/centos/6/os/x86_64/Packages" \
> -g /var/www/html/centos/6/os/x86_64/repodata/c6-x86_64-comps.xml \
> -o . Packages/
Spawning worker 0 with 3955 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
#创建yum仓库的相关选项
#选项-u告诉仓库的rpm包在哪个URL目录,这里使用了http地址
#选项-g告诉仓库有关包的分组信息
#选项-o告诉仓库,在哪个本地目录下创建repodata目录以及其下的文件
Packages/为本地要创建仓库的rpm目录

[root@www x86_64]# ls repodata/   #成功创建了yum仓库base-http,下面是仓库元数据文件
2727fcb43fbe4c1a3588992af8c19e4d97167aee2f6088959221fc285cab6f72-c6-x86_64-comps.xml
5df078da5f9cc13498e5e2a9e6093ed52bd0c1ac2d32f4e392c0173eb3d2681c-primary.xml.gz
5f5db77f755ccd961249b556ffe979bd2b2f4ce91e6260c28a236f34396d7a43-filelists.xml.gz
643bc28fb483d4131a6b0ecbd17c769caae6c015062838c7dea629e47633892c-primary.sqlite.bz2
6edabfeb2957fc20cacf8d38c61a7f9d14593bd87d7c66300485d1f66d56f36f-other.xml.gz
b38a04081eabb1b28bf2d615cfbce1f7244e07a3cdc92208c4bcbfa0723ce331-other.sqlite.bz2
cb96727ddc89e5e1786456c6f2c08a81418296f949470311ee9c2ebb1a6ccc7d-c6-x86_64-comps.xml.gz
e2d9ea7a6ce208f11898da8212427ff0eef709aa4a8a6ac779c6180b8bea1d0b-filelists.sqlite.bz2
repomd.xml


#生成yum仓库extra-http。
[root@www x86_64]# pwd
/var/www/html/centos/6/os/x86_64
[root@www x86_64]# cd ../../extras/x86_64/
[root@www x86_64]# ls . repodata/
.:
Packages  RPM-GPG-KEY-CentOS-6        RPM-GPG-KEY-CentOS-Security-6
repodata  RPM-GPG-KEY-CentOS-Debug-6  RPM-GPG-KEY-CentOS-Testing-6
repodata/:
[root@www x86_64]# createrepo -u "http://www.tangsw.com/centos/6/extras/x86_64/Packages" \
> -o . Packages/
Spawning worker 0 with 2426 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

[root@www x86_64]# ls repodata/  #成功创建了yum仓库extras-http,下面是仓库元数据文件
079695d74c53deee74e35928ee519cc36273934cd7b643ca2b5a2acc23a6f2aa-filelists.xml.gz
0f1f74b6731c95310593b90ab3145921f5b8de579a4bd46aed44d2b4b349575e-other.sqlite.bz2
22c88c0f4fef145d4efb14afe42703371102eebbddef15f89771352687efe74a-primary.xml.gz
598452fa46a28589e2215b43403ba1f0f177636bec652419b3a5b3bb308a86e8-filelists.sqlite.bz2
62b62111b2d9beda6486f5a40c53c860e676a84a3b7ca396b5939dd25d1441fc-other.xml.gz
6eff722739c77958a605f7e65c663a92a124a25c01b671661cda89d82ad25bd4-primary.sqlite.bz2
repomd.xml

4.安装httpd并启动www服务

#先安装httpd
[root@www ~]# yum install -y httpd
.....(略去)......


#启动httpd服务
[root@www ~]# service httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd:                                            [  OK  ]

#查看服务监听进程是否正常
[root@www ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1471/rpcbind        
tcp        0      0 192.168.8.11:80             0.0.0.0:*                   LISTEN      2805/httpd          
tcp        0      0 192.168.56.11:80            0.0.0.0:*                   LISTEN      2805/httpd          
tcp        0      0 127.0.0.1:80                0.0.0.0:*                   LISTEN      2805/httpd          
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1684/sshd           
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1557/cupsd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1764/master         
tcp        0      0 0.0.0.0:45305               0.0.0.0:*                   LISTEN      1504/rpc.statd      
tcp        0      0 :::44683                    :::*                        LISTEN      1504/rpc.statd      
tcp        0      0 :::111                      :::*                        LISTEN      1471/rpcbind        
tcp        0      0 :::22                       :::*                        LISTEN      1684/sshd           
tcp        0      0 ::1:631                     :::*                        LISTEN      1557/cupsd          
tcp        0      0 ::1:25                      :::*                        LISTEN      1764/master         
#当前服务进程正常
a.如果看到连接会话只启用IPv6的端口,而没有启用IPv4的端口,那应该是配置文件问题
    用rpm -qc httpd找到httpd的配置文件httpd.conf(本人的为/etc/httpd/conf/httpd.conf)
        修改Listen 80为Listen www.tangsw.com:80 
        注意这里使用了本地主机名,必须在将本地IP映射到该主机名中(本地无DNS服务),手动映射方法为:
        在/etc/sysconfig/network修改主机名
        在/etc/hosts增加主机名到本地IP的映射
b.如果监听进程正常启动,则看日志分析故障
    rpm -ql httpd | grep log
        如果发现是安全性问题
            简单方法是用setup命令,开启httpd的防火墙端口
            修改/etc/selinux/config,关闭selinux,然后重启linux
            
#设置开机启动
[root@www ~]# chkconfig httpd on

#确保用浏览器访问如下路径没问题
http://www.tangsw.com/centos

5.配置yum客户端

[root@www ~]# vim /etc/yum.repos.d/CentOS-Media.repo

[root@www ~]# cat /etc/yum.repos.d/CentOS-Media.repo
[c6-media]
name=CentOS-$releasever - Media - Local
baseurl=file:///media/cdrom/os
file:///media/cdrom/extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=0
[base-http]
name=CentOS-$releasever - Base - Http
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=1
[extras-http]
name=CentOS-$releasever - extras - Http
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=1
#注意为了测试HTTP的yum源,这里将本地yum源禁用
#$releasever变量值为6,$basearch变量值为x86_64,本机用的是64位CentOS

6.测试客户端配置是否正确

#清理缓存
[root@www ~]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base-http extras-http
Cleaning up Everything
Cleaning up list of fastest mirrors

#查看yum源信息
[root@www ~]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
base-http                                                                                        | 3.7 kB     00:00     
base-http/primary_db                                                                             | 4.6 MB     00:06     
extras-http                                                                                      | 3.4 kB     00:00     
extras-http/primary_db                                                                           |  27 kB     00:00     
repo id                                           repo name                                                       status
base-http                                         CentOS-6 - Base - Http                                          6,575
extras-http                                       CentOS-6 - extras - Http                                           35
repolist: 6,610
#可以看到只有两个http的yum源,分别有3,955和2,426个包,分别对应DVD1和DVD2

#查看包的分组信息是否正确
[root@www ~]# yum grouplist
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
base-http/group_gz                                                                               | 219 kB     00:00     
Installed Groups:
   Additional Development
   Base
   Debugging Tools
   Desktop
   Desktop Debugging and Performance Tools
.........(略去).......

7.测试在客户端安装软件包zsh和zsh-html

[root@www yum.repos.d]# yum -y install zsh
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:4.3.11-4.el6.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================================
 Package               Arch                     Version                               Repository                   Size
========================================================================================================================
Installing:
 zsh                   x86_64                   4.3.11-4.el6.centos                   base-http                   2.2 M
Transaction Summary
========================================================================================================================
Install       1 Package(s)
Total download size: 2.2 M
Installed size: 5.0 M
Downloading Packages:
zsh-4.3.11-4.el6.centos.x86_64.rpm                                                               | 2.2 MB     00:03     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : zsh-4.3.11-4.el6.centos.x86_64                                                                       1/1 
  Verifying  : zsh-4.3.11-4.el6.centos.x86_64                                                                       1/1 
Installed:
  zsh.x86_64 0:4.3.11-4.el6.centos                                                                                      
Complete!


[root@www yum.repos.d]# yum -y install zsh-html
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package zsh-html.x86_64 0:4.3.11-4.el6.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================================
 Package                  Arch                   Version                                Repository                 Size
========================================================================================================================
Installing:
 zsh-html                 x86_64                 4.3.11-4.el6.centos                    base-http                 478 k
Transaction Summary
========================================================================================================================
Install       1 Package(s)
Total download size: 478 k
Installed size: 3.0 M
Downloading Packages:
zsh-html-4.3.11-4.el6.centos.x86_64.rpm                                                          | 478 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : zsh-html-4.3.11-4.el6.centos.x86_64                                                                  1/1 
  Verifying  : zsh-html-4.3.11-4.el6.centos.x86_64                                                                  1/1 
Installed:
  zsh-html.x86_64 0:4.3.11-4.el6.centos                                                                                 
Complete!

大功告成!

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

(0)
上一篇 2015-09-21 13:23
下一篇 2015-09-22 09:35

相关推荐

  • 21期第一周网络练习作业

    计算机的组成部分及功能 由运算器、控制器、存储器、输入设备和输出设备组成 其中运算器负责数据的算术运算和逻辑运算,即数据的加工处理;   控制器负责对控制信息进行分析,控制并协调输入、输出操作或内存、外存访问;   存储器用来存放计算程序及参与运算的各种数据,实现类似人脑记忆功能的部件,分为内存和外存;  &…

    Linux干货 2016-07-12
  • Linux文本处理三剑客之grep

    一、grep命令 grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来 作用:文本搜索工具,根据用户指定的“模式”对目标文本逐行进行匹配检查;打印匹配到的行。 模式:由正则表达式字符及文本字符所编写的过滤条件 二、grep命令格式 grep [OPT…

    Linux干货 2016-08-15
  • 永远不要让自己停下

    曾几何时,我还是刚出象牙塔的小男孩。想想现在,经过4年的洗礼,我不再是小男孩了。可是,我却发现自己变得越来越懒,守着那丁点的知识。 我早已坐吃山空而不自知,早已落后于时代的趋势而不自知。时代需要一个勤奋而专注的我,需要一个不懈怠的我。 如果,我不继续前进,等待我的只有堕落。逆水行舟不进则退,不逼自己一把,永远不知道自己的潜力有多大。 我希望说,再见,懈怠而懒…

    Linux干货 2016-10-07
  • LINUX下用户管理命令简述

    LINUX下用户管理命令简述 添加用户并设置密码 useradd [用户名] 创建用户 [root@localhost ~]# useradd jack [root@localhost ~]# cat /etc/shadow | grep jack jack:!!:17257:0:99999:7::: passwd [用户名] 设置密码 [root@loca…

    Linux干货 2017-04-05
  • configure –help 参数详解

    configure –help 参数详解及apache2.2静态编译和动态编译参考

    Linux干货 2016-05-25
  • 文件管理命令及变量基础

    文件管理工具:cp,    mv,     rm       cp命令:copy 源文件;目标文件 单源复制: cp [OPTION]….[-T]  SOURCE  DEST 多源复制:cp [OPTION] ….SOURCE…DIR…

    Linux干货 2016-12-21