軟體包管家之---yum 2

軟體包管家之---yum 2

來自專欄 Linux 雲計算1 人贊了文章

接上文「軟體包管家之---yum 1」

yum源

阿里雲repo文件:mirrors.aliyun.com/repo CentOS系統的yum源

  • 阿里云: https://mirrors.aliyun.com/centos/$releasever/os/x86_64/
  • 清華大學: https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/x86_64/

EPEL的yum源:

  • 阿里云: https://mirrors.aliyun.com/epel/$releasever/x86_64
  • 自製yum:createrepo path1 ####可以把package拷貝到此路徑,就可以當yum倉庫

Yum常用命令

yum命令的用法:yum [options] [command] [package ...] options

  • --nogpgcheck:禁止進行gpg check
  • -y: 自動回答為「yes」
  • -q:靜默模式
  • --disablerepo=repoidglob:臨時禁用此處指定的repo
  • --enablerepo=repoidglob:臨時啟用此處指定的repo
  • --noplugins:禁用所有插件

command: (1)顯示倉庫列表:yum repolist [all|enabled|disabled] (2)顯示程序包:

  • yum list
  • yum list [all | glob_exp1] [glob_exp2] [...] ####支持通配符的搜索
  • yum list {available|installed|updates} [glob_exp1] [...] ####available表示可用,但還沒有安裝的包,installed表示已經安裝好的包;@表示已經安裝好

(3)安裝程序包:

  • yum install package1 [package2] [...]
  • yum reinstall package1 [package2] [...] (重新安裝)
  • 安裝本地rpm包:yum install XXX.rpm

(4)卸載: yum remove | erase package1 [package2] [...] (5)升級程序包:

  • yum update [package1] [package2] [...] ####不加package,就是全升級
  • yum downgrade package1 [package2] [...] (降級)

(6)檢查可以升級程序包: yum check-update (7)搜索: yum search string1 [string2] [...] #####在yum倉庫中查看關鍵字相關的包名和summary (8)查看程序包的信息:yum info [...] (9)查詢未安裝包中包括的文件列表 repoquery -ql package (先安裝yum-utils工具,基於yum倉庫) (10)查看指定的特性(可以是某文件)是由哪個程序包所提供:yum provides /bin/ls (11)清除緩存:yum clean all (12)創建yum倉庫:createrepo [options] <directory> (13)查看yum事務歷史:

  • yum history [info|list|packages-list|packages-info|
  • summary|addon-info|redo|undo|
  • rollback|new|sync|stats]
  • yum history
  • yum history info 6
  • yum history undo 6 ####撤銷之前的操作,具有依賴性安裝的包可以全部撤回

(14)日誌 : /var/log/yum.log

