Linux雲端計算-05_Linux軟體包管理

shuchaoyang發表於2021-07-11

本章介紹Linux系統軟體的安裝、解除安裝、配置、維護以及如何構建企業本地YUM光碟源及HTTP本地源。

1 RPM軟體包管理

Linux軟體包管理大致可分為二進位制包、原始碼包,使用的工具也各不相同。Linux常見軟體包分為兩種,分別是原始碼包(Source Code)、二進位制包(Binary Code),原始碼包是沒有經過編譯的包,需要經過GCC、C++編譯器環境編譯才能執行,二進位制包無需編譯,可以直接安裝使用。

通常而言,可以透過字尾簡單區別原始碼包和二進位制包,例如.tar.gz、.zip、.rar結尾的包通常稱之為原始碼包,以.rpm結尾的軟體包稱之為二進位制包。真正區分是否為原始碼還是二進位制還得基於程式碼裡面的檔案來判斷,例如包含.h、.c、.cpp、.cc等結尾的原始碼檔案,稱之為原始碼包,而程式碼裡面存在bin目錄可以執行檔案,稱之為二進位制包。

CentOS作業系統中有一款預設軟體管理的工具,紅帽包管理工具(Red Hat Package Manager,RPM)。

使用RPM工具可以對軟體包實現快速安裝、管理及維護。RPM管理工具適用的作業系統包括:CentOS,RedHat,Fedora,SUSE等,RPM工具常用於管理.rpm字尾結尾的軟體包。

RPM軟體包命令規則詳解如下:

RPM包命名格式為:

name-version.rpm
name-version-noarch.rpm
name-version-arch.src.rpm
如下軟體包格式:
epel-release-6-8.noarch.rpm
perl-Pod-Plainer-1.03-1.el6.noarch.rpm

以yasm-1.2.0-4.el7.x86_64.rpm為列解析如下:
RPM包格式解析如下:
 name     軟體名稱,例如yasm、perl-pod-Plainer;
 version   版本號,1.2.0通用格式:“主版本號.次版本號.修正號”;
4表示是釋出版本號,該RPM包是第幾次編譯生成的;
 arch    適用的硬體平臺,RPM支援的平臺有:i386、i586、i686、x86_64、sparc、alpha等。
 .rpm   字尾包表示編譯好的二進位制包,可用rpm命令直接安裝;
 .src.rpm  原始碼包,原始碼編譯生成.rpm格式的RPM包方可使用;
 el*     軟體包發行版本,el6表示該軟體包適用於RHEL 6.x/CentOS 6.x;
 devel:      開發包;
 noarch:     軟體包可以在任何平臺上安裝。

RPM工具命令詳解如下:

RPM 選項 PACKAGE_NAME

-a, --all        查詢所有已安裝軟體包;
-q,--query            表示詢問使用者,輸出資訊;
-l, --list          列印軟體包的列表;
-f, --file       FILE查詢包含FILE的軟體包;
-i, --info       顯示軟體包資訊,包括名稱,版本,描述;
-v, --verbose       列印輸出詳細資訊;
-U, --upgrade       升級RPM軟體包;
-h,--hash           軟體安裝,可以列印安裝進度條;
--last           列出軟體包時,以安裝時間排序,最新的在上面;
-e, --erase         解除安裝rpm軟體包
--force             表示強制,強制安裝或者解除安裝;
--nodeps            RPM包不依賴
-l, --list       列出軟體包中的檔案;
--provides          列出軟體包提供的特性;
-R, --requires      列出軟體包依賴的其它軟體包;
--scripts           列出軟體包自定義的小程式。

RPM企業案例演示:

# 檢查sysstat包是否安裝;

[root@superman-vm01 ~]# rpm -q sysstat
package sysstat is not installed
[root@superman-vm01 ~]#

# 安裝sysstat軟體包;
[root@superman-vm01 ~]# rpm -ivh sysstat-10.1.5-17.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
  1:sysstat-10.1.5-17.el7            ################################# [100%]
[root@superman-vm01 ~]#        

# 檢視軟體安裝的路徑;
[root@superman-vm01 ~]# rpm -ql sysstat
/etc/cron.d/sysstat
/etc/sysconfig/sysstat
/etc/sysconfig/sysstat.ioconf
/usr/bin/cifsiostat
/usr/bin/iostat
/usr/bin/mpstat
/usr/bin/nfsiostat-sysstat
/usr/bin/pidstat
/usr/bin/sadf
/usr/bin/sar
/usr/bin/tapestat
..........                  

# 檢視軟體安裝的版本資訊;
[root@superman-vm01 ~]# rpm -qi sysstat
Name        : sysstat
Version     : 10.1.5
Release     : 17.el7
Architecture: x86_64
Install Date: Sat 10 Jul 2021 06:46:49 AM CST
Group       : Applications/System
Size        : 1172947
License     : GPLv2+
Signature   : RSA/SHA256, Mon 12 Nov 2018 10:47:27 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : sysstat-10.1.5-17.el7.src.rpm
Build Date  : Wed 31 Oct 2018 04:04:26 AM CST
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <
Vendor      : CentOS
URL         :
Summary     : Collection of performance monitoring tools for Linux
Description :
The sysstat package contains sar, sadf, mpstat, iostat, pidstat, nfsiostat-sysstat,
tapestat, cifsiostat and sa tools for Linux.
..........

