当前位置:网站首页>9. Software package management

9. Software package management

2021-01-23 23:11:54 bestvae

1. Packages and package managers

1.1 Package Introduction

Open source software initially only provided .tar.gz The packaged source code file , The user has to compile everything he wants in the GNU/Linux Software running on . For a more convenient way to manage these software , There is a package management system .

1.1.1 Package manager

Package manager functions :

Package each component file of the compiled application into one or several package files , The package manager can be used to implement the program conveniently and quickly The installation of the package 、 uninstall 、 Inquire about 、 Upgrade and verify etc

Mainstream package managers

  • redhat:rpm file , rpm Package manager
  • debian:deb file , dpkg Package manager
1.1.2 Package name

Source code package file naming :

  • name-VERSION.tar.gz|bz2|xz

  • VERSION: major.minor.release

rpm Package naming :

  • name-VERSION-release.arch.rpm
  • VERSION: major.minor.release

common arch:

  • x86: i386, i486, i586, i686

  • x86_64: x64, x86_64, amd64

  • It's not about the platform :noarch

1) The package file consists of ( Each package is unique )

  • The files in the package
  • Metadata , Such as : The name of the package , edition , Dependence , Description, etc.
  • There may be scripts that run when the package is installed or unloaded

2) database ( public ):/var/lib/rpm

  • Package name and version
  • Dependency relationship
  • Functional specifications
  • File path and check code information generated after package installation
1.1.4 Access to packages

1) System version of the CD or official website

CentOS Mirror image :

https://www.centos.org/download/

http://mirrors.aliyun.com

http://mirrors.sohu.com

http://mirrors.163.com

Ubuntu Mirror image :

http://cdimage.ubuntu.com/releases/

http://releases.ubuntu.com

2) Third party organizations provide

https://fedoraproject.org/wiki/EPEL

https://mirrors.aliyun.com/epel/?spm=a2c6h.13651104.0.0.3bc47dfaZpesAr

http://www.elrepo.org

3) Software project official site

http://yum.mariadb.org/10.4/centos8-amd64/rpms/

http://repo.mysql.com/yum/mysql-8.0-community/el/8/x86_64/

4) Search engine

http://pkgs.org

http://rpmfind.net

http://rpm.pbone.net

https://sourceforge.net/

5) Self made

Put the source code file , utilize an instrument , Such as :rpmbuild,fpm And so on rpm Package file

2. Package manager rpm

2.1 install

Format :

rpm {-i|--install} [install-options] PACKAGE_FILE ...

Options :

  • -v Print details
  • -h Show installation progress

Installation options 【install-options】

  • --test: Test installation , But don't actually perform the installation , namely dry run Pattern
  • --nodeps: Ignore dependencies
  • --nosignature: Do not check the legitimacy of the source
  • --nodigest: Do not check package integrity
  • --noscripts: Do not execute package scripts

Be careful : because rpm Most of the command installation packages will cause package dependency problems , So I don't use rpm Installation package

2.2 Upgrades and demotions

Format :

 upgrade 
rpm {-U|--upgrade} [install-options] PACKAGE_FILE...
rpm {-F|--freshen} [install-options] PACKAGE_FILE...
#upgrade: There are old packages installed , be “ upgrade ”, If there are no older packages , be “ install ”
#freshen: There are old packages installed , be “ upgrade ”,  If there are no older packages , The upgrade operation is not performed 

 Downgrade 
rpm {--oldpackage} [install-options] PACKAGE_FILE...

Be careful :1. Don't upgrade the kernel ;Linux Multiple kernel versions are supported , So install the new kernel directly

​ 2. If the configuration file of the original package has been modified after installation , Upgrade time , The same configuration file provided by the new version will not directly cover the old one edition Configuration file for , And rename the new version of the file (FILENAME.rpmnew) Keep it later

3.3 Packet query

Format :

rpm {-q|--query} [select-options] [query-options]

【select-options】

  • -a: All bags
  • -f: See which package installation generated the specified file
  • -p rpmfile: Query the package files that have not been installed

【query-options】

  • --changelog: Inquire about rpm Bag changelog
  • -c: Query the configuration file of the program
  • -d: Query program documentation
  • -i:information
  • -l: View all files generated after installation of the specified package
  • --scripts: The script that comes with the package

and CAPABILITY relevant

  • --whatprovides CAPABILITY: query-specified CAPABILITY Which package provides
  • --whatrequires CAPABILITY: query-specified CAPABILITY Depends on which package
  • --provides: Lists the CAPABILITY
  • -R: Query the specified package depends on CAPABILITY

Example :

