?yum源的生成與配置{ local;cdrom;http;ftp;}

?yum源的生成與配置{ local;cdrom;http;ftp;}


本文是繼上一篇文章“CentOS程序安裝的3種方式{ 源碼包安裝 | rpm包安裝 | yum安裝;}”的補充,上篇文章http://www.www58058.com/38812主要介紹了基于cdrom的yum源制作和配置以及歸納了詳細的yum命令。本文繼續介紹基于本地file、遠程http、遠程ftp的私人yum倉庫的制作與配置,實現了在不同環境下的yum使用與配置。每種方式適用于不同場合,需根據實際情況選擇。


本地yum源

【一】安裝createrepo

[root@cent7]~>yum install createrepo

【二】進入repo目錄,執行createrepo命令創建repodata目錄

[root@cent7]/testdir/repodb>createrepo .
[root@cent7]/testdir/repodb>ls repodata/
126a4254b443d131331b4b0690e9c0b6d21a2086439cafc91c06cef05a4d4d80-filelists.sqlite.bz2
13fdc6b363cf52e0a85e9c14a3c7542ff8aa1414059ed3e60e921abe39b608ca-filelists.xml.gz
565784001204f6fb5bc9cc276322d70295eddb1e013d175e232f4efeb6e43d91-primary.sqlite.bz2
5e9a10c873af5ffb1fdd8e91272852c5c9fe2d2bb46e52ca6749b25a0833f3c0-primary.xml.gz
bf7893674c749b8e5bb4688498d02e729c2ab4839cd6e3baeeeaa0c9d8aa24c7-other.xml.gz
de5be08c023c4647355eb21db734c14e07f61ddce7b3802e6a42867e4a46d45f-other.sqlite.bz2
repomd.xml

【三】進入/etc/yum.repo.d/下創建自己的repo文件

[root@cent7]/etc/yum.repos.d>vim myrepo.repo
[local]
name=/testdir/repodb
baseurl=file:///testdir/repodb
gpgcheck=0
enabled=1

【四】查看yum倉庫信息

[root@cent7]/etc/yum.repos.d>yum repolist
Loaded plugins: fastestmirror, langpacks
local                                                  | 2.9 kB     00:00    
local/primary_db                                         | 1.8 kB   00:00    
Determining fastest mirrors
repo id                         repo name                               status
local                           /testdir/repodb                         1
repolist: 1

【五】使用yum安裝tree軟件

[root@cent7]/etc/yum.repos.d>yum install tree
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================
Package        Arch             Version                Repository       Size
==============================================================================
Installing:
tree           x86_64           1.6.0-10.el7           local            46 k

Transaction Summary
==============================================================================

Installed:
 tree.x86_64 0:1.6.0-10.el7                                                  

Complete!

至此,本地的yum源已經配置好了,我們可以在/testdir/repodb/目錄下添加第三方的rpm包,每次添加完成后要執行一次createrepo命令,由此生成rpm包的元數據。創建本地的yum源極大的方便了軟件的安裝,充分發揮了yum工具的作用,無論是軟件的安裝、卸載、升級,yum都在/var/log/yum.log中記錄了相關信息。


CentOS 6.8基于httpd-2.2.29的yum源

雖然系統自帶的倉庫已經很常用,只要連接到互聯網我們就能很容易有獲取到互聯網的yum倉庫。但是如果是在企業內網,企業內部不允許訪問互聯網,又或者如果企業服務器眾多,如果都要從互聯網去獲取yum倉庫,那將很占用帶寬?;谶@種情況,我們就需要自己在企業內部創建yum倉庫。下圖是國內的開源鏡像網站,通過配置repo文件即可作為yum源

mirrors.jpg

【一】下載并解壓httpd-2.2.29.tar.bz2

[root@cent6~]/home/testdir>tar xf httpd-2.2.29.tar.bz2 
[root@cent6~]/home/testdir>cd httpd-2.2.29

【二】安裝Development tools

[root@cent6~]yum groupinstall "Development tools"

【三】配置./configure生成makefile文件,主要是指定軟件的安裝路徑與配置文件的路徑,可通過./configure –help查看相關說明與幫助

[root@cent6]/home/testdir/httpd-2.2.29>./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd^C
[root@cent6]/home/testdir/httpd-2.2.29>make && make install

