linux中增加本地CD盤、阿里雲的yum包操作及rpm、yum、reposync指令簡析

rpm:在 Linux 操作系統下,幾乎所有的軟件均通過RPM 進行安裝、卸載及管理等操作。

-qa:查詢已經安裝的所有包

-qi:查詢已經安裝軟件的包信息和版本

-ql:已經安裝裝軟件包的配置文件

[root@localhost python]# rpm -qa | grep man
man-1.6f-32.el6.x86_64
man-pages-3.22-20.el6.noarch
pixman-0.32.4-4.el6.x86_64
crash-gcore-command-1.0-5.el6.x86_64
libsemanage-2.0.43-4.2.el6.x86_64
gnome-power-manager-2.28.3-7.el6_4.x86_64
man-pages-overrides-6.6.3-2.el6.noarch
erlang-pman-R14B-04.3.el6.x86_64
crash-trace-command-1.0-5.el6.x86_64

 

[root@localhost python]# rpm -qi man
Name        : man                          Relocations: (not relocatable)
Version     : 1.6f                              Vendor: CentOS
Release     : 32.el6                        Build Date: Fri 22 Feb 2013 10:13:10 AM CST
Install Date: Wed 19 Jul 2017 06:15:20 PM CST      Build Host: c6b9.bsys.dev.centos.org
Group       : System Environment/Base       Source RPM: man-1.6f-32.el6.src.rpm
Size        : 398388                           License: GPLv2
Signature   : RSA/SHA1, Sun 24 Feb 2013 01:39:26 AM CST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://primates.ximian.com/~flucifredi/man/
Summary     : A set of documentation tools: man, apropos and whatis

[root@localhost python]# rpm -qi mysql-sever
package mysql-sever is not installed

[root@localhost python]# rpm -ql man | more
/etc/cron.daily/makewhatis.cron
/etc/man.config
/usr/bin/apropos
/usr/bin/man
/usr/bin/man2html
/usr/bin/manpath
/usr/bin/whatis

[root@localhost python]# whereis  man  【擴展whereis 來搜索配置文件】
man: /usr/bin/man /etc/man.config /usr/share/man /usr/share/man/man7/man.7.gz /usr/share/man/man1p/man.1p.gz /usr/share/man/man1/man.1.gz

[root@localhost python]# rpm -ivh **.rpm【直接安裝】

[root@localhost python]# rpm -ivh /path/to/packege **.rpm 【指定安裝目錄】

-h:顯示進度;-v:顯示過程;-v:顯示詳細過程。

 

yum:yum(全稱爲 Yellow dog Updater, Modified)是一個在Fedora和RedHat以及SUSE中的Shell前端軟件包管理器。基於RPM包管理,能夠從指定的服務器自動下載RPM包並且安裝,可以自動處理依賴性關係,並且一次安裝所有依賴的軟體包,無須繁瑣地一次次下載、安裝。yum提供了查找、安裝、刪除某一個、一組甚至全部軟件包的命令,而且命令簡潔而又好記.

 

yum install httpd 安裝httpd的軟件包。

yum 中搜索mysql的服務包

yum中查看httpd的信息。