[root@centos8 data]# rpm -qf /etc/skel/.bashrc 
bash-4.4.19-10.el8.x86_64

[root@centos8 data]# rpm -ql tree
/usr/bin/tree
/usr/lib/.build-id
/usr/lib/.build-id/d8
/usr/lib/.build-id/d8/6d516d7cb07fb9334cb268af808119e33a5ac5
/usr/share/doc/tree
/usr/share/doc/tree/LICENSE
/usr/share/doc/tree/README
/usr/share/man/man1/tree.1.gz

[root@centos8 data]# rpm -qd tree
/usr/share/doc/tree/LICENSE
/usr/share/doc/tree/README
/usr/share/man/man1/tree.1.gz

[root@centos8 data]# rpm -q --scripts bash
postinstall scriptlet (using <lua>):
nl        = '\n'
sh        = '/bin/sh'..nl
...

[root@centos8 data]# rpm -q --whatrequires tree
no package requires tree

3.4 Package uninstall

Format :

rpm {-e|--erase} [--allmatches] [--nodeps] [--noscripts] [--notriggers] [--test]
PACKAGE_NAME ...

Be careful : When the package is unloaded , The corresponding configuration file will not be deleted , With FILENAME.rpmsave Form reservation

Example : force delete rpm package , And restore

[root@centos7 ~]#rpm -e rpm --nodeps
# Restart access rescue Pattern 
#mkdir /mnt/cdrom
#mount /dev/sr0 /mnt/cdrom
#rpm -ivh /mnt/cdrom/Packages/rpm-4.11.3-40.el7.x86_64.rpm --root=/mnt/sysimage
#reboot

3.5 Packet verification

When installing the package , The system also checks whether the source of the package is legal

Check the steps yourself :

1. Import the required public key 
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# Query whether the key is imported successfully 
rpm -qa “gpg-pubkey*”

2. Check package integrity and signature 
rpm -K|--checksig rpmfile  

Example :

[root@centos8 ~]#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[root@centos8 rpm-gpg]#rpm -K /misc/cd/AppStream/Packages/httpd-2.4.37-
16.module_el8.1.0+256+ae790463.x86_64.rpm
/misc/cd/AppStream/Packages/httpd-2.4.37-
16.module_el8.1.0+256+ae790463.x86_64.rpm: digests signatures OK

[root@centos8 ~]#rpm -qa "gpg-pubkey*"
gpg-pubkey-8483c65d-5ccc5b19

When the software is installed , The metadata of each file in the package will be , Such as : size , jurisdiction , owner , Time, etc. recorded to rpm Related numbers According to the library , It can be used to check whether the files in the package have changed from the original installation

Format :

rpm {-V|--verify} [select-options] [verify-options]

Example :

[root@centos8 data]# vim /etc/issue
[root@centos8 data]# cat /etc/issue
111
\S
Kernel \r on an \m
[root@centos8 data]# rpm -V centos-release 
S.5....T.  c /etc/issue
[root@centos8 data]# vim /etc/issue
[root@centos8 data]# rpm -V centos-release 
.......T.  c /etc/issue

3.yum

3.1 yum working principle

​ First in yum Create... On the server yum repository( Warehouse ), A lot of... Are stored in the warehouse in advance rpm package , And package related Metadata file ( Place in a specific directory repodata Next ), When yum Client side utilization yum/dnf When tools are installed, when packages are installed , automatically download repodata The metadata in , Query whether there are related packages and dependencies in remote data , Automatically find the relevant package from the warehouse and download it install .

yum The repository of servers can exist in many forms :

  • file:// The local path
  • http:// 、https://
  • ftp://

3.2 yum Client configuration

yum Client configuration file :