# 解除安裝sysstat軟體;
[root@superman-vm01 ~]# rpm -qa|grep sysstat
sysstat-10.1.5-17.el7.x86_64
[root@superman-vm01 ~]#
[root@superman-vm01 ~]# rpm -e sysstat-10.1.5-17.el7.x86_64
[root@superman-vm01 ~]#

# 升級sysstat軟體;
[root@superman-vm01 ~]# rpm -Uvh sysstat-10.1.5-17.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
  1:sysstat-10.1.5-17.el7            ################################# [100%]
[root@superman-vm01 ~]#

# 檢查sysstat相關的軟體包是否安裝;
[root@superman-vm01 ~]# rpm -qa|grep sysstat
sysstat-10.1.5-17.el7.x86_64
[root@superman-vm01 ~]#

# 強制解除安裝sysstat;
[root@superman-vm01 ~]# rpm -e --nodeps sysstat
[root@superman-vm01 ~]#

# 不依賴其它軟體包;
[root@superman-vm01 ~]# rpm -ivh --nodeps sysstat-10.1.5-17.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
  1:sysstat-10.1.5-17.el7            ################################# [100%]
[root@superman-vm01 ~]#

2  Tar軟體包管理

Linux作業系統除了使用RPM管理工具對軟體包管理之外,還可以透過tar、zip、jar等工具進行原始碼包的管理。

2.1 Tar命令引數詳解

-A, --catenate, --concatenate  將存檔與已有的存檔合併

-c, --create         建立新的存檔
-d, --diff, --compare   比較存檔與當前檔案的不同之處
--delete                  從存檔中刪除
-r, --append              附加到存檔結尾
-t, --list                列出存檔中檔案的目錄
-u, --update              僅將較新的檔案附加到存檔中
-x, --extract, --get      解壓檔案
-j, --bzip2, --bunzip2   有bz2屬性的軟體包;
-z, --gzip, --ungzip   有gz屬性的軟體包;
-b, --block-size N        指定塊大小為Nx512位元組(預設時 N=20);
-B, --read-full-blocks    讀取時重組塊;
-C, --directory DIR       指定新的目錄;
--checkpoint              讀取存檔時顯示目錄名;
-f, --file [HOSTNAME:]F   指定存檔或裝置,後接檔名稱;
--force-local             強制使用本地存檔,即使存在克隆;
-G, --incremental         建立老GNU格式的備份;
-g, --listed-incremental  建立新GNU格式的備份;
-h, --dereference         不轉儲動態連結,轉儲動態連結指向的檔案;
-i, --ignore-zeros        忽略存檔中的0位元組塊(通常意味著檔案結束);
--ignore-failed-read      在不可讀檔案中作0標記後再退出;
-k, --keep-old-files      儲存現有檔案;從存檔中展開時不進行覆蓋;
-K, --starting-file F     從存檔檔案F開始;
-l, --one-file-system     在本地檔案系統中建立存檔;
-L, --tape-length N       在寫入N*1024個位元組後暫停,等待更換磁碟;
-m, --modification-time   當從一個檔案中恢復檔案時,不使用新的時間標籤;
-M, --multi-volume        建立多卷存檔,以便在幾個磁碟中存放;
-O, --to-stdout           將檔案展開到標準輸出;
-P, --absolute-paths      不要從檔名中去除'/';
-v, --verbose     詳細顯示處理的檔案;
--version      顯示tar程式的版本號;
--exclude             FILE不把指定檔案包含在內;
-X, --exclude-from FILE      從指定檔案中讀入不想包含的檔案的列表。
2.2.1 TAR命令實戰
# 檢視keepalived-2.2.2.tar.gz包中內容;

[root@superman-vm01 ~]# tar -tf keepalived-2.2.2.tar.gz
keepalived-2.2.2/
keepalived-2.2.2/tools/
keepalived-2.2.2/tools/timed_reload
keepalived-2.2.2/Makefile.in
keepalived-2.2.2/build-aux/
keepalived-2.2.2/build-aux/install-sh
keepalived-2.2.2/build-aux/missing
keepalived-2.2.2/build-aux/compile
keepalived-2.2.2/build-aux/depcomp
keepalived-2.2.2/build-aux/ar-lib
keepalived-2.2.2/bin_install/
keepalived-2.2.2/bin_install/Makefile.in
keepalived-2.2.2/bin_install/Makefile.am
keepalived-2.2.2/keepalived.spec.in
..........

# 解壓keepalived-2.2.2.tar.gz程式包;
[root@superman-vm01 ~]# tar -xvf keepalived-2.2.2.tar.gz
keepalived-2.2.2/
keepalived-2.2.2/tools/
keepalived-2.2.2/tools/timed_reload
keepalived-2.2.2/Makefile.in
keepalived-2.2.2/build-aux/
keepalived-2.2.2/build-aux/install-sh
keepalived-2.2.2/build-aux/missing
keepalived-2.2.2/build-aux/compile
keepalived-2.2.2/build-aux/depcomp
keepalived-2.2.2/build-aux/ar-lib
keepalived-2.2.2/bin_install/
keepalived-2.2.2/bin_install/Makefile.in
keepalived-2.2.2/bin_install/Makefile.am
keepalived-2.2.2/keepalived.spec.in
keepalived-2.2.2/snap/
keepalived-2.2.2/snap/snapcraft.yaml
keepalived-2.2.2/snap/hooks/
keepalived-2.2.2/snap/hooks/post-refresh
keepalived-2.2.2/snap/hooks/install
keepalived-2.2.2/INSTALL
keepalived-2.2.2/doc/
keepalived-2.2.2/doc/Makefile.in
keepalived-2.2.2/doc/man/
keepalived-2.2.2/doc/man/man8/
........