[root@centos7 yum.repos.d]# yum search libvir ####搜索包頭,匹配搜索,包括安裝和未安裝的Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile==================================== N/S matched: libvir =====================================fence-virtd-libvirt.x86_64 : Libvirt backend for fence-virtdlibvirt-client.x86_64 : Client side utilities of the libvirt librarylibvirt-daemon.x86_64 : Server side daemon and supporting files for libvirt librarylibvirt-daemon-config-network.x86_64 : Default configuration files for the libvirtd daemonlibvirt-daemon-config-nwfilter.x86_64 : Network filter configuration files for the libvirtd : daemonlibvirt-daemon-driver-interface.x86_64 : Interface driver plugin for the libvirtd daemonlibvirt-daemon-driver-lxc.x86_64 : LXC driver plugin for the libvirtd daemonlibvirt-daemon-driver-network.x86_64 : Network driver plugin for the libvirtd daemon[root@centos7 yum.repos.d]# yum remove libvirt-daemon ###卸載包,libvirt-daemon與虛擬網卡有關,可以卸載掉[root@centos7 yum.repos.d]# rpm -q yum-utilsyum-utils-1.1.31-45.el7.noarch[root@centos7 yum.repos.d]#[root@centos7 yum.repos.d]# rpm -q vsftpdpackage vsftpd is not installed[root@centos7 yum.repos.d]# repoquery -ql vsftpd/etc/logrotate.d/vsftpd/etc/pam.d/vsftpd/etc/vsftpd/etc/vsftpd/ftpusers/etc/vsftpd/user_list/etc/vsftpd/vsftpd.conf/etc/vsftpd/vsftpd_conf_migrate.sh/usr/lib/systemd/system-generators/vsftpd-generator/usr/lib/systemd/system/vsftpd.service/usr/lib/systemd/system/vsftpd.target/usr/share/man/man5/vsftpd.conf.5.gz/usr/share/man/man8/vsftpd.8.gz/var/ftp/var/ftp/pub[root@centos7 yum.repos.d]# yum info tree ####查看程序的信息,未安裝的也可以查看Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfileInstalled PackagesName : treeArch : x86_64Version : 1.6.0Release : 10.el7Size : 87 kRepo : installedFrom repo : cdromSummary : File system tree viewerURL : http://mama.indstate.edu/users/ice/tree/License : GPLv2+Description : The tree utility recursively displays the contents of directories in a : tree-like format. Tree is basically a UNIX port of the DOS tree : utility.[root@centos7 yum.repos.d]# yum list |grep tree ####可以查看所有的包,包括安裝的和為安裝的,@cdrom表示已經從cdrom裝好了,沒有@就表示在yum倉庫中tree.x86_64 1.6.0-10.el7 @cdrom maven-dependency-tree.noarch 2.0-7.el7 cdrom maven-dependency-tree-javadoc.noarch 2.0-7.el7 cdrom subscription-manager-plugin-ostree.x86_64 1.20.11-1.el7.centos cdrom texlive-pst-tree.noarch 2:svn24142.1.12-38.el7 cdrom texlive-pst-tree-doc.noarch 2:svn24142.1.12-38.el7 cdrom [root@centos7 yum.repos.d]# tree.├── cdrom.repo└── repo_backup ├── CentOS-Base.repo ├── CentOS-CR.repo ├── CentOS-Debuginfo.repo ├── CentOS-fasttrack.repo ├── CentOS-Media.repo ├── CentOS-Sources.repo └── CentOS-Vault.repo1 directory, 8 files[root@centos7 yum.repos.d]# yum list installed ####只查看已經安裝好的安裝包Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfileInstalled PackagesGConf2.x86_64 3.2.6-8.el7 @anacondaGeoIP.x86_64 1.5.0-11.el7 @anacondaModemManager.x86_64 1.6.10-1.el7 @anacondaModemManager-glib.x86_64 1.6.10-1.el7 @anacondaNetworkManager.x86_64 1:1.10.2-13.el7 @anaconda


yum包組的常用命令

  1. 列出包組:yum groupslist
  2. 安裝包組:yum groupinstall "Development Tools" -y
  3. 卸載包組: yum groupremove packagename
  4. 查看包組的信息:yum groupinfo groupname
  5. 升級包組:yum groupupdate groupname

[root@centos7 yum.repos.d]# yum grouplist ####列出yum源中包組列表Loaded plugins: fastestmirror, langpacksThere is no installed groups file.Maybe run: yum groups mark convert (see man yum)Loading mirror speeds from cached hostfileAvailable 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 WorkstationAvailable 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 ManagementDone[root@centos7 yum.repos.d]# yum groupinstall "Development Tools" -y ###執行包組的安裝[root@centos7 wu]# yum groupinfo "Development Tools" ####查看包組的信息時,裡面的+ = -代表不同的含義Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfileGroup: Development ToolsGroup-Id: developmentDescription: A basic development environment.Mandatory Packages: +autoconf #####+號表示沒有安裝,升級的時候會自動安裝 +automake binutils #####不帶符號,表示已經裝好的包,但不是隨著包組一起裝上的 +bison +flex +gcc +gcc-c++ gettext +libtool make =byacc ####=表示安裝包組的時候裝上的包 -trac ####-表示包還沒有安裝,不會隨著包組一起安裝


