Linux (CentOS) software management (2) – Yum install online

Time:2021-12-2

When installing RPM packages manually, solving the dependency problem is a big trouble. If all RPM packages are installed manually, the use of RPM packages is large. Therefore, the red hat series has introduced the “Yum online installation” method.

Advantages of Yum online installation: put all software packages on the official server. When Yum online installation is performed, the dependency problem can be solved automatically.

1、 Yum source profile

1. Location

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

2. Content instance (centos7)

[root/etc/yum.repos.d]$cat CentOS-Base.repo
# CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

3. Description

\ explain
[base] The container name must be placed in []
name Container description, you can write it yourself
mirrorlist Mirror site
baseurl Yum source server address
enabled Whether this container is valid. Do not write or enable = 1 takes effect, and enable = 0 does not take effect
gpgcheck Whether the RPM digital certificate is valid. 1: Entry into force; 0: not effective
gpgkey The location where the RPM digital certificate public key file is saved. Generally do not modify.
About baseurl
Baseurl is the official Yum source server address of CentOS by default. It can be used, but because it is a foreign website, the access may be slow. At this time, you can replace it with another Yum source server address.
Common Yum source server address
\ address
Netease http://mirrors.163.com/.help/…
Sohu http://mirrors.sohu.com/help/…
Tsinghua University https://mirrors.tuna.tsinghua…
University of science and technology of China http://centos.ustc.edu.cn/hel…

For more open source images, see [IV. sorting of commonly used linux domestic open source image stations]

4. Clear Yum cache

Yum will download the list of containers to the local/var/cache/yumIn, when we modify the web address of the container without modifying the name of the container, the list in the local cache may be out of sync with the list in the yum service. At this time, there will be a problem that we can’t update.
In this case, you need to clear the yum cache.

command

yum clean [packages|headers|all]
parameter

packages: delete downloaded software cache files
headers: delete the downloaded software file header cache
all: delete all container cache data

example
[root/var/cache/yum/x86_64/7]$yum clean packages
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
0 package files removed

[root/var/cache/yum/x86_64/7]$yum clean headers
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
0 header files removed

[root/var/cache/yum/x86_64/7]$yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors

5. List all containers of the current Yum server

command
yum repolist all
example
[vagrant~]$yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.huaweicloud.com
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
... omit
base/7/x86_64                      CentOS-7 - Base                   enabled: 9,911
base-debuginfo/x86_64              CentOS-7 - Debuginfo              disabled
base-source/7                      CentOS-7 - Base Sources           disabled
... omit
extras/7/x86_64                    CentOS-7 - Extras                 enabled:   291
extras-source/7                    CentOS-7 - Extras Sources         disabled
fasttrack/7/x86_64                 CentOS-7 - fasttrack              disabled
updates/7/x86_64                   CentOS-7 - Updates                enabled:   626
updates-source/7                   CentOS-7 - Updates Sources        disabled
repolist: 10,828

6. yum-fastestmirrorplug-in unit

For CentOS system administrators, yum is definitely a good thing. Unfortunately, the speed of official Yum sources is really hard to compliment, while unofficial Yum sources are diverse and difficult to choose.

Fortunately, the yum fastestmirror plug-in makes up for this defect: automatically select the fastest Yum source.
install
yum -y install yum-fastestmirror
configuration file
/etc/yum/pluginconf.d/fastestmirror.conf

/Var / cache / Yum / timedhosts.txt #yum mirrored speed test record file

2、 Build yam source using CD

Without a network, we can’t install online using yum. At this time, we can use the CD to build the yum source.

1. Mount the CD

  • Insert disc
  • Establish mount point
[root/dev]$mkdir /mnt/cdrom
  • Mount CD
[root/dev]$mount /dev/cdrom /mnt/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only

2. Disable the network Yum source

  • get into/etc/yum.repos.dDirectory, modify the network Yum source file suffix to make it invalid
[root~]$cd /etc/yum.repos.d/
[root/etc/yum.repos.d]$mv CentOS-Base.repo CentOS-Base.repo.bak

3. Make the CD source effective

[root/etc/yum.repos.d]$vim CentOS-Media.repo
# CentOS-Media.repo

[c7-media]
name=CentOS-$releasever - Media
baseurl= file:///mnt/cdrom    #The address is the CD mount address
# file:///media/CentOS/  #Comment out addresses that do not exist
#        file:///media/cdrom/
#        file:///media/cdrecorder/
gpgcheck=1
Enabled = 1 # change enabled = 0 to enabled = 1 to make the yum source file effective
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

4. Can be usedyum listCommand to view the available packages from the yum source on the CD

3、 Yum common commands

1. Query

Yum [list info search providers whatprovides] [parameters]
Query the list of all available packages
yum list

yum list installedYou can view all installed software

Use wildcard matching to query the list of available packages
yum list [pattern]
  • example
[root~]$yum list g?nc-[a-e]*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.sohu.com
Available Packages
gvnc-devel.i686                      0.7.0-3.el7                   base

gvnc-devel.x86_64                    0.7.0-3.el7                   base
Query the list of software available for upgrading on the server
yum list updates
  • example
[root/etc/yum.repos.d]$yum list updates
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.huaweicloud.com
Updated Packages
NetworkManager.x86_64                       1:1.10.2-14.el7_5               updates
NetworkManager-libnm.x86_64                 1:1.10.2-14.el7_5               updates
NetworkManager-ppp.x86_64                   1:1.10.2-14.el7_5               updates
... omit
Search all keyword related packages on the server
Yum search [keyword]
Yum search all [Keywords]
example
[root~]$yum search fastestmirror
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.huaweicloud.com
==================================== N/S matched: fastestmirror ====================
yum-plugin-fastestmirror.noarch : Yum plugin which chooses fastest repository from a mirrorlist

  Name and summary matches only, use "search all" for everything.
