YUM online upgrade function

YUM online upgrade function

YUM is a software installation management tool. Its function is to help users automatically deal with dependency attribute problems that may be encountered when installing, upgrading, and deleting software. YUM can analyze the header data of software packages to understand the dependencies between software, and then create attribute dependency solutions to ensure that there will be no problems with software installation, upgrade, and deletion. In this way, users can conveniently manage various software without having to manually resolve dependency issues.

Although YUM is a convenient software installation and management tool, to use its functions, you need to find a server suitable for YUM, that issoftware source. Each YUM server may offer many different software features. CentOS has created multiple mirror sites to provide software updates around the world. Therefore, as long as you can connect to the Internet, you can theoretically use YUM without processing any setting values.

Use YUM for query, installation, upgrade and deletion functions

Query function

yum [ list | search | providers | whatprovides ] 参数

If you want to use yum to query the software provided by the original Linux distribution or the name of some known software, and want to know the function of the software, you can use yum related parameters:

yum [option] [查询工作选项] [相关参数]
选项:
 [option] 主要的选项包括有:
 -y      :当yum要等待使用者输入时,这个选项可以自动提供 yes 的回应。
 --installroot=/some/path:将该软件安装在 /some/path 而不使用默认路径
 [查询工作选项] [相关参数] 这方面的参数有:
 search  :查找某个软件名称或是描述的重要关键字
 list    :列出目前 yum 所管理的所有的软件与版本,有点类似 rpm -qa
 info    :同上,不过有点类似rpm -qai的执行结果
 provides:从文件去查找软件,类似 rpm -qf 的功能

Use Cases

What are the software related to finding disk array (raid)?

[root@localhost ~]# yum search raid
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile    # 找出速度最快的那一台yum服务器
 * base: mirrors.aliyun.com                   # 下面三个软件源,且来源为该服务器
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.jlu.edu.cn
=================================== N/S matched: raid ===================================
dmraid.i686 : dmraid (Device-mapper RAID tool and library)
dmraid.x86_64 : dmraid (Device-mapper RAID tool and library)
dmraid-devel.x86_64 : Development libraries and headers for dmraid.
dmraid-events-logwatch.x86_64 : dmraid logwatch-based email reporting
......
......
# 在冒号(:)左边的是软件名称,右边则是在 RPM内的name设置(软件名)

Find out what the function of mdadm software is

[root@localhost ~]# yum info mdadm
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.jlu.edu.cn
Available Packages
Name        : mdadm    #这个软件的名称
Arch        : x86_64   #这个软件的硬件架构
Version     : 4.1      #此软件的版本
Release     : 9.el7_9  #发布的版本
Size        : 439 k    #此软件的文件总容量
Repo        : updates/7/x86_64  #软件源的安装状态
Summary     : The mdadm program controls Linux md devices (software RAID arrays)
URL         : http://www.kernel.org/pub/linux/utils/raid/mdadm/
License     : GPLv2+
Description : The mdadm program is used to create, manage, and monitor Linux MD (software
            : RAID) devices.  As such, it provides similar functionality to the raidtools
            : package.  However, mdadm is a single program, and it can perform
            : almost all functions without a configuration file, though a configuration
            : file can be used to help with some common tasks.

List all software names provided on the YUM server

[root@localhost ~]# yum list
....
.....
......
zziplib-devel.x86_64            0.13.62-12.el7                      base     
zziplib-utils.x86_64            0.13.62-12.el7                      base     
# 【软件名称  版本  在那个软件源内】

What software lists the passwd command?

[root@localhost ~]# yum provides passwd
....
....
passwd-0.79-6.el7.x86_64 : An utility for setting or changing passwords using PAM
Repo        : base

passwd-0.79-6.el7.x86_64 : An utility for setting or changing passwords using PAM
Repo        : @anaconda
# 就上面的软件提供了passwd这个命令

Use the function of yum to find out which software starts with pam? And which ones have not been installed yet?