# 打包keepalived檔案或者目錄,打包後名稱keepalived-2.2.2.tar;
[root@superman-vm01 ~]# tar -cvf keepalived-2.2.2.tar keepalived-2.2.2
keepalived-2.2.2/
keepalived-2.2.2/tools/
keepalived-2.2.2/tools/timed_reload
keepalived-2.2.2/Makefile.in
keepalived-2.2.2/build-aux/
keepalived-2.2.2/build-aux/install-sh
keepalived-2.2.2/build-aux/missing
keepalived-2.2.2/build-aux/compile
keepalived-2.2.2/build-aux/depcomp
keepalived-2.2.2/build-aux/ar-lib
keepalived-2.2.2/bin_install/
keepalived-2.2.2/bin_install/Makefile.in
keepalived-2.2.2/bin_install/Makefile.am
keepalived-2.2.2/keepalived.spec.in
keepalived-2.2.2/snap/
keepalived-2.2.2/snap/snapcraft.yaml
keepalived-2.2.2/snap/hooks/
keepalived-2.2.2/snap/hooks/post-refresh
keepalived-2.2.2/snap/hooks/install
keepalived-2.2.2/INSTALL
keepalived-2.2.2/doc/
keepalived-2.2.2/doc/Makefile.in
keepalived-2.2.2/doc/man/
keepalived-2.2.2/doc/man/man8/
........

# 將a.txt檔案追加到keepalived-2.2.2.tar中;
[root@superman-vm01 ~]# tar -rf keepalived-2.2.2.tar abc.txt
[root@superman-vm01 ~]#
[root@superman-vm01 ~]# tar tf keepalived-2.2.2.tar | grep abc.txt
abc.txt
[root@superman-vm01 ~]#

# 使用gzip格式打包並壓縮keepalived-2.2.2目錄;
[root@superman-vm01 ~]# tar -czvf keepalived-2.2.2.tar.gz keepalived-2.2.2
keepalived-2.2.2/
keepalived-2.2.2/tools/
keepalived-2.2.2/tools/timed_reload
keepalived-2.2.2/Makefile.in
keepalived-2.2.2/build-aux/
keepalived-2.2.2/build-aux/install-sh
keepalived-2.2.2/build-aux/missing
keepalived-2.2.2/build-aux/compile
keepalived-2.2.2/build-aux/depcomp
keepalived-2.2.2/build-aux/ar-lib
keepalived-2.2.2/bin_install/
keepalived-2.2.2/bin_install/Makefile.in
keepalived-2.2.2/bin_install/Makefile.am
keepalived-2.2.2/keepalived.spec.in
keepalived-2.2.2/snap/
keepalived-2.2.2/snap/snapcraft.yaml
keepalived-2.2.2/snap/hooks/
keepalived-2.2.2/snap/hooks/post-refresh
keepalived-2.2.2/snap/hooks/install
.........

# 使用bzip2格式打包並壓縮superman目錄;
[root@superman-vm01 ~]# tar -cjvf keepalived-2.2.2.tar.bz2 keepalived-2.2.2
keepalived-2.2.2/
keepalived-2.2.2/tools/
keepalived-2.2.2/tools/timed_reload
keepalived-2.2.2/Makefile.in
keepalived-2.2.2/build-aux/
keepalived-2.2.2/build-aux/install-sh
keepalived-2.2.2/build-aux/missing
keepalived-2.2.2/build-aux/compile
keepalived-2.2.2/build-aux/depcomp
keepalived-2.2.2/build-aux/ar-lib
keepalived-2.2.2/bin_install/
keepalived-2.2.2/bin_install/Makefile.in
keepalived-2.2.2/bin_install/Makefile.am
keepalived-2.2.2/keepalived.spec.in
keepalived-2.2.2/snap/
keepalived-2.2.2/snap/snapcraft.yaml
keepalived-2.2.2/snap/hooks/
keepalived-2.2.2/snap/hooks/post-refresh
keepalived-2.2.2/snap/hooks/install
..........

# 使用gzip格式打包並壓縮當前目錄所有檔案,排除abc.txt中記錄的檔案;
[root@superman-vm01 ceshi]# ls
abc.txt  keepalived-2.2.2
[root@superman-vm01 ceshi]#
[root@superman-vm01 ceshi]# tar -czf keepalived-2.2.2.tar.gz * -X abc.txt
[root@superman-vm01 ceshi]#
[root@superman-vm01 ceshi]# tar tf keepalived-2.2.2.tar.gz | grep abc.txt
abc.txt
[root@superman-vm01 ceshi]#

# 使用gzip格式打包並壓當前目錄所有檔案及目錄,排除abc.txt。
[root@superman-vm01 ceshi]# ls
abc.txt  keepalived-2.2.2
[root@superman-vm01 ceshi]#
[root@superman-vm01 ceshi]# tar -czf keepalived-2.2.2.tar.gz * --exclude=abc.txt
[root@superman-vm01 ceshi]#
[root@superman-vm01 ceshi]# tar tf keepalived-2.2.2.tar.gz | grep abc.txt
[root@superman-vm01 ceshi]#

3  原始碼包軟體安裝

通常使用RPM工具管理.rpm結尾的二進位制包,而標準的.zip、tar結尾的原始碼包則不能使用RPM工具去安裝、解除安裝及升級,原始碼包安裝有三個步驟,如下:

 ./configure    預編譯,主要用於檢測系統基準環境庫是否滿足,生成MakeFile檔案;

 make              編譯,基於第一步生成的makefile檔案,進行原始碼的編譯;
 make install   安裝,編譯完畢之後,將相關的可執行檔案安裝至系統中;
