如何實現本地yum源的共享

上一篇關于Linux yum客戶端的配置的博客,介紹了如何通過修改本機yum配置文件來訪問網絡或者本地的yun sever, 本文就來介紹一下,如何把我們的本地RPM包像yum sever一樣通過http或ftp網絡方式共享出去。

一、準備好發行版光盤,包,元數據
    CentOS-6.8-x86_64-bin-DVD1.iso
二、準備網絡服務http(s);ftp
根據netstat -ntl命令執行結果可以看出,80(http),21(ftp)端口都沒有顯示, 服務還沒有配置

[root@centos6 ~]#netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:44496               0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 :::111                      :::*                        LISTEN      
tcp        0      0 :::55028                    :::*                        LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      

1)配置ftp服務
1.安裝vsftpd包

[root@centos6 ~]#yum -y -q install vsftpd         <-- 利用配置過的yum倉庫
[root@centos6 ~]#rpm -ql vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/rc.d/init.d/vsftpd                           <-- 服務名稱
....中間省略....
/usr/share/man/man8/vsftpd.8.gz
/var/ftp
/var/ftp/pub                                      <-- 共享文件存放路徑

2.啟動ftp服務
以下兩種方法均可

[root@centos6 ~]#/etc/rc.d/init.d/vsftpd start    <-- 路徑名
Starting vsftpd for vsftpd:                                [  OK  ]
[root@centos6 ~]#service vsftpd start             <-- service指令
Starting vsftpd for vsftpd:                                [  OK  ]

3.設置開機自啟動

[root@centos6 ~]#chkconfig vsftpd on

2)配置http服務
1.安裝httpd包

[root@centos6 ~]#yum -y install httpd             <-- 利用配置過的yum倉庫
[root@centos6 ~]#rpm -ql httpd
/etc/httpd
....中間省略....
/etc/rc.d/init.d/htcacheclean
/etc/rc.d/init.d/httpd                            <-- 服務名稱
....中間省略....
/var/www/html                                     <-- 共享文件存放路徑
....后面省略....

2.啟動http服務

[root@centos6 ~]#cd /etc/httpd/conf.d/
[root@centos6 conf.d]#mv welcome.conf welcome.conf.bak    <-- 重命名welcome.conf文件,否則通過http訪問不到/var/www/html共享文件夾
[root@centos6 ~]#/etc/rc.d/init.d/httpd start             <-- 路徑名
Starting httpd:                                            [  OK  ]
[root@centos6 ~]#service httpd start                      <-- service指令
Starting httpd:                                            [  OK  ]

3.設置開機自啟動

[root@centos6 ~]#chkconfig httpd on

三、關閉防火墻服務

[root@centos6 ~]#service iptables stop             <-- 關閉服務
[root@centos6 ~]#chkconfig iptables off            <-- 禁止開機啟動

四、拷貝目標文件到共享目錄
1.ftp服務的共享目錄是/var/ftp/pub

[root@centos6 /]#cd /var/ftp/pub
[root@centos6 6]#mkdir 6                           <-- 創建以版本號命名的文件夾
[root@centos6 6]#cp -r /misc/cd/Packages           <-- 從光盤拷貝包文件
[root@centos6 6]#cp -r /misc/cd/repodata           <-- 從光盤拷貝元數據
[root@centos6 6]#ls
Packages  repodata

通過瀏覽器訪問ftp://192.168.196.132,已經可以訪問共享文件了            <– 本機IP192.168.196.132

如何實現本地yum源的共享

2.同樣方法可以把rpm包拷貝到http服務的共享目錄下/var/www/html
還有另外一種方法就是把目錄/var/ftp/pub掛載到目錄/var/www/html,這樣通過http訪問/var/www/html相當于訪問/var/ftp/pub,我們就省去了重復復制的操作

[root@centos6 ~]#mount /var/ftp/pub /var/www/html -B

通過瀏覽器訪問http://192.168.196.132,已經可以訪問共享文件了

如何實現本地yum源的共享

五、yum客戶端的配置
1.修改yum配置文件

[root@centos6 ~]#vi /etc/yum.repos.d/centos.repo 
[ftpbase]
name=ftp yum base
baseurl=ftp://192.168.196.132/pub/$releasever     
gpgcheck=0
enabled=1

[httpbase]
name=http yum base
baseurl=http://192.168.196.132/$releasever
gpgcheck=0
enabled=1

2.清理緩存

[root@centos6 ~]#yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: ftpbase httpbase
Cleaning up Everything
Cleaning up list of fastest mirrors

3.創建緩存