本次案例參考使用阿里雲的Yum包來安裝。(https://opsx.alibaba.com/mirror

備份文件【我本地刪除所有文件,記得刪除先備份】

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

[root@localhost ~]# cd /etc/yum.repos.d
yum.repos.d/                      yum.repos.d.backup_backup.tar.gz  
[root@localhost ~]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Base.repo.backup
[root@localhost yum.repos.d]# yum clean all 【清除yum之前配置】
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache   【加載yum的緩存】
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                           | 3.7 kB     00:00     
base/group_gz                                                                                  | 242 kB     00:00     
base/filelists_db                                                                              | 6.4 MB     00:02     
base/primary_db                                                                                | 4.7 MB     00:02     
base/other_db                                                                                  | 2.8 MB     00:01     
extras                                                                                         | 3.4 kB     00:00     
extras/filelists_db                                                                            |  24 kB     00:00     
extras/prestodelta                                                                             | 1.1 kB     00:00     
extras/primary_db                                                                              |  27 kB     00:00     
extras/other_db                                                                                |  28 kB     00:00     
updates                                                                                        | 3.4 kB     00:00     
updates/filelists_db                                                                           | 1.7 MB     00:00     
updates/prestodelta                                                                            |  80 kB     00:00     
updates/primary_db                                                                             | 2.4 MB     00:01     
updates/other_db                                                                               |  33 MB     00:26     
Metadata Cache Created
[root@localhost yum.repos.d]# yum search openssl  【查詢yum中是否有openssl中安裝包】
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
================================================ N/S Matched: openssl ================================================
openssl-devel.i686 : Files for development of applications which will use OpenSSL
openssl-devel.x86_64 : Files for development of applications which will use OpenSSL
openssl-perl.x86_64 : Perl scripts provided with OpenSSL
openssl-static.x86_64 : Libraries for static linking of applications which will use OpenSSL
perl-Crypt-OpenSSL-Bignum.x86_64 : Perl interface to OpenSSL for Bignum
perl-Crypt-OpenSSL-RSA.x86_64 : Perl interface to OpenSSL for RSA

[root@localhost yum.repos.d]# yum repolist 【已經看到阿里巴巴的Yum庫文件了】
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                 repo name                                                               status
base                                    CentOS-6 - Base - mirrors.aliyun.com                                    6,713
extras                                  CentOS-6 - Extras - mirrors.aliyun.com                                     35
updates                                 CentOS-6 - Updates - mirrors.aliyun.com                                   257
repolist: 7,005

案例二【加載本地的CD盤中的資源】

#mkdir /mnt/repos/

#mount /dev/cdrom /mnt/repos/

#cd /mnt/repos/Packages

#cd /etc/yum.repos.d/

#cp CentOS-Base.repo CentOS-Base.repo.aliyun.backup

 #mv CentOS-Base.repo my.repo  #將原來的文件備份,然後更名修改my.repo的配置參數。

 

#yum clean all
#yum makecache

[root@localhost yum.repos.d]# yum repolist 【查看本身Cd掛載包的packege包】
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: 
 * updates: mirrors.cn99.com
repo id                                           repo name                                                     status
base                                              CentOS-6 - Base                                               6,367
updates                                           CentOS-6 - Updates                                              259
repolist: 6,626

【測試是不是掛載了,這裏搜索有些資源來鑑定】

[root@localhost yum.repos.d]# yum search zlib
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: 
 * updates: mirrors.aliyun.com
================================================= N/S Matched: zlib ==================================================
jzlib.x86_64 : JZlib re-implementation of zlib in pure Java
jzlib-demo.x86_64 : Examples for jzlib
jzlib-javadoc.x86_64 : Javadoc for jzlib
mingw32-zlib.noarch : MinGW Windows zlib compression librar

[root@localhost yum.repos.d]# yum search openssl-devel 【Openssl-devel資源包不在Cd盤掛載的分區中】
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: 
 * updates: mirrors.aliyun.com
============================================= N/S Matched: openssl-devel =============================================
openssl-devel.i686 : Files for development of applications which will use OpenSSL
openssl-devel.x86_64 : Files for development of applications which will use OpenSSL

  Name and summary matches only, use "search all" for everything.

稱熱打鐵(把掛載的CD盤,進行自動掛載,不需要關機就卸載)

[root@localhost mnt]# mount /dev/cdrom /mnt/repos/   【確保CD盤已經掛載】
mount: block device /dev/sr0 is write-protected, mounting read-only
mount: /dev/sr0 already mounted or /mnt/repos/ busy
mount: according to mtab, /dev/sr0 is already mounted on /mnt/repos
[root@localhost mnt]# cd repos/
[root@localhost repos]# ls
CentOS_BuildTag  GPL       Packages                  RPM-GPG-KEY-CentOS-6           RPM-GPG-KEY-CentOS-Testing-6
EFI              images    RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Debug-6     TRANS.TBL
EULA             isolinux  repodata     

[root@localhost repos]# vim /etc/fstab 【修改文件參數,如圖下】

 

案例3  在系統本身同步阿里雲的資源包,保證內網下面安裝使用。

[root@localhost repos]# cd /etc/yum  【進去yum的配置文件】
yum/                              yum.repos.d/                      
yum.conf                          yum.repos.d.backup_backup.tar.gz  
[root@localhost repos]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# ls
CentOS-Base.repo.aliyun.backup  CentOS-Base.repo.backup  my.repo
[root@localhost yum.repos.d]# mv my.repo my.repo_backup
[root@localhost yum.repos.d]# mv CentOS-Base.repo.aliyun.backup CentOS-Base.repo.aliyun  
[root@localhost yum.repos.d]# mv CentOS-Base.repo.aliyun CentOS-Base.repo   【同上一樣,把配置文件改動回來】
[root@localhost yum.repos.d]# yum claen
Loaded plugins: fastestmirror, refresh-packagekit, security
No such command: claen. Please use /usr/bin/yum --help
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                           | 3.7 kB     00:00     
base/group_gz                                                                                  | 242 kB     00:00     
base/filelists_db                                                                              | 6.4 MB     00:01     
base/primary_db                                                                                | 4.7 MB     00:01     
base/other_db                                                                                  | 2.8 MB     00:00     
extras                                                                                         | 3.4 kB     00:00     
extras/filelists_db                                                                            |  24 kB     00:00     
extras/prestodelta                                                                             | 1.1 kB     00:00     
extras/primary_db                                                                              |  27 kB     00:00     
extras/other_db                                                                                |  28 kB     00:00     
updates                                                                                        | 3.4 kB     00:00     
updates/filelists_db                                                                           | 2.0 MB     00:00     
updates/prestodelta                                                                            | 104 kB     00:00     
updates/primary_db                                                                             | 3.0 MB     00:00     
updates/other_db                                                                               |  42 MB     00:18     
Metadata Cache Created
[root@localhost yum.repos.d]# yum repolist    【已經變成回來阿里雲的yum庫】
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                 repo name                                                               status
base                                    CentOS-6 - Base - mirrors.aliyun.com                                    6,713
extras                                  CentOS-6 - Extras - mirrors.aliyun.com                                     35
updates                                 CentOS-6 - Updates - mirrors.aliyun.com                                   311
repolist: 7,059
[root@localhost yum.repos.d]# reposync -r base -p /opt/repos/   【reposync 同步指令,可以用Man reposync來搜索幫助。這裏更新阿里雲官網的Yum包到本地 repos中】
[base: 1     of 6713  ] Downloading Packages/389-ds-base-1.2.11.15-95.el6_9.x86_64.rpm
389-ds-base-1.2.11.15-95.el6_9.x86_64.rpm                                                      | 1.5 MB     00:00     
。。。。。【由於太多,我就截圖一半了】

[root@localhost repos]# ls   【查看驗證】
base
[root@localhost repos]# cd base/
[root@localhost base]# ls
Packages
[root@localhost base]# cd Packages/
[root@localhost Packages]# ls
389-ds-base-1.2.11.15-95.el6_9.x86_64.rpm                 ConsoleKit-libs-0.4.1-6.el6.x86_64.rpm
389-ds-base-devel-1.2.11.15-95.el6_9.i686.rpm             ConsoleKit-x11-0.4.1-6.el6.x86_64.rpm
389-ds-base-devel-1.2.11.15-95.el6_9.x86_6

 

總結: yum、rpm的操作不簡單,也不復雜。熟悉掌握好,可以做本地yum包。用一臺專門連接外部網絡的機子做支撐,其他需要更新安裝YUm包的機子專門連接這臺。外部網絡互相聯通的機子保持資源更新,其他機子保證內網下做大數據、人工智能測試。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章