使用make編譯時,Linux作業系統必須有GCC編譯器,用於編譯原始碼。

原始碼包安裝通常需要./configure、make、make install三個步驟,某些特殊原始碼可以只有三步中的其中一個步驟,或者兩個步驟。

3.1 原始碼安裝實戰

以CentOS 7 Linux系統為基準,在其上安裝Nginx原始碼包,企業中原始碼安裝的詳細步驟如下:

1、nginx.org官網下載nginx-1.19.9.tar.gz包

[root@superman-vm01 ~]# wget
--2021-07-10 07:43:34--  
Resolving nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
Connecting to nginx.org (nginx.org)|52.58.199.22|:80... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.

--2021-07-10 07:43:35--  (try: 2)  
Connecting to nginx.org (nginx.org)|52.58.199.22|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 887908 (867K) [application/octet-stream]
Saving to: ‘nginx-1.19.9.tar.gz’

57% [=====================>                 ] 507,913     --.-K/s   in 16m 50s

2021-07-10 08:00:26 (503 B/s) - Read error at byte 507913/887908 (Connection timed out). Retrying.

--2021-07-10 08:00:28--  (try: 3)  
Connecting to nginx.org (nginx.org)|52.58.199.22|:80... connected.
HTTP request sent, awaiting response... 206 Partial Content
Length: 887908 (867K), 379995 (371K) remaining [application/octet-stream]
Saving to: ‘nginx-1.19.9.tar.gz’

100%[++++++++++++++++++++++================>] 887,908     6.46KB/s   in 52s    

2021-07-10 08:01:20 (7.11 KB/s) - ‘nginx-1.19.9.tar.gz’ saved [887908/887908]

[root@superman-vm01 ~]#

2、Nginx原始碼包解壓
[root@superman-vm01 ~]# tar -xvf nginx-1.19.9.tar.gz  
nginx-1.19.9/
nginx-1.19.9/auto/
nginx-1.19.9/conf/
nginx-1.19.9/contrib/
nginx-1.19.9/src/
nginx-1.19.9/configure
nginx-1.19.9/LICENSE
nginx-1.19.9/README
nginx-1.19.9/html/
nginx-1.19.9/man/
nginx-1.19.9/CHANGES.ru
nginx-1.19.9/CHANGES
nginx-1.19.9/man/nginx.8
nginx-1.19.9/html/50x.html
nginx-1.19.9/html/index.html
nginx-1.19.9/src/core/
..........

3、原始碼Configure預編譯,需進入解壓後的目錄執行./configure指令,分號“;”表示連線多個命令。
[root@superman-vm01 ~]# cd nginx-1.19.9/;./configure
checking for OS
+ Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
checking for gcc -pipe switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
...........