【四】安裝完成,導入環境變量和lib庫目錄

[root@cent6]~>vim /etc/profile.d/httpd.sh  
PATH=$PATH:/usr/local/httpd/bin
[root@cent6]~>. /etc/profile.d/http.sh   #或重新登錄
[root@cent6]~>vim /etc/ld.so.conf.d/httpd.conf
/usr/local/httpd/lib
[root@cent6]~>ldconfig

【五】導入頭文件到/usr/include,用軟鏈接或者拷貝

[root@cent6]~>ln -sv /usr/local/include/* /usr/include/
`/usr/include/*' -> `/usr/local/include/*'

【六】導入manual手冊的路徑到man.config

[root@cent6]~>vim /etc/man.config
MANPATH /usr/local/httpd/man
[root@cent6]~>man apachectl

【七】啟動apache,如果成功可以看到80端口已經啟用

[root@cent6]~>apachectl start
[root@cent6]~>netstat -tan
Active Internet connections (servers and established)
tcp        0      0 :::80                       :::*                        LISTEN      

【八】暫時停止iptables,可以通過/sbin/iptables -F清除所有規則來暫時停止防火墻: (警告:這只適合在沒有配置防火墻的環境中,如果已經配置過默認規則為deny的環境,此步驟將使系統的所有網絡訪問中斷)

[root@cent6]~>/sbin/iptables -P INPUT ACCEPT
[root@cent6]~>iptables -F

【九】在另一臺主機中測試http是否啟動,如果正確安裝則可以看到如下結果

[root@cent7]/etc>curl 10.1.253.64
<html><body><h1>It works!</h1></body></html>

【十】確保apache服務啟動成功的前提下,開始配置基于http的yum源,首先是在httpd的默認文檔路徑下創建repo倉庫,并放置rpm包,再生成repodata文件

[root@cent6]~>mkdir -p /usr/local/httpd/htdocs/centos/7/extras/x86_64/Packages/

cp /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm ./Packages/

[root@cent6]~>createrepo Packages/ -o /usr/local/httpd/htdocs/centos/7/extras/x86_64/

可以看到生成了一個rpm包的元數據:

11.jpg

可以看到在瀏覽器中已經可以正常訪問http的yum文件列表

12.jpg

【十一】在CentOS 7中配置該repo倉庫

  [root@cent7]~>vim /etc/yum.repos.d/myrepo.repo
 1 [base]
 2 name=myrepo
 3 baseurl=http://10.1.253.64/centos/7/extras/x86_64/
 4        
 5 gpgcheck=1
 6 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 7 enabled=1

在CentOS 7上可以看到:

    [root@cent7]~>yum list
   Loaded plugins: fastestmirror
   Loading mirror speeds from cached hostfile
   Installed Packages
   tree.x86_64                      1.6.0-10.el7                        installed
   [root@cent7]/usr/local/httpd/htdocs/centos/7/extras/x86_64>yum install tree
Loaded plugins: fastestmirror, refresh-packagekit, security
==============================================================================

Package        Arch             Version                 Repository      Size
==============================================================================

Installing:
tree           x86_64           1.5.3-3.el6             base            36 k

Transaction Summary
==============================================================================

Installed:
tree.x86_64 0:1.5.3-3.el6

由此,基于http的yum源已經完成了,但是軟件包不是一層不變的,如果有新的第三包需要使用yum安裝怎么辦呢?

此時需要createrepo –update即可,如下:


[root@cent6]~>createrepo /usr/local/httpd/htdocs/centos/7/extras/x86_64/ --update
Spawning worker 0 with 1 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

CentOS 6.8基于ftp的yum源

【一】安裝vsftp程序,光盤鏡像中有相應的軟件包

[root@cent7]/media/cdrom/Packages>rpm -ih vsftpd*
################################# [100%]
Updating / installing...
###
############################## [100%]

[root@cent6]/misc/cd/Packages>service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]


注意: FTP不需要任何配置,默認就是匿名可以訪問的。如果修改了/var/ftp的權限會導致本來是匿名訪問的忽然要你輸入用戶名密碼,改回 chmod 755 /var/ftp 即可


【二】把光盤鏡像copy到ftp的默認路徑/var/ftp/pub,并使用createrepo生成rpm包的元數據

[root@cent6]~>mkdir /var/ftp/pub/Packages/
[root@cent6]~>cp /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm /var/ftp/pub/Packages/
[root@cent6]~>createrepo /var/ftp/pub/centos/Packages -o /var/ftp/pub/centos
Spawning worker 0 with 1 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

【三】在CentOS 7上驗證ftp服務器是否可用:

[root@cent7]/home>lftp 10.1.253.64
lftp 10.1.253.64:/> dir pub/centos/
drwxr-xr-x    2 0        0            4096 Aug 09 13:46 Packages
drwxr-xr-x    2 0        0            4096 Aug 09 13:56 repodata

【四】配置repo文件,指向該ftp源

 [root@cent7]~>vim /etc/yum.repos.d/myrepo.repo
[ftp]
1 name=ftp
2 baseurl=ftp://10.1.253.64/pub/centos/
3 gpgcheck=0
4 enabled=1

[root@cent7]~>yum clean all

[root@cent7]~>yum repolist
Loaded plugins: fastestmirror
repo id                               repo name                         status
ftp                                   ftp                               1
repolist: 1

【五】使用yum安裝軟件

[root@cent7]~>yum install tree
Loaded plugins: fastestmirror

==============================================================================
Package        Arch             Version                  Repository     Size
==============================================================================
Installing:
tree           x86_64           1.5.3-3.el6              ftp            36 k

Transaction Summary
==============================================================================


Installed:
 tree.x86_64 0:1.5.3-3.el6                                                  

Complete!

由此,基于ftp的yum源已經配置完成了,,但是軟件包不是一層不變的,如果有新的第三包需要使用yum安裝怎么辦呢?此時需要createrepo –update即可,如下:


[root@cent6]~>createrepo /var/ftp/pub/centos/Packages/ --update
Spawning worker 0 with 1 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

最后 but not least

1471841907874255.jpg

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

(0)
hellochelloc
上一篇 2016-08-24
下一篇 2016-08-24

相關推薦

  • SELinux介紹

    SELinux介紹 SELinux: Secure Enhanced Linux, 是美國國家安全局(NSA=The National Security Agency)和SCC(Secure Computing Corporation)開發的 Linux的一個強制訪問控制的安全模塊。 2000年以GNU GPL發布, Linux內核2.6版本后集成在內核中D…

    Linux干貨 2016-10-08
  • 第四周

    第四周 1.復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其他用戶均沒有任何訪問權限。 [root@node1 ~]# cp -r /etc/skel/ /home/tuser1 [root@node1 ~]# chmod -R go= /home/tuser1 [root@node1 ~]# ls -…

    Linux干貨 2017-07-26
  • 程序員的相關笑話(二)

    從前,有一個牧羊人,他有很多的羊。一天他趕著他的那群羊到了一條公路邊上。突然,有一輛保時潔急駛過來,上面坐著一個年輕人人,穿著Armani的衣服,和Cerutti的皮鞋,Ray-Ban的太陽眼鏡,TAG-Heuer的手表,以前Versace的領帶。 他走到牧羊人面前問牧羊人:“如果我能說出你有多少只羊,你能給我一只嗎?” 牧羊人看了看他那一大群數都數不過來的…

    Linux干貨 2016-07-10
  • Nginx 代理和緩存

    一 實驗環境 Nginx 版本:nginx-1.8.1 Nginx代理服務器WAN:192.168.1.5 LAN:172.16.2.1 Web1:172.16.2.2 Web2:172.16.2.3 1.  配置好IP、DNS 、網關,確保使用遠程連接工具能夠連接服務器 2.      …

    Linux干貨 2016-12-05
  • LVS類型及其調度算法

    LVS類型:     NAT:–>(DNAT) (多目標的DNAT)     DR:     TUN:     FULLNAT: LVS NAT的特性  &nbs…

    Linux干貨 2016-10-29
  • 設計模式(八)裝飾器模式Decorator(結構型)

    1. 概述        若你從事過面向對象開發,實現給一個類或對象增加行為,使用繼承機制,這是所有面向對象語言的一個基本特性。如果已經存在的一個類缺少某些方法,或者須要給方法添加更多的功能(魅力),你也許會僅僅繼承這個類來產生一個新類—這建立在額外的代碼上。       通過繼…

    Linux干貨 2015-07-03
欧美性久久久久