- /etc/yum.conf         		  # Provide public configuration for all warehouses 
- /etc/yum.repos.d/*.repo:     # Provide configuration files for each warehouse 
-  Help reference : man 5 yum.conf

yum Of repo Variables available in the configuration file :

- $releasever:  At present OS The major version number of the distribution of , Such as :8,7,6
- $arch: CPU framework , Such as :aarch64, i586, i686,x86_64 etc. 
- $basearch: System basic platform ;i386, x86_64
- $contentdir: Presentation directory , such as :centos-8,centos-7
- $YUM0-$YUM9: Custom variable 

Example : The configuration file

[root@centos8 ~]# cat /etc//yum.conf 
[main]
gpgcheck=1										# Check the validity before installing the package 
installonly_limit=3							# Number of packages allowed to be installed at the same time 
clean_requirements_on_remove=True		# Whether to delete unused packages when unloading 
best=True										# Automatically select the latest version when upgrading , Even without package dependencies 
skip_if_unavailable=False					#

[root@centos8 yum.repos.d]# cat /etc/yum.repos.d/CentOS-Base.repo 

[BaseOS]											# Warehouse name 
name=CentOS-$releasever - Base			# Warehouse description 		
# Warehouse path 
baseurl=http://mirrors.cloud.aliyuncs.com/$contentdir/$releasever/BaseOS/$basearch/os/	
gpgcheck=1										# Check the validity before installing the package 
enabled=1										# Enable warehouse 
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial		# Verify file location 

Example : by centos8 Configure two other common sources (epel and Extras Source )

[root@centos8 yum.repos.d]# vim CentOS-epel.repo
[epel]                                                      
name=Extra Packages for Enterprise Linux 8 - $basearch
baseurl=http://mirrors.cloud.aliyuncs.com/epel/8/Everything/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8

[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.cloud.aliyuncs.com/$contentdir/$releasever/extras/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

yum-config-manager command

Used to manage yum The configuration file of the warehouse

Format :

[root@centos8 ~]# yum provides yum-config-manager
Last metadata expiration check: 1:31:04 ago on Thu 21 Jan 2021 10:29:03 AM CST.
yum-utils-4.0.17-5.el8.noarch : Yum-utils CLI compatibility layer
Repo        : BaseOS
Matched from:
Filename    : /usr/bin/yum-config-manager

# Add warehouses 
yum-config-manager --add-repo URL or file
# Disable warehouse 
yum-config-manager --disable “ Warehouse, "
# Enable warehouse 
yum-config-manager --enable “ Warehouse, ” 

3.3 yum command

Format :

yum [options] <command> [<args>...]

Common options :

  • -y # The automatic answer is “yes”
  • -q # silent mode
  • --nogpgcheck # Don't make gpg check
  • --enablerepo=repoidglob # Temporarily enable the repo, Support for wildcards , Such as :”*“
  • --disablerepo=repoidglob # Temporarily disable repo, Use with the above statement , What's put in the back will take effect
3.3.1 Show

Format :

yum repolist [all|enabled|disabled]						# Show warehouse list ,all The inactive warehouses will be listed 
yum list [all | glob_exp1] [glob_exp2] [...]			# Show a list of programs ,all Will list packages that are not installed 

Example :

[root@centos8 ~]# yum repolist 
repo id                                      repo name
AppStream                                    CentOS-8 - AppStream
BaseOS                                       CentOS-8 - Base
data                                         created by dnf config-manager from file:///data
epel                                         Extra Packages for Enterprise Linux 8 - x86_64
extras                                       CentOS-8 - Extras

[root@centos8 ~]# yum repolist all
repo id             repo name                   		status                                   
AppStream           CentOS-8 - AppStream         		enabled                                   
AppStream-source    CentOS-8 - AppStream Sources    	disabled   

[root@centos8 ~]# yum list all tree
Last metadata expiration check: 2:21:49 ago on Thu 21 Jan 2021 10:29:03 AM CST.
Installed Packages
tree.x86_64            1.7.0-15.el8                                                @anaconda
[root@centos8 ~]# yum list all httpd
Last metadata expiration check: 2:22:00 ago on Thu 21 Jan 2021 10:29:03 AM CST.
Available Packages
httpd.x86_64           2.4.37-30.module_el8.3.0+561+97fdbbcc                       AppStrea
3.3.2 Erection sequence

Format :

yum install package1 [package2] [...]
yum reinstall package1 [package2] [...] # reinstall 

Example :

[root@centos8 data]# yum install [url]
							Install a package directly from a URL
[root@centos8 data]# yum -y install tree
...
Installed:
  tree-1.7.0-15.el8.x86_64                                                       
Complete!
3.3.3 Uninstall package

Format :

yum remove | erase package1 [package2] [...]
3.3.4 Upgrades and demotions

Format :

yum update [package1] [package2] [...]
yum downgrade package1 [package2] [...] ( Downgrade )
yum check-update( Check for available upgrades )

Example :

[root@centos7 ~]#yum install samba --disablerepo=updates
[root@centos7 ~]#yum update samba

# Update all software that can be updated 
[root@centos7 ~]# yum update

3.3.5 Inquire about

Format :

# Check out the package information:
yum info [...]  

# View the specified properties ( It could be a file ) By which package :
yum provides | whatprovides feature1 [feature2] [...]

# View the... On which the specified package depends capabilities:
yum deplist package1 [package2] [...]

Example :

# Note that you need to write the full path of the file to find 
[root@centos8 data]# yum provides vsftpd.conf
Last metadata expiration check: 2:51:12 ago on Thu 21 Jan 2021 01:31:05 PM CST.
Error: No Matches found

[root@centos8 data]# yum provides vsftp.conf
Last metadata expiration check: 2:50:03 ago on Thu 21 Jan 2021 01:31:05 PM CST.
Error: No Matches found
[root@centos8 data]# yum provides /etc/vsftpd/vsftpd.conf
Last metadata expiration check: 2:50:58 ago on Thu 21 Jan 2021 01:31:05 PM CST.
vsftpd-3.0.3-32.el8.x86_64 : Very Secure Ftp Daemon
Repo        : AppStream
Matched from:
Filename    : /etc/vsftpd/vsftpd.conf

[root@centos8 data]# yum info tree
Last metadata expiration check: 2:52:35 ago on Thu 21 Jan 2021 01:31:05 PM CST.
Installed Packages
Name         : tree
Version      : 1.7.0
Release      : 15.el8
Architecture : x86_64
Size         : 109 k
Source       : tree-1.7.0-15.el8.src.rpm
Repository   : @System
From repo    : BaseOS
Summary      : File system tree viewer
URL          : 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@centos8 data]# yum deplist httpd
Last metadata expiration check: 2:54:15 ago on Thu 21 Jan 2021 01:31:05 PM CST.
package: httpd-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64
  dependency: /bin/sh
   provider: bash-4.4.19-12.el8.x86_64
  dependency: /etc/mime.types
   provider: mailcap-2.1.48-3.el8.noarch
  dependency: httpd-filesystem
...
3.3.5 Warehouse cache

Format :

# Clear directory /var/cache/yum/ cache 
yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]

# Build cache 
yum makecache

Example :

[root@centos8 data]# du -sh /var/cache/dnf/
41M	/var/cache/dnf/
[root@centos8 data]# yum clean all 
29 files removed
[root@centos8 data]# du -sh /var/cache/dnf/
1.3M	/var/cache/dnf/
[root@centos8 data]# du -sh /var/cache/dnf/
1.3M	/var/cache/dnf/
[root@centos8 data]# yum makecache 
...
Metadata cache created.
[root@centos8 data]# du -sh /var/cache/dnf/
41M	/var/cache/dnf/
3.3.6 see yum history

yum Executing the install / uninstall command will be recorded in the relevant log

#CentOS 7 Previous version logs 
/var/log/yum.log

#CentOS 8  Version log 
/var/log/dnf.rpm.log
/var/log/dnf.log

command

yum history [info|list|packages-list|packages-info|summary|addoninfo|redo|undo|rollback|new|sync|stats]

Example :

[root@centos8 data]# yum history
ID     | Command line                  			| Date and time    | Action(s)      | Altered
-----------------------------------------------------------------------------------------------
    22 | -y install tree                        | 2021-01-21 16:07 | Install        |    1   
    21 | remove tree                            | 2021-01-21 16:07 | Removed        |    1   
    20 | -y install yum-utils.noarch            | 2021-01-21 12:03 | I, U           |   13  
    
[root@centos8 ~]#dnf history undo 22 -y
Removed:
 dnf-utils-4.0.2.2-3.el8.noarch              
Complete!
[root@centos8 ~]#dnf history redo 22 -y
3.3.7 For private use yum Warehouse

Example :

# This example is created in Intranet environment with CD-ROM hanging yum Source 
[root@centos7 os]#mount /data/CentOS-7-x86_64-DVD-2009\(1\).iso /home/centos/7/os/
mount: /dev/loop0  Write protect , Will mount... As read-only 
[root@centos7 os]#ll
 Total usage  696
-rw-r--r--  3 root root     14 10 month  30 05:14 CentOS_BuildTag
drwxr-xr-x  3 root root   2048 10 month  27 00:25 EFI
-rw-rw-r-- 21 root root    227 8 month   30 2017 EULA
-rw-rw-r-- 21 root root  18009 12 month  10 2015 GPL
drwxr-xr-x  3 root root   2048 10 month  27 00:26 images
drwxr-xr-x  2 root root   2048 11 month   3 00:17 isolinux
drwxr-xr-x  2 root root   2048 10 month  27 00:25 LiveOS
drwxr-xr-x  2 root root 673792 11 month   4 19:30 Packages
drwxr-xr-x  2 root root   4096 11 month   4 19:35 repodata
-rw-rw-r-- 21 root root   1690 12 month  10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 21 root root   1690 12 month  10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--  1 root root   2883 11 month   4 19:36 TRANS.TBL

# Configure the warehouse server 
[root@centos7 os]#mv CentOS7-Base-163.repo CentOS7-Base-163.repo.bak
[root@centos7 os]cat Base.repo
[root@centos7 os]#cat /etc/yum.repos.d/Base.repo 
[BaseOS]
name=Centos7 BaseOS
baseurl=file:///home/centos/7/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[root@centos7 os]#yum repolist
 Loaded plug-in :fastestmirror
Loading mirror speeds from cached hostfile
 Source identification                    Source name                        state 
BaseOS                 Centos7 BaseOS             4,070
repolist: 4,070

# install httpd service 
[root@centos7 os]#yum -y install httpd
[root@centos7 os]#service httpd start
Redirecting to /bin/systemctl start  httpd.service
[root@centos7 ~]#cp -a /home/centos/7/os/* /var/www/html/centos/7/

# Here, the warehouse server is built , Modify local repository baseurl
[root@centos7 ~]#cat /etc/yum.repos.d/Base.repo 
[BaseOS]
name=Centos7 BaseOS
baseurl=http://172.16.60.243/centos/7/
[root@centos7 os]#yum repolist
 Loaded plug-in :fastestmirror
Loading mirror speeds from cached hostfile
 Source identification                    Source name                        state 
BaseOS                 Centos7 BaseOS             4,070
repolist: 4,070

# Client configuration yum File test 
[root@localhost yum.repos.d]# yum -y install vim
...
 Installed as a dependency :
  gpm-libs.x86_64 0:1.20.7-6.el7        vim-common.x86_64 2:7.4.629-7.el7        vim-filesystem.x86_64 2:7.4.629-7.el7       
 complete 

Example : download extras Source , Make private yum Source

# Install the download tool 
[root@centos8 ~]# yum -y install yum-utils

# To configure epel Source 
[root@centos8 ~]# cat /etc/yum.repos.d/CentOS-Base.repo
...
[epelOS]
name=CentOS-$releasever - epel
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
baseurl=https://mirrors.aliyun.com/epel/8/Everything/x86_64/
gpgcheck=0
enabled=1

# Use the tool to download rpm Bao He metadata
[root@centos8 ~]# yum reposync --repoid=epelOS --download-metadata -p /data

# Download complete will package and metadata Copy to http in www Under the folder , Configure as before epel The warehouse is fine 

4. Compilation and installation

4.1 c Language source code compilation process

  • ./configure

    (1) Pass parameters through options , Specify installation path 、 Enable features, etc ; The execution will refer to the user's specification and Makefile.in writing Piece generation Makefile

    (2) Check the dependent external environment , Such as dependent packages

  • make according to Makefile file , Will detect the dependent environment , Build the application

  • make install Copy the file to the appropriate path

4.1.1 Get ready

Solve the installation environment and dependencies

  • development tool :make, gcc (c/c++ compiler GNU C Complier)
  • Software dependent dependency packages
4.1.2 Compilation and installation

First step : function configure Script , Generate Makefile file

Get the options it supports

  • ./configure --help
  • --prefix=/PATH: Specify the default installation location , The default is /usr/local/
  • --sysconfdir=/PATH: Configuration file installation location

The second step :make

The third step :make install

4.1.3 Installation complete configuration
  1. The binary program directory is imported into PATH In the environment variables

    Edit the file /etc/profile.d/NAME.sh

  2. Import help book

    edit /etc/man.config|man_db.conf file , Add one MANPATH

Example : Compilation and installation cmatrix

# Get ready : If the system has no dependency, it needs to be installed first 
#gcc make autoconf ncurses-devel 

#1. download cmatrix
https://github.com/abishekvashok/cmatrix/releases

#2. decompression 
[root@centos8 data]# tar -xf cmatrix-v2.0-Butterscotch.tar -C /usr/local/

#3. Configure the installation path 
[root@centos8 /]# cd /usr/local/src/cmatrix/
[root@centos8 cmatrix]#./configure --prefix=/apps/cmatrix

#4. Compile and install 
[root@centos8 cmatrix]#make && make install 

#5. Configuration environment 
[root@centos8 ~]#echo 'PATH=/apps/cmatrix/bin:$PATH' > /etc/profile.d/cmatrix.sh
[root@centos8 ~]#. /etc/profile.d/cmatrix.sh

# Or with soft links 
[root@centos8 ~]#ln -sv /apps/cmatrix/bin/cmatrix /usr/local/bin/

#6. Realization man help 
[root@centos8 ~]#vim /etc/man_db.conf
MANDATORY_MANPATH                       /apps/cmatrix/share/man
[root@centos8 ~]#man cmatrix

版权声明
本文为[bestvae]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/01/20210123231109658H.html

随机推荐