在虛擬機上使用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.www58058.com/8214

(0)
王重陽王重陽
上一篇 2015-09-21
下一篇 2015-09-22

相關推薦

  • 8-4 作業

    1.用正則表達式表示IP地址 2.用正則表達式表示手機號11 13 17 15  18 3.用正則表達式表示身份證號18   4.用正則表達式表示郵箱  

    Linux干貨 2016-08-08
  • class-6 用戶組管理(二) 權限管理

                      一、用戶組管理  1、設置修改用戶密碼密碼      設置密碼     passwd [OPT…

    Linux干貨 2016-08-05
  • CentoS 6.8 安裝(小白請進)

    先說點題外話,我現在還是一個小白,剛接觸‘高大上’的linux不久,隨著深入的學習了解,興趣越來越濃,這個東西很有意思的,不像學windows那樣枯燥無味,真的,不信?歡迎加入馬哥大家庭。 廢話不多說,注意了:前方高能?。。?首先呢,先下載一個VMware Workstation這個虛擬機軟件,它的作用很強大,可以使你在一臺機器上同時運行一個甚至多個linu…

    2017-02-17
  • zabbix如何監控nginx的status

    nginx   status配置 server {                 listen      80;                 server…

    Linux干貨 2016-02-19
  • bash之腳本入門及課后作業

    概述: shell是一個工具程序,在用戶登錄后后系統啟動,它解釋并運行由命令或腳本文件輸入的命令,從而實現用戶與內核之間的交互。bash是Linux操作系統上默認的shell,在交互和編程兩方面,bash提供了許多Bourne shell沒有的功能,并且還結合了C shell和Kron shell最有用的功能。 bash的語法和結構   …

    Linux干貨 2016-08-15
  • 瀏覽和管理log文件

    瀏覽和管理log文件 log文件是一種包含系統消息的文件,包括內核、服務和應用運行在其上。不同的日志文件對應不同的日志信息。例如,默認的系統log文件,一個log文件對應安全消息,一個log文件對應計劃任務。當要對一個系統問題排錯例如加載內核驅動或者當尋找對系統的非授權登錄攻擊,日志文件是很有幫助的。一些log文件被一個稱之為rsyslogd的守護進程控制?!?/p>

    Linux干貨 2017-05-15
欧美性久久久久