[root@centos6 ~]#yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
ftpbase                                                                                        | 4.0 kB     00:00     
ftpbase/group_gz                                                                               | 226 kB     00:00     
ftpbase/filelists_db                                                                           | 6.3 MB     00:00     
ftpbase/primary_db                                                                             | 4.7 MB     00:00     
ftpbase/other_db                                                                               | 2.8 MB     00:00     
httpbase                                                                                       | 4.0 kB     00:00     
httpbase/group_gz                                                                              | 226 kB     00:00     
httpbase/filelists_db                                                                          | 6.3 MB     00:00     
httpbase/primary_db                                                                            | 4.7 MB     00:00     
httpbase/other_db                                                                              | 2.8 MB     00:00     
Metadata Cache Created

4.列出yum倉庫

[root@centos6 ~]#yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id                                                     repo name                                status
ftpbase                                                     ftp yum base                             6,696
httpbase                                                    http yum base 6,696
repolist: 13,392

結果可以看出,網絡yum源已經創建成功,可以通過http或者ftp服務訪問了

六、第三方的軟件倉庫的配置
上面是以發行版光盤為rpm包的來源,提供了元數據repodata,假如我們想要分享第三方的軟件,就必須使用createrepo命令來生成所需的repodata

[root@centos6 6]#cd /var/ftp/pub/6     <--cd到Package所在目錄
[root@centos6 6]#mv repodata /root/    <--移走已有repodata 
[root@centos6 6]#createrepo ./         <--創建元數據
Spawning worker 0 with 3206 pkgs       <--rpm包數小于6696是由于我們只拷貝一張光盤上的rpm包
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@centos6 6]#ls
Packages  repodata

來測試一下yum源

[root@centos6 6]#yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: ftpbase httpbase
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@centos6 6]#yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
ftpbase                                                                                     | 2.9 kB     00:00     
ftpbase/filelists_db                                                                        | 3.3 MB     00:00     
ftpbase/primary_db                                                                          | 2.5 MB     00:00     
ftpbase/other_db                                                                            | 1.4 MB     00:00     
httpbase                                                                                    | 2.9 kB     00:00     
httpbase/filelists_db                                                                       | 3.3 MB     00:00     
httpbase/primary_db                                                                         | 2.5 MB     00:00     
httpbase/other_db                                                                           | 1.4 MB     00:00     
Metadata Cache Created
[root@centos6 6]#yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id                                                     repo name                           status
ftpbase                                                     ftp yum base                        3,206
httpbase                                                    http yum base 3,206
repolist: 6,412

yum源配置成,而且手動生成的repodata能正確反映rpm包的實際數目了!

原創文章,作者:ffu,如若轉載,請注明出處:http://www.www58058.com/78133

(3)
ffuffu
上一篇 2017-06-17 15:30
下一篇 2017-06-17 16:54

相關推薦

  • Linux 系統啟動流程及bash 腳本編程練習

    馬哥教育網絡班23期 第10周課堂練習 Linux 系統啟動流程及bash 腳本編程練習1、請詳細描述CentOS系統的啟動流程(詳細到每個過程系統做了哪些事情) 2、為運行于虛擬機上的CentOS 6添加一塊新硬件,提供兩個主分區; (1)為硬盤新建兩個主分區;并為其安裝grub; (2)為硬盤的第一個主分區提供內核和ramdisk文件;為第二個分區提供r…

    Linux干貨 2017-01-23
  • 通過FTP服務怒刷基礎功法熟練度(匿名篇)

        Linux門派多種多樣,那么本次就講講本人刷基本命令熟練度的方法。FTP原理什么的都不說了,網上有很多。直接上酸菜~學徒水平,大師勿笑。     本篇搭載的是FTP匿名用戶訪問,同時可以在服務器上進行創建刪除等操作。危險系數有點點大,僅推薦用來刷命令熟練度使用。我用的Li…

    2017-07-25
  • 馬哥教育網絡第21期-第五周課程練習

    1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行; [root@6 ~]# grep '^[[:space:]]\+' /boot/grub/grub.conf 2、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白…

    Linux干貨 2016-08-15
  • puppet進階管理之終極應用

         上一篇博客寫了puppet操作file、cron、user、group、exec基礎資源的使用,連接地址為 http://www.www58058.com/13990  這次實驗puppet的操作Package、Server和puppet的特殊資源屬性Metaparameters。 回顧下…

    Linux干貨 2016-04-12
  • 8.1-用戶和組(作業篇)

     1、將/etc/issue文件中的內容轉換為大寫后保存至/tmp/issue.out文件中。 [root@localhost ~]# tr a-z A-Z </etc/issue > /tmp/issue.out [root@localhost ~]#&n…

    Linux干貨 2016-08-04
  • 如何成為一名軟件架構師

    Daniel Mohl是一名專業的軟件工程師/架構師,他的興趣包括理解各種復雜的編程語言、企業應用架構以及如何搭建業務與技術,他通曉F#、C#、CoffeeScript、JavaScript、Erlang、ASP.NET、MVC、WPF、WCF、Sliverlight、SQL Server等技術。有著多年的軟件開發經驗。 他經常會被一些有潛力和有前途的程序員…

    Linux干貨 2016-03-22
欧美性久久久久