[root@localhost ~]# yum list pam*
pam.x86_64          1.1.8-23.el7                         @base  
Available Packages      # 下面则是【可升级】或【未安装】的
pam.i686            1.1.8-23.el7                         base   
pam-devel.i686      1.1.8-23.el7                         base   
pam-devel.x86_64    1.1.8-23.el7                         base   
pam-kwallet.x86_64  5.5.2-1.el7                          epel 
.....
....

Install/upgrade functionality

yum [option] [安装与升级的工作选项] [相关参数]
选项:
 install :后面接要安装的软件
 update  :后面接要升级的软件,若要整个系统都要升级,就直接 update 即可

Install the uninstalled pam-devel found in the previous exercise

[root@localhost ~]# yum install -y pam-devel
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                              | 6.8 kB  00:00:00     
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.jlu.edu.cn
Resolving Dependencies   # 接下来先处理【属性依赖】的软件问题
--> Running transaction check
---> Package pam-devel.x86_64 0:1.1.8-23.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved
# 由上面的检查发现到pam整个软件也需要同步升级,这样才能够安装新版 pam-devel
# 至于下面则是一个总结的表格显示
=========================================================================================
 Package              Arch              Version                    Repository       Size
=========================================================================================
Installing:
 pam-devel            x86_64            1.1.8-23.el7               base            185 k

Transaction Summary
=========================================================================================
Install  1 Package         

Total download size: 185 k   
Installed size: 528 k      
Downloading packages:
pam-devel-1.1.8-23.el7.x86_64.rpm                                 | 185 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pam-devel-1.1.8-23.el7.x86_64                                         1/1 
  Verifying  : pam-devel-1.1.8-23.el7.x86_64                                         1/1 

Installed:
  pam-devel.x86_64 0:1.1.8-23.el7                                                        

Complete!

Delete function

yum [remove] software

[root@localhost ~]# yum remove pam-devel
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Resolving Dependencies     # 先解决依赖性问题
--> Running transaction check
---> Package pam-devel.x86_64 0:1.1.8-23.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================
 Package              Arch              Version                   Repository        Size
=========================================================================================
Removing:
 pam-devel            x86_64            1.1.8-23.el7              @base            528 k

Transaction Summary
=========================================================================================
Remove  1 Package   # 没用依赖性问题只删除了一个软件

Installed size: 528 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : pam-devel-1.1.8-23.el7.x86_64                                         1/1 
  Verifying  : pam-devel-1.1.8-23.el7.x86_64                                         1/1 

Removed:
  pam-devel.x86_64 0:1.1.8-23.el7                                                        

Complete!

YUM configuration file

Although yum can be used directly if your host can connect to the Internet, the CentOS mirror station may choose to be far away from us. For example, we are in Yunnan, but the CentOS mirror station chooses to be in Beijing, so the connection The speed to Beijing will be very slow. In order to solve this problem, we can manually modify the yum configuration file and set the mirror station to a location closer to us, which can speed up software downloads and updates.

Open source mirror site

Alibaba Cloud open source mirror site: https://mirrors.aliyun.com/

Netease open source mirror station: https://mirrors.163.com/

University of Science and Technology of China open source mirror site: https://mirrors.ustc.edu.cn/

Tsinghua Open Source Mirror Station: https://mirrors.tuna.tsinghua.edu.cn/

If you connect to the above URL, you will find a bunch of links inside, and those links are the software sources provided by this yum server. Therefore, the high-speed network center also provides software sources such as centosplus, cloud, extras, fasttrack, os, updates, etc. The most recognized software sources are os (system default software) and updates (software upgrade version)

image-20230531210556003

When using YUM to install software, the most important thing is to find the address of the software source so that you can download the required software. The most important part of the software source is the repodata directory, which stores the software attribute dependency data generated after analyzing the RPM software. In other words, when you find a software source address, you must make sure there is a directory named [repodata] under the address, so that you can use YUM to install the software correctly.

image-20230531210618277

Now let me modify the configuration file