[root~]$yum search all fastestmirror
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.huaweicloud.com
==================================== Matched: fastestmirror ========================
yum-plugin-fastestmirror.noarch : Yum plugin which chooses fastest repository from a mirrorlist

2. Installation

grammar
Yum - y install [package name]
option

-y: automatically answer yes when prompted whether to install dependencies
install: installation

example
[root~]$yum install -y gcc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.huaweicloud.com
base                                                                | 3.6 kB  00:00:00
extras                                                              | 3.4 kB  00:00:00
... omit
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-28.el7 will be updated
--> Processing Dependency: gcc = 4.8.5-28.el7 for package: gcc-c++-4.8.5-28.el7.x86_64
... omit
---> Package libstdc++-devel.x86_64 0:4.8.5-28.el7_5.1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================
 Package          Arch          Version     Repository       Size
=======================================================================================
Updating:
 gcc            x86_64    4.8.5-28.el7_5.1    updates     16 M
Updating for dependencies:
 cpp            x86_64    4.8.5-28.el7_5.1    updates     5.9 M
... omit
Transaction Summary
=========================================================================================
Upgrade  1 Package (+8 Dependent packages)

Total download size: 32 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/9): gcc-4.8.5-28.el7_5.1.x86_64.rpm                               |  16 MB  00:00:03
(2/9): libgcc-4.8.5-28.el7_5.1.i686.rpm                              | 108 kB  00:00:00
... omit
(9/9): gcc-c++-4.8.5-28.el7_5.1.x86_64.rpm                           | 7.2 MB  00:00:06
----------------------------------------------------------------------------------------
Total                                                       4.9 MB/s |  32 MB  00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Updating   : libgcc-4.8.5-28.el7_5.1.x86_64                         1/18
  Updating   : libstdc++-4.8.5-28.el7_5.1.x86_64                      2/18
... omit
  Cleanup    : libgomp-4.8.5-28.el7.x86_64                            18/18
  Verifying  : libgomp-4.8.5-28.el7_5.1.x86_64                        1/18
  Verifying  : libstdc++-4.8.5-28.el7_5.1.i686                        2/18
  ... omit
  Verifying  : libstdc++-4.8.5-28.el7.i686                            18/18

Updated:
  gcc.x86_64 0:4.8.5-28.el7_5.1

Dependency Updated:
  cpp.x86_64 0:4.8.5-28.el7_5.1         gcc-c++.x86_64 0:4.8.5-28.el7_5.1       libgcc.i686 0:4.8.5-28.el7_5.1                libgcc.x86_64 0:4.8.5-28.el7_5.1     libgomp.x86_64 0:4.8.5-28.el7_5.1
  libstdc++.i686 0:4.8.5-28.el7_5.1     libstdc++.x86_64 0:4.8.5-28.el7_5.1     libstdc++-devel.x86_64 0:4.8.5-28.el7_5.1

Complete!

3. Upgrade

In the production server, unless there is a major bug in the current software version, try not to upgrade the software
useYum -y update [package name]Use extreme caution when ordering, if not enteredPackage name, the command becomesyum -y update, the commandUpgrade all packages as well as software and system kernel, it may cause system restart or even crash!

grammar
Yum -y update [package name]
Yum - y upgrade [package name]
option

-y: automatically answer yes when prompted whether to install dependencies
updateKernel update, followed by the software to be updated, otherwise all packages will be updated, software settings and system settings will be changed, and the system version will be updated
upgrade: upgrade, followed by the software to be upgraded, otherwise all packages will be upgraded.

4. Unloading

In the production server, the server should use the minimum installation, install what software, and try not to uninstall

grammar
Yum - y remove [package name]
option

-y: automatically answer yes when prompted whether to install dependencies
remove: uninstall software

example
[root~]$yum -y remove zip
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package zip.x86_64 0:3.0-11.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

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

Removing:
 zip            x86_64      3.0-11.el7      installed           796 k

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

Remove  1 Package

Installed size: 796 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : zip-3.0-11.el7.x86_64                                1/1
  Verifying  : zip-3.0-11.el7.x86_64                                1/1

Removed:
  zip.x86_64 0:3.0-11.el7

5. Yum software group management command

List all available software groups
yum grouplist
  • example
[root~]$yum grouplist
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.sohu.com
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
Install the specified software group. The group name can be found in the grouplist
Yum groupinstall [software group name]
Uninstall the specified software group
Yum groupremove [software group name]

4、 Sorting of common Linux domestic open source image stations

[Alibaba cloud open source mirror station]:https://opsx.alibaba.com/

[Huawei open source mirror station]:http://mirrors.huaweicloud.com/

[Netease open source mirror station]:http://mirrors.163.com/

[Sohu open source mirror station]:http://mirrors.sohu.com/

[Tsinghua University open source software mirror station]:https://mirrors.tuna.tsinghua…

[open source mirror station of University of science and technology of China]:http://centos.ustc.edu.cn/

[open source mirror station of Shanghai University]:http://mirrors.shu.edu.cn/

[Zhejiang University open source mirror station]:http://mirrors.zju.edu.cn/

[open source mirror station of Shanghai Jiaotong University]:http://ftp.sjtu.edu.cn/

[Chongqing University open source software mirror station]:http://mirrors.cqu.edu.cn/

[open source mirror station of Nanjing University]:http://mirrors.nju.edu.cn/

[open source software mirror station of Nanjing University of Posts and telecommunications]:http://mirrors.njupt.edu.cn/

[Neusoft Information Institute open source mirror station]:http://mirrors.neusoft.edu.cn/

[Lanzhou University open source community mirror station]:http://mirror.lzu.edu.cn/