?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 21:22
下一篇 2016-08-24 21:22

相關推薦

  • 8.5文本處理工具

    取本機ip地址 利用head命令取行首兩行,tail命令取行尾一行, ifconfig |head -2 |tail -1   利用tr -s命令替換空格為“:”,并合并重復的“:”。利用cut -d:-f3命令,保留以“:”為分割符的第三部分   ifconfig |head -2 |tail -1 |tr -s "…

    Linux干貨 2016-08-08
  • 正則表達式練習題及作業(8.5)

    當天練習題: 基本正則表達式練習題 1.顯示/proc/meminfo文件中以大小s開頭的行;(要求:使用兩種方式)   可有四種方式 [root@CentOS7 ~]# cat /proc/meminfo | grep -E "^(s|S)" SwapCac…

    Linux干貨 2016-08-15
  • 樹的遍歷和排序

    樹的遍歷和排序

    Linux干貨 2017-10-23
  • Btrfs文件系統

    一:概述     1.1簡介         Btrfs被稱為是下一代Linux文件系統。通常念成 Butter FS,Better FS 或B-tree FS。它采用了很多先進的文件系統設計,不僅解決了 ext2/3的擴展性問題,支持寫時…

    Linux干貨 2016-04-19
  • N26—第三周

    1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。 [root@localhost ~]# who | cut -d ' ' -f 1 |sort -u l_cong root (unknown)   2、取出最后登錄到當前系統的用戶的相關信息。 [l_cong@localhost ~]$…

    Linux干貨 2017-02-15
  • 如何在微軟云上搭建mysql主從

    大家好: 今天我分享下在生產環境的微軟云服務器上如何搭建mysql主從: 環境如下圖: 我把cnux06-testing設為Mysql主服務器,暫時沒需求的cnux04-web1db2設為Mysql從服務器 1–首先要在master上開啟binlog日志功能并使主從庫中的 server-id保持不同 操作步驟如下: A: 先查看mysql的主目錄…

    Linux干貨 2017-02-14
欧美性久久久久