[root@localhost ~]# vim /etc/yum.repos.d/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

CentOS-Base.repo has a lot of content. It only lists the software source content of base. You can check other software source contents by yourself.

  • [base]: Represents the name of the software source. The square brackets must exist, and the name inside can be chosen at will. But there can’t be two that can’t change the same software source name, otherwise yum will not know where to find the list of software related to the software source
  • name: Just to explain the significance of this software source, it is not of high importance.
  • mirrorlist=: List the mirror sites that can be used for this software source. If you don’t want to use it, you can comment out this line.
  • baseurl: This is the most important, because what follows is the actual address of the software source. The mirrorlist is fetched by the YUM program to identify the mirror site. The baseurl specifies a fixed software source address. Put the URL we just found here (note the path )
  • enable=1: It is to enable this software source, if you don’t want to start it, you can use enable=0
  • gpgcheck=1:Remember RPM digital signature? This is to specify whether to view the digital signature in the RPM file
  • gpgkey=: It is the location of the public key file of the digital signature, and the default value is fine.

After understanding the configuration, let us modify the entire file content and use the resources of the University of Science and Technology of China mirror site. The modification method only lists the base software source. Other projects can be processed in this way.

[root@localhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.ustc.edu.cn/centos/7.9.2009/updates/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.ustc.edu.cn/centos/7.9.2009/extras/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# 默认情况下,软件源仅有这三个启用,所以这里仅修改这三个软件源的baseurl而已。

Then you will definitely say that the configuration is troublesome. Is there an easier way? Yes, directly use the officially produced repo file

Use wget to download, wget is a network download tool

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#-O参数指定要将下载的文件输出至指定路径
#/etc/yum.repos.d/CentOS-Base.repo是指定输出路径
# https://mirrors.aliyun.com/repo/Centos-7.repo是要下载的文件的URL地址。
# 执行该命令后,系统将会使用阿里云提供的软件仓库来更新和安装软件包

The next step is to test whether these software sources are running normally.

[root@localhost ~]# yum repolist all

image-20230531213010593

It is enabled by writing enabled on the far right. Since /etc/yum.repos.d/ has multiple configuration files, you will find that there are other software sources.

Problems arising from modifying software source and solutions

If we want to modify the YUM configuration file so that it uses a specific mirror site instead of the software source provided by other software developers, we need to create a .repo file in the /etc/yum.repos.d/ directory, which Is a specific configuration file format. But it should be noted that different software sources may have old and new versions, and YUM will download the list of software sources in the local /var/cache/yum directory. If we modify the URL of the mirror site but do not modify the software source name (the file in brackets), it may cause the local list to be out of sync with the YUM server list, making it impossible to update the software. The solution is very simple, you only need to clear the old local data.

yum clean [ packages | headers |all ]
选项:
packages:将已下载的安装文件删除
headers :将下载的安装文件头删除
all     :将所有软件源数据都删除

Use Cases

Delete related data of all downloaded software sources (including the software itself and the manifest)

[root@localhost ~]# yum clean all

YUM’s software group function

It is very simple to install a software online through yum, but what if you want to install a large software? For example, I installed the test machine using the default installation method. This host only has the GNOME window manager. So what if I want to install KDE? Do I need to reinstall it? Of course not, you can use the software group function of yum

yum [群组功能] [软件群组]
选项:
 grouplist   :列出所有可使用的【软件群组组】,例如 Development Tools之类
 groupinfo   :后面接group name,则可了解该group内含的所有软件名
 groupinstall:这个很好用,可以按照一整组的软件群组,相当的不错

Use Cases

Check the current software source and the available and installed software groups on this machine.

[root@localhost ~]# yum grouplist
Available Environment Groups:   #还可以安装的系统环境软件群组
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Cinnamon Desktop
   MATE Desktop
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:               # 还能额外安装的软件群组
   Cinnamon
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Educational Software
   Electronic Lab
   Fedora Packager
   General Purpose Desktop
   Graphical Administration Tools
   Haskell
   LXQt Desktop
   Legacy UNIX Compatibility
   MATE
   Milkymist
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
   TurboGears application framework
   Xfce
Done

Most of the software on the system is provided for installation in groups, just like a package, including many related software, which work together to complete some specific functions. For example, GNOME, KDE, X Windows, etc. These names are actually the names of software groups, which include a series of related software. After installing these software groups, you can use these software to complete some specific functions. When installing CentOS, we can choose the software group to be installed, or choose a single software to install. If you execute the above command, you should see a [Scientific Support] software group under [Available Groups]. You can use the following command to view the details.

[root@localhost ~]# yum groupinfo "Scientific Support"
Group: Scientific Support
 Group-Id: scientific
 Description: Tools for mathematical and scientific computations, and parallel computing.  # 这句话的意思是用于数学和科学计算以及并行计算的工具。
 Optional Packages:
   Macaulay2
   atlas
   fftw
   fftw-devel
   fftw-static
   gnuplot
   gromacs
   gromacs-mpi
   gsl-devel
   hdf
   hdf5
   jmol
   lapack
   maxima
   .....
   .....
   .....

Let’s install it and see

[root@localhost ~]# yum groupinstall "Scientific Support"

The software in Scientific Support is all "optional" rather than "mandatory", so by default, none of the above software will be installed for you. If you want to install the above software, you can use [yum install fftw] to install it one by one. What if you want groupinstall to install all optional software by default? Then you have to modify the configuration file and change the software options selected by groupinstall, as shown below

distroverpkg=centos-release     # 找到这一行添加如下内容
group_package_types=default,mandatory,optional
# default:表示安装软件包群组时,同时安装默认类型的软件包;
# mandatory:表示安装软件包群组时,同时安装必须的软件包,如果不安装这些软件包,软件包群组将无法正常工作;
# optional:表示安装软件包群组时,同时安装可选的软件包,这些软件包并不是必须的,但是可以提供额外的功能。

Through settings group_package_types=default,mandatory,optional, yum will install the default type, required type and optional type of software packages at the same time when installing the software package group. This can ensure that the software package group can work properly and provide additional functions.

Then execute the install command again /

[root@localhost ~]# yum groupinstall "Scientific Support"
# 你就会发现有一大堆软件的安装。

System-wide automatic upgrade

We can manually choose whether we need to upgrade, but can we let the system automatically upgrade to keep our system up to date at all times? Yes, you can use [yum update -y] to automatically upgrade, and then use the crontab function to handle it.

Suppose I have better network bandwidth at 3:00am every day, which is suitable for upgrade.

# 使用命令crontab -e打开定时任务编辑器。在编辑器中添加如下行
0 3 * * * /usr/bin/yum update -y
# 表示在每天的凌晨3:00执行yum update -y命令进行自动升级操作。 

With the above settings, the system will automatically execute the yum update -y command at 3:00 a.m. every day for automatic upgrade operations.

Management Choice: RPM or Tarball

If I want to upgrade or completely install a new software, should I choose RPM or Tarball for installation?

Prioritize the original RPM function

In Linux systems, software management is usually performed using RPM (Red Hat Package Manager). RPM is a software package manager that makes it easy to install, upgrade, and uninstall software. In addition, RPM also has high security characteristics because it provides digital signature and verification functions to ensure the security of the software.

By using RPM, software can be automatically upgraded and maintained, and the original manufacturer will continue to maintain software updates, so the system can be kept in the latest state, improving system security. In addition, RPM can also be used to easily query and verify software packages, making software management easier and more comfortable.

For example, each version of RHEL and Centos provides a maintenance period of at least five years, which means that the software of these systems will continue to be updated and maintained to ensure the stability and security of the system. At the same time, yum, as a tool of RPM, can also automatically upgrade software packages, improving the security and stability of the system.

Therefore, in Linux systems, using RPM to manage software is the preferred way, because it has the advantages of high security, easy management and maintenance, and can ensure the stability and security of the system.

Select the RPM released by the software official website or the software source address provided

Although the original manufacturer provides a lot of software and updates, it is not possible to include all software and functions. For example, CentOS does not provide NTFS-related driver modules. If you need to install these special software, you need to find the software source and install it yourself.

You can install special software by checking the official website to see if the relevant RPM files are provided. If the software source URL has been provided, you can download the YUM configuration file of the software source and add it to the system to easily install and upgrade the software automatically.

Therefore, when using RPM to manage software, you also need to note that the software provided by the original manufacturer is not omnipotent. There may be some special software that you need to find the software source to install.

Install Special Software Using Tarballs

Some special-purpose software may not provide RPM files for installation. Although you can make SRPM and convert it to RPM for installation, this has no practical significance when there is only one host.

If you want to manage the same multiple hosts, making RPM files becomes very valuable, because you can easily install and upgrade on multiple hosts. However, if it is only a stand-alone version of special software, such as MPICH, PVM and other parallel computing function libraries commonly used in academic networks, it is recommended to use Tarball to install it. There is no need to specifically find RPM for installation.

Therefore, when using RPM to manage software, it is also necessary to note that for some special-purpose software, there may not be an RPM file for installation. In this case, you can use Tarball and other methods to install without having to specifically create an RPM file.

Test new versions of software using Tarball

Sometimes we need to use new versions of certain software, but the original manufacturer only provides older versions of the software. In this case, you can use Tarball to install new software to the /usr/local/ directory, so that two versions of the software can be installed on the system at the same time. Most software installs multiple versions without interfering with each other and can be used to test new software.

However, when using multiple versions of software, you need to pay attention to whether the command used is the new version of the software or the old version of the software. You can specify which version of the software to use by prefixing the command with the complete path, such as /usr/local/bin/xxx. You can also set which version of the software to use by default by modifying environment variables.

It should be noted that using new versions of software may cause problems, so you should back up the original software before installing the new version so that you can restore it when you need to go back to the original software.

Summarize

RPM and Tarball each have their own advantages and disadvantages, and you need to choose the appropriate method for installation according to the specific situation.

For software that already provides RPM files, using RPM for installation can easily manage and upgrade the software. Moreover, RPM can solve dependency problems and automatically install related dependent software packages. Therefore, if there is an RPM file, give priority to using RPM for installation.

However, for some software, the RPM file may not be provided, or the architecture of the software is too different, or the dependency attribute problem cannot be solved, so it may be more convenient to use Tarball to install it. By using Tarball installation, you can avoid dependency problems, and you can also easily install new versions of software.

Therefore, when choosing to use RPM or Tarball for software installation, you need to choose based on the specific situation, weigh the advantages and disadvantages of each, and choose the most appropriate method for installation.

Basic service case: Take APache as an example

By default, you do not need to modify the service configuration file, your service can be processed through the system default values. There is a tacit secret formula that you can memorize so that you won’t be embarrassed when handling services.

  1. Install: yum install (your software)
  2. start up:systemctl start (your software)
  3. boot: systemctl enable (your software)
  4. firewall:firewall-cmd --add-service="(your service)"; firewall-cmd --permanent --add-service="(your service)"
  5. test: Use software to check whether your service is normal or not

Let's do an experiment

  1. Install required software
[root@localhost ~]# yum install -y httpd php mariadb-server php-mysql
  1. Start up and start up, these two steps must be carried out.
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 四 2023-06-01 14:40:15 CST; 10s ago
     Docs: man:httpd(8)
  1. firewall
[root@localhost ~]# firewall-cmd --add-service="http"
success
[root@localhost ~]# firewall-cmd --permanent --add-service="http"
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens34
  sources: 
  services: dhcpv6-client http ssh      #这个启动才是重点
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
  1. test

In the final test, enter the browser and enter your IP address in the URL, and the following interface will appear, which means success. Your Linux is already a web server

image-20230601144455399

Guess you like

Origin blog.csdn.net/qq_52089863/article/details/130988097