5、make install安裝
[root@superman-vm01 nginx-1.19.9]# make install
make -f objs/Makefile install
make[1]: Entering directory `/root/nginx-1.19.9'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin'                 || mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx'                 || mv '/usr/local/nginx/sbin/nginx'                     '/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf'                 || mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types'              || cp conf/mime.types '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
test -f '/usr/local/nginx/conf/fastcgi_params'          || cp conf/fastcgi_params '/usr/local/nginx/conf'
cp conf/fastcgi_params          '/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf'            || cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params'            || cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params            '/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params'             || cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params             '/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf'              || cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs'                 || mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' ||              mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html'                 || cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' ||              mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/root/nginx-1.19.9'
[root@superman-vm01 nginx-1.19.9]#  

透過以上五個步驟,原始碼包軟體安裝成功,原始碼包在編譯及安裝時,可能會遇到各種錯誤,需要把錯誤解決之後,然後再進行下一步安裝即可,後面章節會重點針對企業使用的軟體進行案例演練。

4  YUM軟體包管理

前端軟體包管理器(Yellow Updater Modified,YUM)適用於CentOS、Fedora、RedHat及SUSE中的Shell命令列,主要用於管理RPM包,於RPM工具使用範圍類似,YUM工具能夠從指定的伺服器自動下載RPM包並且安裝,還可以自動處理依賴性關係。

使用RPM工具管理和安裝軟體時,會發現rpm包有依賴,需要逐個手動下載安裝,而YUM工具的最大便利就是可以自動安裝所有依賴的軟體包,從而提升效率,節省時間。

4.1 YUM工作原理

學習YUM,一定要理解YUM工作原理,YUM正常執行,需要依賴兩個部分,一是YUM源端,二是YUM客戶端,也即使用者使用端。

YUM客戶端安裝的所有RPM包都是來自YUM服務端,YUM源端透過HTTP或者FTP伺服器釋出。而YUM客戶端能夠從YUM源端下載依賴的RPM包是由於在YUM源端生成了RPM包的基準資訊,包括RPM包版本號、配置檔案、二進位制資訊、依賴關係等。

YUM客戶端需要安裝軟體或者搜尋軟體,會查詢/etc/yum.repos.d下以.repo結尾檔案,CentOS Linux預設的.repo檔名為CentOS-Base.repo,該檔案中配置了YUM源端的映象地址,所以每次安裝、升級RPM包,YUM客戶端均會查詢.repo檔案。

YUM客戶端如果配置了CentOS官方repo源,客戶端作業系統必須能聯外網,滿足網路條件,才能下載軟體並安裝,如果沒有網路,也可以構建光碟源或者內部YUM源。在只要YUM客戶端時,YUM客戶端安裝軟體,預設會把YUM源地址、Header資訊、軟體包、資料庫資訊、快取檔案儲存在/var/cache/yum中,每次使用YUM工具,YUM優先透過Cache查詢相關軟體包,Cache中不存在,然後在訪問外網YUM源。

4.2 YUM引數詳解

由於YUM工具的使用簡便、快捷、高效,在企業中得到廣泛的使用,得到眾多IT運維、程式人員的青睞,要能熟練使用YUM工具,需要先掌握YUM命令列引數的使用,如下為YUM命令工具的引數詳解及實戰步驟:

YUM命令工具指南,YUM格式為:

YUM [command] [package] -y|-q 其中的[options]是可選。-y安裝或者解除安裝出現YES時,自動確認yes;-q不顯示安裝的過程。
yum install sysstat         安裝sysstat軟體包;
yum reinstall sysstat                   重新安裝sysstat軟體包
yum search sysstat      YUM搜尋軟體包;
yum list sysstat            顯示指定程式包安裝情況sysstat;
yum list          顯示所有已安裝及可安裝的軟體包;
yum remove sysstat       刪除程式包sysstat;
yum erase sysstat       刪除程式包sysstat;
yum update          核心升級或者軟體更新;
yum update sysstat       更新sysstat軟體;
yum check-update       檢查可更新的程式;
yum info sysstat            顯示安裝包資訊sysstat;
yum provides        列出軟體包提供哪些檔案;
yum provides "*/rz"      列出rz命令由哪個軟體包提供;
yum grouplist            詢可以用groupinstall安裝的組名稱;
yum groupinstall "Chinese Support"   安裝中文支援;
yum groupremove "Chinese Support"    刪除程式組Chinese Support;
yum deplist sysstat      檢視程式sysstat依賴情況;
yum clean   packages      清除快取目錄下的軟體包;
yum clean   headers      清除快取目錄下的headers;
yum clean   all            清除快取目錄下的軟體包及舊的headers。
yum repolist {all|enabled|disabled}     列出所有/已啟用/已禁用的yum源
yum list {all|installed|avaliable}      列出所有/已安裝/可安裝的軟體包
4.2.1 YUM安裝實戰

1、基於CentOS 7 Linux,執行命令yum install sysstat -y,安裝sysstat服務

[root@superman-vm01 ~]# yum install sysstat -y

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

* base: mirrors.aliyun.com
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package sysstat.x86_64 0:10.1.5-17.el7 will be updated
---> Package sysstat.x86_64 0:10.1.5-19.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================

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

Updating:
sysstat          x86_64          10.1.5-19.el7             base          315 k

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

Upgrade  1 Package

Total size: 315 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
 Updating   : sysstat-10.1.5-19.el7.x86_64                                 1/2
 Cleanup    : sysstat-10.1.5-17.el7.x86_64                                 2/2
 Verifying  : sysstat-10.1.5-19.el7.x86_64                                 1/2
 Verifying  : sysstat-10.1.5-17.el7.x86_64                                 2/2

Updated:
 sysstat.x86_64 0:10.1.5-19.el7                                                

Complete!
[root@superman-vm01 ~]#

2、執行命令yum grouplist,檢查groupinstall的軟體組名

[root@superman-vm01 ~]# yum grouplist

Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.bfsu.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
Available Environment Groups:
  Minimal Install
  Compute Node
  Infrastructure Server
  File and Print Server
  Basic Web Server
  Virtualization Host
  Server with GUI
  GNOME Desktop
  KDE Plasma Workspaces
  Development and Creative Workstation
Available Groups:
  Compatibility Libraries
  Console Internet Tools
  Development Tools
  Graphical Administration Tools
  Legacy UNIX Compatibility
  Scientific Support
  Security Tools
  Smart Card Support
  System Administration Tools
  System Management
Done
[root@superman-vm01 ~]#

3、執行命令yum groupinstall "GNOME Desktop" -y,安裝Linux影像介面

[root@superman-vm01 ~]# yum groupinstall "GNOME Desktop" -y

Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.bfsu.edu.cn
Warning: Group core does not have any packages to install.
Warning: Group gnome-desktop does not have any packages to install.
Warning: Group guest-agents does not have any packages to install.
Package gtk2-immodule-xim-2.24.31-1.el7.x86_64 already installed and latest version
Warning: Group guest-desktop-agents does not have any packages to install.
Warning: Group fonts does not have any packages to install.
Warning: Group print-client does not have any packages to install.
Warning: Group desktop-debugging does not have any packages to install.
Warning: Group dial-up does not have any packages to install.
Package gstreamer1-plugins-bad-free-1.10.4-3.el7.x86_64 already installed and latest version
Package gstreamer1-plugins-good-1.10.4-2.el7.x86_64 already installed and latest version
Package gstreamer1-plugins-ugly-free-1.10.4-3.el7.x86_64 already installed and latest version
Warning: Group multimedia does not have any packages to install.
Warning: Group base does not have any packages to install.
Group base does have 1 conditional packages, which may get installed.
Warning: Group internet-browser does not have any packages to install.
Warning: Group x11 does not have any packages to install.
Resolving Dependencies
--> Running transaction check
---> Package NetworkManager-bluetooth.x86_64 1:1.18.8-2.el7_9 will be installed
.........

4、執行命令yum install sysstat php php-devel php-mysql mariadb mariadb-server -y,安裝中小企業LAMP架構環境

[root@superman-vm01 ~]# yum install sysstat php php-devel php-mysql mariadb mariadb-server -y

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
Package sysstat-10.1.5-19.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.68-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.68-1.el7 for package: 1:mariadb-5.5.68-1.el7.x86_64
---> Package mariadb-server.x86_64 1:5.5.68-1.el7 will be installed
--> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.68-1.el7.x86_64
---> Package php.x86_64 0:5.4.16-48.el7 will be installed
--> Processing Dependency: php-common(x86-64) = 5.4.16-48.el7 for package: php-5.4.16-48.el7.x86_64
..........

5、執行命令yum remove ntpdate -y,解除安裝ntpdate軟體包

[root@superman-vm01 ~]# yum remove ntpdate -y
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2 will be erased
--> Processing Dependency: ntpdate = 4.2.6p5-29.el7.centos.2 for package: ntp-4.2.6p5-29.el7.centos.2.x86_64
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-29.el7.centos.2 will be erased
--> Processing Dependency: ntp for package: ipa-client-4.6.8-5.el7.centos.6.x86_64
--> Running transaction check
---> Package ipa-client.x86_64 0:4.6.8-5.el7.centos.6 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package         Arch        Version                        Repository     Size
================================================================================
Removing:
 ntpdate         x86_64      4.2.6p5-29.el7.centos.2        @base         121 k
Removing for dependencies:
 ipa-client      x86_64      4.6.8-5.el7.centos.6           @updates      255 k
 ntp             x86_64      4.2.6p5-29.el7.centos.2        @base         1.4 M
Transaction Summary
================================================================================
Remove  1 Package (+2 Dependent packages)
Installed size: 1.7 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : ipa-client-4.6.8-5.el7.centos.6.x86_64                       1/3 
  Erasing    : ntp-4.2.6p5-29.el7.centos.2.x86_64                           2/3 
  Erasing    : ntpdate-4.2.6p5-29.el7.centos.2.x86_64                       3/3 
  Verifying  : ntp-4.2.6p5-29.el7.centos.2.x86_64                           1/3 
  Verifying  : ntpdate-4.2.6p5-29.el7.centos.2.x86_64                       2/3 
  Verifying  : ipa-client-4.6.8-5.el7.centos.6.x86_64                       3/3 
Removed:
  ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2                                      
Dependency Removed:
  ipa-client.x86_64 0:4.6.8-5.el7.centos.6 ntp.x86_64 0:4.2.6p5-29.el7.centos.2
Complete!
[root@superman-vm01 ~]#

6、執行命令yum provides rz或者yum provides "*/rz",查詢rz命令的提供者

[root@superman-vm01 ~]# yum provides rz
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.bfsu.edu.cn
extras/7/x86_64/filelists_db                             | 235 kB     00:00     
updates/7/x86_64/filelists_db                            | 5.1 MB     00:04     
lrzsz-0.12.20-36.el7.x86_64 : The lrz and lsz modem communications programs
Repo        : base
Matched from:
Filename    : /usr/bin/rz
lrzsz-0.12.20-36.el7.x86_64 : The lrz and lsz modem communications programs
Repo        : @anaconda
Matched from:
Filename    : /usr/bin/rz
[root@superman-vm01 ~]# 
[root@superman-vm01 ~]# yum provides "*/rz"
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
lrzsz-0.12.20-36.el7.x86_64 : The lrz and lsz modem communications programs
Repo        : base
Matched from:
Filename    : /usr/bin/rz
lrzsz-0.12.20-36.el7.x86_64 : The lrz and lsz modem communications programs
Repo        : @anaconda
Matched from:
Filename    : /usr/bin/rz
[root@superman-vm01 ~]#

7、執行命令yum update -y,升級Linux所有可更新的軟體包或Linux核心升級

[root@superman-vm01 ~]# yum update -y

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package GeoIP.x86_64 0:1.5.0-13.el7 will be updated
---> Package GeoIP.x86_64 0:1.5.0-14.el7 will be an update
--> Processing Dependency: geoipupdate for package: GeoIP-1.5.0-14.el7.x86_64
---> Package ModemManager.x86_64 0:1.6.10-1.el7 will be updated
---> Package ModemManager.x86_64 0:1.6.10-4.el7 will be an update
---> Package ModemManager-glib.x86_64 0:1.6.10-1.el7 will be updated
---> Package ModemManager-glib.x86_64 0:1.6.10-4.el7 will be an update
---> Package PackageKit.x86_64 0:1.1.10-1.el7.centos will be updated
---> Package PackageKit.x86_64 0:1.1.10-2.el7.centos will be an update
...........

4.3 配置網路源


# 安裝163的yum源:

[root@superman-vm01 ~] # wget -O /etc/yum.repos.d/CentOS7-Base-163.repo
--2021-07-10 17:07:57--  
Resolving mirrors.163.com (mirrors.163.com)... 1.193.221.38, 124.116.156.215, 124.116.156.214, ...
Connecting to mirrors.163.com (mirrors.163.com)|1.193.221.38|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1572 (1.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS7-Base-163.repo’

100%[ ======================================>] 1,572       --.-K/s   in 0s      

2021 -07-10 17:07:57 (76.7 MB/s) - ‘/etc/yum.repos.d/CentOS7-Base-163.repo’ saved [1572/1572]

[root@superman-vm01 ~] #

# 安裝阿里雲的yum源:
[root@superman-vm01 ~] # wget -O /etc/yum.repos.d/CentOS-Base.repo
--2021-07-10 17:08:52--  
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 1.180.14.242, 1.180.14.241, 1.180.14.248, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|1.180.14.242|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

100%[ ======================================>] 2,523       --.-K/s   in 0s      

2021 -07-10 17:08:52 (384 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]

[root@superman-vm01 ~] #

# 搜狐沒有現成的yum原始檔下載,需要自己配置:

[root@superman-vm01 ~] # echo "[sohu]
name =Centos- $releasever -sohu
baseurl = $releasever/os/ $basearch
gpgcheck = 1
gpgkey = $releasever/os/ $basearch/RPM-GPG-KEY-CentOS- $releasever " > /etc/yum.repos.d/CentOS-souhu.repo
[root@superman-vm01 ~] #
[root@superman-vm01 ~] #
[root@superman-vm01 ~] #
[root@superman-vm01 ~] # yum makecache
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile

4.4 配置本地源

[root@superman-vm01 ~]# mkdir /mnt/cdrom

[root@superman-vm01 ~]# mount /dev/cdrom /mnt/cdrom
echo "[local]
name=centos-$releasever-local
baseurl=file:///mnt/cdrom
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-7" > /etc/yum.repos.d/centos-7-local.repomount: /dev/sr0 is write-protected, mounting read-only
[root@superman-vm01 ~]# echo "[local]
name=centos-$releasever-local
baseurl=file:///mnt/cdrom
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-7" > /etc/yum.repos.d/centos-7-local.repo
[root@superman-vm01 ~]#

4.5 自動配置倉庫

# 安裝yum的擴充套件包:

[root@superman-vm01 ~]# yum install yum-utils -y        
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base                                                     | 3.6 kB     00:00    
extras                                                   | 2.9 kB     00:00    
local                                                    | 3.6 kB     00:00    
updates                                                  | 2.9 kB     00:00  

# 自動配置國內epel倉庫:
[root@superman-vm01 ~]# yum-config-manager --add-repo=
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
adding repo from:

[mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_]
name=added from:
baseurl=
enabled=1


[root@superman-vm01 ~]#

4.6 禁用/啟用倉庫

# epel 是倉庫的id [epel]

[root@superman-vm01 ~]# yum-config-manager --disable epel
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
[root@superman-vm01 ~]#
[root@superman-vm01 ~]# yum-config-manager --enable epel
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
[root@superman-vm01 ~]#

# 檢視倉庫狀態:
[root@superman-vm01 ~]# yum repolist all
Loaded plugins: fastestmirror, langpacks
Repository 'sohu' is missing name in configuration, using id
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Loading mirror speeds from cached hostfile
Loading mirror speeds from cached hostfile
Loading mirror speeds from cached hostfile
Loading mirror speeds from cached hostfile
repo id                             repo name                         status
C7.0.1406-base/x86_64               CentOS-7.0.1406 - Base            disabled
C7.0.1406-centosplus/x86_64         CentOS-7.0.1406 - CentOSPlus      disabled
C7.0.1406-extras/x86_64             CentOS-7.0.1406 - Extras          disabled
C7.0.1406-fasttrack/x86_64          CentOS-7.0.1406 - Fasttrack       disabled
C7.0.1406-updates/x86_64            CentOS-7.0.1406 - Updates         disabled
C7.1.1503-base/x86_64               CentOS-7.1.1503 - Base            disabled
C7.1.1503-centosplus/x86_64         CentOS-7.1.1503 - CentOSPlus      disabled
C7.1.1503-extras/x86_64             CentOS-7.1.1503 - Extras          disabled
C7.1.1503-fasttrack/x86_64          CentOS-7.1.1503 - Fasttrack       disabled
C7.1.1503-updates/x86_64            CentOS-7.1.1503 - Updates         disabled
C7.2.1511-base/x86_64               CentOS-7.2.1511 - Base            disabled
C7.2.1511-centosplus/x86_64         CentOS-7.2.1511 - CentOSPlus      disabled
C7.2.1511-extras/x86_64             CentOS-7.2.1511 - Extras          disabled
C7.2.1511-fasttrack/x86_64          CentOS-7.2.1511 - Fasttrack       disabled
C7.2.1511-updates/x86_64            CentOS-7.2.1511 - Updates         disabled
C7.3.1611-base/x86_64               CentOS-7.3.1611 - Base            disabled
C7.3.1611-centosplus/x86_64         CentOS-7.3.1611 - CentOSPlus      disabled
C7.3.1611-extras/x86_64             CentOS-7.3.1611 - Extras          disabled
C7.3.1611-fasttrack/x86_64          CentOS-7.3.1611 - Fasttrack       disabled
C7.3.1611-updates/x86_64            CentOS-7.3.1611 - Updates         disabled
C7.4.1708-base/x86_64               CentOS-7.4.1708 - Base            disabled
C7.4.1708-centosplus/x86_64         CentOS-7.4.1708 - CentOSPlus      disabled
C7.4.1708-extras/x86_64             CentOS-7.4.1708 - Extras          disabled
C7.4.1708-fasttrack/x86_64          CentOS-7.4.1708 - Fasttrack       disabled
C7.4.1708-updates/x86_64            CentOS-7.4.1708 - Updates         disabled
C7.5.1804-base/x86_64               CentOS-7.5.1804 - Base            disabled
C7.5.1804-centosplus/x86_64         CentOS-7.5.1804 - CentOSPlus      disabled
C7.5.1804-extras/x86_64             CentOS-7.5.1804 - Extras          disabled
C7.5.1804-fasttrack/x86_64          CentOS-7.5.1804 - Fasttrack       disabled
C7.5.1804-updates/x86_64            CentOS-7.5.1804 - Updates         disabled
C7.6.1810-base/x86_64               CentOS-7.6.1810 - Base            disabled
C7.6.1810-centosplus/x86_64         CentOS-7.6.1810 - CentOSPlus      disabled
C7.6.1810-extras/x86_64             CentOS-7.6.1810 - Extras          disabled
C7.6.1810-fasttrack/x86_64          CentOS-7.6.1810 - Fasttrack       disabled
C7.6.1810-updates/x86_64            CentOS-7.6.1810 - Updates         disabled
C7.7.1908-base/x86_64               CentOS-7.7.1908 - Base            disabled
C7.7.1908-centosplus/x86_64         CentOS-7.7.1908 - CentOSPlus      disabled
C7.7.1908-extras/x86_64             CentOS-7.7.1908 - Extras          disabled
C7.7.1908-fasttrack/x86_64          CentOS-7.7.1908 - Fasttrack       disabled
C7.7.1908-updates/x86_64            CentOS-7.7.1908 - Updates         disabled
C7.8.2003-base/x86_64               CentOS-7.8.2003 - Base            disabled
C7.8.2003-centosplus/x86_64         CentOS-7.8.2003 - CentOSPlus      disabled
C7.8.2003-extras/x86_64             CentOS-7.8.2003 - Extras          disabled
C7.8.2003-fasttrack/x86_64          CentOS-7.8.2003 - Fasttrack       disabled
C7.8.2003-updates/x86_64            CentOS-7.8.2003 - Updates         disabled
base/7/x86_64                       CentOS-7 - Base - mirrors.aliyun. enabled: 0
base-debuginfo/x86_64               CentOS-7 - Debuginfo              disabled
base-source/7                       CentOS-7 - Base Sources           disabled
c7-media                            CentOS-7 - Media                  disabled
centos-kernel/7/x86_64              CentOS LTS Kernels for x86_64     disabled
centos-kernel-experimental/7/x86_64 CentOS Experimental Kernels for x disabled
centosplus/7/x86_64                 CentOS-7 - Plus - mirrors.aliyun. disabled
centosplus-source/7                 CentOS-7 - Plus Sources           disabled
contrib/7/x86_64                    CentOS-7 - Contrib - mirrors.aliy disabled
cr/7/x86_64                         CentOS-7 - cr                     disabled
extras/7/x86_64                     CentOS-7 - Extras - mirrors.aliyu enabled: 0
extras-source/7                     CentOS-7 - Extras Sources         disabled
fasttrack/7/x86_64                  CentOS-7 - fasttrack              disabled
sohu                                sohu                              enabled: 0
updates/7/x86_64                    CentOS-7 - Updates - mirrors.aliy enabled: 0
updates-source/7                    CentOS-7 - Updates Sources        disabled
repolist: 0
[root@superman-vm01 ~]#

5. 同步外網源

在企業實際應用場景中,僅僅靠光碟裡面的RPM軟體包是不能滿足需要,我們可以把外網的YUM源中的所有軟體包同步至本地,可以完善本地YUM源的軟體包數量及完整性。

5.1 安裝reposync工具

[root@superman-vm01 ~]# yum install yum-utils createrepo -y

Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_              | 4.7 kB     00:00    
(1/3): mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_/group_g |  96 kB   00:00    
(2/3): mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_/updatei | 1.0 MB   00:04    
(3/3): mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_/primary | 6.9 MB   00:07

5.2 同步源

# 建立本地目錄:

[root@superman-vm01 ~]# mkdir /data/{centos,epel}
[root@superman-vm01 ~]#

# 同步yum源:
[root@superman-vm01 ~]# reposync -r base -r updates -p /data/centos/
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
No Presto metadata available for base
389-ds-base-1.3.10.2-6.el7.x86 FAILED                                          
389-ds-base-devel-1.3.10.2-6.e FAILED                                          
(1/10072): 389-ds-base-snmp-1.3.10.2-6.el7.x86_64.rpm      | 178 kB   00:00    
(2/10072): ElectricFence-2.2.2-39.el7.i686.rpm             |  35 kB   00:00    
(3/10072): ElectricFence-2.2.2-39.el7.x86_64.rpm           |  35 kB   00:00    
(4/10072): GConf2-3.2.6-8.el7.i686.rpm                     | 1.0 MB   00:01    
(5/10072): Cython-0.19-5.el7.x86_64.rpm                    | 1.9 MB   00:03    
(6/10072): GConf2-3.2.6-8.el7.x86_64.rpm                   | 1.0 MB   00:01    
(7/10072): GConf2-devel-3.2.6-8.el7.i686.rpm               | 110 kB   00:00    
(8/10072): GConf2-devel-3.2.6-8.el7.x86_64.rpm             | 110 kB   00:00  
.........

# 生成後設資料:
[root@superman-vm01 ~]# createrepo /data/centos
[root@superman-vm01 ~]#

# 結合前面所學制作本地源,如果想讓其它伺服器使用該源,後面可以結合nginx釋出。

歡迎關注我的微信公眾號【 超哥的IT私房菜 】獲取更多技術乾貨!

image-20210707074326947

有什麼吐槽或反饋意見,直接告訴我! 我會解決您說的問題,進一步更好的服務您哦!



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/291614/viewspace-2780722/,如需轉載,請註明出處,否則將追究法律責任。

相關文章