項目實戰

1.利用腳本配置yum客戶端

[root@centos7 data]# vim createrepo.sh#!/bin/bash## CentOS-Media.repo## This repo can be used with mounted DVD media, verify the mount point for# CentOS-7. You can use this repo and yum to install items directly off the# DVD ISO that we release.## To use this repo, put in your DVD and use it with the other repos too:# yum --enablerepo=c7-media [command]# # or for ONLY the media repo, do this:## yum --disablerepo=* --enablerepo=c7-media [command]mkdir /etc/yum.repos.d/backupmv /etc/yum.repos.d/* /etc/yum.repos.d/backupcat > /etc/yum.repos.d/test.repo <<EOF[c7-media]name=CentOS-$releasever - Mediabaseurl=file:///media/CentOS/file:///media/cdrom/file:///media/cdrecorder/gpgcheck=1enabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7EOF

2.模擬自研rpm包,製作yum倉庫

[root@centos7 wu]# mount /dev/sr0 /mntmount: /dev/sr0 is write-protected, mounting read-only[root@centos7 wu]# cp /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm /data[root@centos7 wu]# cd /data/[root@centos7 data]# lltotal 48-rw-r--r--. 1 root root 47508 Aug 11 09:34 tree-1.6.0-10.el7.x86_64.rpm[root@centos7 data]# createrepo . ####製作yum倉庫路徑Spawning worker 0 with 1 pkgsSpawning worker 1 with 0 pkgsWorkers FinishedSaving Primary metadataSaving file lists metadataSaving other metadataGenerating sqlite DBsSqlite DBs complete[root@centos7 data]# lltotal 52drwxr-xr-x. 2 root root 4096 Aug 11 09:36 repodata-rw-r--r--. 1 root root 47508 Aug 11 09:34 tree-1.6.0-10.el7.x86_64.rpm[root@centos7 data]# pwd #####這個路徑可以作為客戶端的yum倉庫路徑/data[root@centos7 data]# pwd/data[root@centos7 data]# cd /etc/yum.repos.d/[root@centos7 yum.repos.d]# lltotal 4-rw-r--r--. 1 root root 149 Aug 10 20:47 cdrom.repodrwxr-xr-x. 2 root root 187 Aug 10 20:42 repo_backup[root@centos7 yum.repos.d]# vim cdrom.repo[cdrom]name=cdrom repobaseurl=file:///run/media/wu/CentOS 7 x86_64gpgcheck=1gpgkey=file:///run/media/wu/CentOS 7 x86_64/RPM-GPG-KEY-CentOS-7enabled=1[test]name=testbaseurl=file:///data/gpgcheck=0~ "cdrom.repo" 11L, 210C written [root@centos7 yum.repos.d]#[root@centos7 yum.repos.d]#[root@centos7 yum.repos.d]#[root@centos7 yum.repos.d]#[root@centos7 yum.repos.d]#[root@centos7 yum.repos.d]#[root@centos7 yum.repos.d]# yum repolist ####可以看到成功將test作為yum倉庫了Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfilefile:///run/media/wu/CentOS%207%20x86_64/repodata/repomd.xml: [Errno 14] curl#37 - "Couldnt open file /run/media/wu/CentOS%207%20x86_64/repodata/repomd.xml"Trying other mirror.test | 2.9 kB 00:00:00 test/primary_db | 1.8 kB 00:00:00 repo id repo name status!cdrom cdrom repo 9,911test test 1repolist: 9,912[root@centos7 yum.repos.d]#

推薦閱讀:

超聲去污大作戰:揣進兜里的「洗衣機」| 科技讓生活更美好
【裝機幫扶站】第180期:萬元神機真的只能用來掃雷!
楊元慶回應「不要給技術貼上愛國標籤」聯想是為了技術站隊高通?
未來人類與人工智慧的關係有這十二種可能性,你pick哪一種?丨花生觀察醬

TAG:科技 | Linux運維 | 雲計算 |