Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux package Management

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Linux package Management

RPM package Foundation

RPM

YUM

Compilation and installation

Overview

Package management on Linux is a necessary skill for us. This paper will analyze the package management of Linux from three perspectives: rpm, yum and source code compilation. First of all, let's take a look at the main content of this article:

-package naming-RPM: package manager installation, uninstallation, upgrade, query, verification, database maintenance-YUM: the configuration file of yum, the front-end program of RPM, the general operation of yum: upgrade, check, uninstall, view, Package group management uses CD as the command line option of the local yum repository yum and available variables in the repo configuration file-compilation, installation, installation, three steps of compilation, installation, and related configuration RPM packages after installation

Before we learn about RPM, we need to know the basics of the rpm package. In general, a binary application consists of binaries, library files, configuration files, and help files, while both the source code and the rpm package have their own naming conventions:

Source code: name-VERSION.tar.gz | bz2 | xz where VERSION: major.minor.release rpm package: name-VERSION-release.arch.rpm, where VERSION: major.minor.release release:release.OS, such as: ash-4.2.46-19.el7.x86_64.rpm, noarch means platform-independent

There are dependencies, even circular dependencies, between packages, which leads to RPM and YUM. The following are the main categories of packages:

Application-VERSION-ARCH.rpm: main package Application-devel-VERSION-ARCH.rpm development subpackage Application-utils-VERSION-ARHC.rpm other subpackages Application-libs-VERSION-ARHC.rpm other subpackages

For library files, there are two common commands and related configuration files

Ldd: view the library files that the binary depends on ldconifg: manage and view the library files loaded on this machine configuration files: / etc/ld.so.conf, / etc/ld.so.conf.d/*.conf cache files: / etc/ld.so.cache

Here is a common rpm package:

RPMrpm-RPM Package Manager

RPM is a package manager, and the main operations for rpm are:

Install: rpm {- I |-- install} [install-options] PACKAGE_FILE... Uninstall: rpm {- e |-- erase} [--allmatches] [--nodeps] [--noscripts] upgrade: rpm {- U |-- upgrade} [install-options] PACKAGE_FILE. Rpm {- F |-- freshen} [install-options] PACKAGE_FILE... Query: rpm {- Q |-- query} [select-options] [query-options] check: rpm {- V |-- verify} [select-options] [verify-options] Database maintenance: rpm {--initdb |-- rebuilddb} / var/lib/rpm

Use the example

Install a rpm package:

[root@centos7] # rpm-ivh tree-1.6.0-10.el7.x86_64.rpm

[install-options]-h: hash marks output progress bar; each # indicates 2% progress;-- test: test installation, check and report dependencies, conflict messages, etc. -- nodeps: ignore dependencies, not recommended-- replacepkgs: reinstall, note that configuration files will not be replaced-- nosignature: do not check package signature information, do not check source validity-- nodigest: do not check package integrity information

Uninstall a rpm package:

[root@centos7 ~] # rpm-e tree [erase-options]-- almatches: uninstall all versions of packages that match the specified name:-- nodeps: ignore dependencies-- test; test uninstall, dry run mode

Query a rpm package:

[root@centos7 ~] # rpm-qi tree

[root@centos7 ~] # rpm-ql tree

[query-options]-FILE: query all installed packages-f FILE: query which package installation generates the specified files;-- chargelog: query the list of all files generated by the rpm package installation -imam murmurinfo: information related to the package, version number, size The package group to which you belong, such as c _ CAPABILITY _ talk _ configfiles: query the configuration file provided by the specified program-- dforce _ talk _ docfiles: query the documents provided by the specified package-- provides: list all the CAPABILITY-R _ moment files provided by the specified package: query the dependencies of the specified package-- scripts: view the script snippets that come with the package

Verify a rpm package:

[root@centos7 ~] # rpm- V tree [root@centos7 ~] # echo $? 0 [root@centos7 ~] # how to get the public key: in CD: RPM-GPG-KEY-CentOS-7 or under this path: ls / etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 obtains and imports the key of the trusted package maker: for CentOS distributions: # rpm-- import / media/cdrom/RPM-GPG-KEY-CentOS-7 Verification: (1) when installing a program signed by this organization Verification will be performed automatically (2) Manual verification: rpm-K PACKAGE_ file [root @ centos7 ~] # rpm-K tree-1.6.0-10.el7.x86_64.rpm tree-1.6.0-10.el7.x86_64.rpm: rsa sha1 (md5) pgp md5 OK [root@centos7 ~] #

About the encryption and decryption problems when making and using rpm packages:

Producer:

1. An one-way encryption algorithm is used to extract the signature of this packet, which is of fixed length.

two。 Encrypt the signature with the private key and append it to the file. The signature of the private key encryption is the digital signature.

Users:

1. Get the public key of the producer to decrypt the signature. If it can be decrypted, it shows that the rpm packet is indeed the corresponding maker, which is the verification of source validity.

two。 The packet is calculated with the same one-way encryption algorithm, and a signature is calculated, and then the signature is compared with the signature of the decrypted digital signature. If the two are the same, its integrity is verified.

[root@centos7 ~] # rpm-ql tree/usr/ bin/tree/usr/share/doc/tree-1.6.0/usr/share/doc/tree-1.6.0/LICENSE/usr/share/doc/tree-1.6.0/README/usr/share/man/man1/tree.1.gz [root@centos7 ~] # echo > > / usr/bin/tree # append a space [root@centos7 ~] # rpm-V tree # to / usr/bin/tree Verify whether the package file changes S.5T. / usr/bin/tree # size after installation MD5 Timestamp has changed [root@centos7 ~] # rpm-K tree-1.6.0-10.el7.x86_64.rpm # verify source validity and package integrity tree-1.6.0-10.el7.x86_64.rpm: rsa sha1 (md5) pgp md5 OK [root@centos7 ~] # check: S file Size differs M Mode differs (includes permissions and file type) 5 digest (formerly MD5 sum) differs D Device major/minor number mismatch L ReadLink (2) path mismatch U User ownership differs G Group ownership differs T mTime differs P caPabilities differ

Upgrade the rpm package:

Rpm-Uvh PACKAGE_FILE...rpm-Fvh PACKAGE_FILE...-U: upgrade or install-F: upgrade-- oldpackage: downgrade;-- force: mandatory upgrade; Note: (1) do not upgrade the kernel; Linux supports the coexistence of multiple kernel versions, so install the new version of the kernel directly (2) if the configuration file of an original package has been modified after installation, when upgrading, the same configuration file provided by the new version of the program will not overwrite the configuration file of the original version, but will be provided after renaming the configuration file of the new version (FILENAME.rpmnew)

Database reconstruction | this function should be used with caution!

Rpm Manager database path: / var/lib/rpm/, related query operations, through the database here

Rpm {--initdb |-- rebuilddb}-- initdb: initialize the database. There is currently no database to initialize to create a new one; currently, sometimes no action is performed;-- rebuilddb: rebuild, whether it currently exists or not, directly recreate the database

Build the rpm database in another directory:

[root@centos7] # rpm-- initdb-- dbpath=/tmp/rpm [root@centos7 ~] # ls / tmp/rpm/Basenames _ _ db.003 Name RequirenameConflictname Dirnames Obsoletename Sha1header__db.001 Group Packages Sigmd5__db.002 Installtid Providename Triggername

Look at the difference after reconstruction.

[root@centos7] # rpm-- rebuilddb-- dbpath=/tmp/rpm [root@centos7] # ls / tmp/rpm/ Basenames Dirnames Installtid Obsoletename Providename Sha1header TriggernameConflictname Group Name Packages Requirename Sigmd5 [root@centos7] #

Summary of rpm commands:

Rpm command to implement program management: install:-ivh,-- nodeps,-- replacepkgs uninstall:-e,-- nodeps upgrade:-Uvh,-Fvh,-- nodeps,-- oldpackge query:-Q,-qa,-qf,-qi,-qd,-qc,-Q-- scripts,-Q-- chagelog,-Q-- provides,-q-- requires check:-V Import GPG key:-- import -K (verify source validity and package integrity)-- nodeigest (do not check integrity during verification)-- nosignature (do not check source validity during verification) package source validity verification and integrity verification: integrity verification: SHA256 source legitimacy verification: RSA query public key: 0 database reconstruction:-- initdb,-- rebuilddbYUM

Rpm brings convenience to our package management, but when installing packages, we cannot automatically resolve the dependencies between packages, for example, if you want to install a package, it may remind you that this package depends on package A, then you need to install package A, but when you install package A, you are prompted to install package B and package C, then you have to install package B and package C again, and then go back to install the package you want to install. Over and over again, for a person who works efficiently, it is simply miserable; as a result, yum has become a gorgeous appearance, yum is a front tool of rpm, its main advantage is that it can automatically resolve the dependency between packages, in addition, yum can also install a package group at one time; it can be seen that yum is based on rpm, and the two complement each other.

The main knowledge points of yum:

The configuration files and variables of the yum client use the CD as the local yum repository with similar functions to rpm to realize the package group management function of yum.

Configuration file for yum client

/ etc/yum.conf: provide common configuration for all warehouses / etc/yum.repos.d/*.repo: provide configuration for warehouse pointing

What is yum's warehouse?

When we install the rpm package with rpm, the rpm package comes from the CD, and there are a small number of rpm packages in the CD's Packets directory; then, for yum, it also needs to point to a "warehouse", otherwise "a clever housewife cannot make bricks without rice", ah, and this "warehouse" can be either local or online.

How to point to the yum repository requires us to configure / etc/yum.repos.d/*.repo. The important point is that the address pointing to the yum repository must be the parent directory of the rpm package metadata file repodata, and the configuration file must be named with the extension .repo, or there will be an error! The configuration file that points to the yum repository is defined as follows:

[repositoryID] name=Some name for this repositorybaseurl=url://path/to/repository/enabled= {1 | 0} gpgcheck= {1 | 0} gpgkey=URLenablegroups= {1 | 0} failovermethod= {roundrobin | priority} defaults to: roundrobin, meaning random selection; cost= defaults to 1000

Reference example:

1 [base] # parent directory of remote yum source 2 name=CentOS 7 3 baseurl= http://10.1.0.1/cobbler/ks_mirror/7/ # repodata 4 gpgcheck=1 # enables integrity and source validity. 0 means to disable 5 gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 6 enabled=0 # to enable this yum source 0 means to disable 7 8 [base_local] # local CD yum source 9 name=Mirros-CentOS 7 10 baseurl= file:///media/cdrom # mount point 11 gpgcheck=1 12 gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 13 ecabled=1

Show warehouse list

[root@centos7 / etc/yum.repos.d] # yum repolist

At this point, we can use yum to implement the corresponding functions of rpm.

Of course, the world martial arts, only fast unbroken, for the creation of yum warehouse, we also have a "quick move"!

Yum-config-manager command:

Common parameters of yum-config-manager:-- add-repo= "parent directory of repodata or mount point of CD"-- disable "warehouse name" disable warehouse-- enable "warehouse name" enable warehouse

Quickly create a network yum repository:

[root@centos7 ~] # yum-config-manager-- add-repo= Loaded plugins: fastestmirror, langpacksadding repo from: [10.1.0.1 cobblerksmirrorial 7 _] name=added from: baseurl=enabled=1 [root@centos7 ~] #

Quickly create a CD yum repository:

[root@centos7] # yum-config-manager-- add-repo= Loaded plugins: fastestmirror, langpacksadding repo from: [media_cdrom_] name=added from: baseurl=enabled=1 [root@centos7 ~] #

Disable the base repository:

[root@centos7] # yum-config-manager-- disable base

This command actually modifies the .repo file and remains in effect after reboot.

Open the base repository:

[root@centos7] # yum-config-manager-- enable base

Disable all yum repositories:

[root@centos7] # yum-config-manager-- disable *

Open all yum repositories:

[root@centos7] # yum-config-manager-- enable *

In addition, the repo configuration script for yum has been written, and the problem is that when we need to run yum's repo configuration file in an environment with both CentOS 7 and CentOS 6, we find that what is suitable for CentOS 7 is not applicable to CentOS 6, and vice versa, so the repo configuration file has its own variables:

Variables available in yum's repo configuration file: $releasever: major version number of the current release of OS $arch: platform, i386 Magi, i486 Magi, i586 Magi, x8613 64, etc. $basearch: basic platform; i386 $YUM0-$YUM9: custom variable example: http://server/centos/$releasever/$basearch/http://server/centos/7/x86_64http://server/centos/6/i384

Make a local yum source

In addition to using CD-ROMs as local yum sources, we can also use third-party rpm packages to personalize local yum sources that we don't need. First, we need to download the required rpm package from a site, and then use the createrepo command in the directory of the downloaded rpm package to make a local yum source.

Log in to the ftp server to download the required rpm package:

[root@centos7 ~] # lftp 10.1.0.1lftp 10.1.0.1 cd pub lftp 10.1.0.1:/pub/Sources/7.x86_64 >! mkdir / testdir/zsh # create / testdir/zsh directory locally in the format! COMMANDlftp 10.1.0.1:/pub/Sources/7.x86_64 > lcd / testdir/zsh # lcd enter the corresponding directory lcd ok, local cwd=/testdir/zshlftp 10.1.0.1:/pub/Sources/7.x86_64 > lpwd # to check whether you have successfully entered the corresponding directory / testdir/zshlftp 10.1.0.1:/pub/Sources/7.x86_64 > mget zsh-5.0.2-7.el7_1.2.x86_64.rpm # to download the rpm package Download only one 2489616 bytes transferred lftp 10.1.0.1:/pub/Sources/7.x86_64 > bye [root@centos7 ~] # cd / testdir/zsh [root@centos7 / testdir/zsh] # ls zsh-5.0.2-7.el7download 1.2.x8664.rpm [root @ centos7 / testdir/zsh] # as a test

About the createrepo command:

Createrepo [options] # directory is required

Create a local yum source:

[root@centos7 / testdir/zsh] # createrepo. # create a local yum source under the current directory

Create a profile:

[root@centos7 / testdir/zsh] # yum-config-manager-- add-repo= Loaded plugins: fastestmirror, langpacksadding repo from: [testdir_zsh] name=added from: baseurl=enabled=1 [root@centos7 / testdir/zsh] #

View:

Verification: installing zsh

[root@centos7 / testdir/zsh] # yum-y install zsh

At this point, our local yum source can be considered a success!

Yum common command line

Display warehouse list: yum repolist [all | enabled | disabled] display package: yum list {available | installed | updates} installation package: yum install package1 [package2] [...] Yum reinstall package1 [package2] [...] (reinstall) upgrade package: yum update [package1] [package2] [...] Yum downgrade package1 [package2] [...] (downgrade) check for available upgrades: yum check-update uninstall package: yum remove | erase package1 [package2] [...] View the package information:yum info [...] See which package the specified feature (which can be a file) is provided by: yum provides | whatprovidesfeature1 [feature2] [...] Clean up the local cache: yum clean [packages | metadata | expire-cache | rpmdb | plugins | all] build cache: yum makecache # cache metadata search: yum search string1 [string2] [...] Use the specified keywords to search for the package name and summary information to view the capabilities: yum deplist package1 [package2] [...] on which the specified package depends. View yum transaction history: yum history yum history info 6 yum history undo 6 # undo operation log of yum command: / var/log/yum.log--nogpgcheck: disable gpgcheck-y: automatically answer "yes"-Q: silent mode-- disablerepo=repoidglob: temporarily disable the repo--enablerepo=repoidglob specified here: temporarily enable the repo--noplugins specified here: disable all plug-ins

Related examples:

[root@centos7 ~] # yum makecache # cache metadata Loaded plugins: fastestmirror Langpackstestdir_zsh | 2.9kB 00:00:00 (1 kB 2): testdir_zsh/other_db | 1.5 kB 00:00:00 (2 stroke 2): testdir_zsh/filelists_db | | 5.7 kB 00:00:00 Loading mirror speeds from cached hostfileMetadata Cache Created [root@centos7 ~] # [root@centos7 ~] # yum history |

[root@centos7 ~] # yum check-update # check for available upgrades [root@centos7 ~] # yum-y update zsh

[root@centos7 ~] # yum deplist zsh to view the capability capabilities on which the specified package depends

[root@centos7 ~] # yum provides zsh # to see which program provides the features of the specified package

Package group management function of yum

Yum groupinstall group1 [group2] [...] yum groupupdate group1 [group2] [...] yum grouplist [hidden] [groupwildcard] [...] yum groupremove group1 [group2] [...] yum groupinfo group1 [...]

The relationship between package and package group, in its structural relationship, is similar to the concept of user and user group, is to facilitate management. The package group management command for yum is similar to the regular installation uninstall upgrade command for yum.

Source code compilation

With rpm and yum, sometimes we can not fully meet our needs, for example, we need to upgrade a program, but the program does not have a corresponding rpm package, or the version of the rpm package is too old, and we only have the source package, so we need to compile and install the program. In addition, yum installs dependencies automatically, it is possible to install a lot of things we do not need, and we do not want to install unnecessary things, at this time, we should also consider compiling and installing. There are three steps to compile and install, but sometimes we also need to deal with the specific software, and we need to read the installation information before compiling.

C code compilation and installation three steps: 1. / configure: (1) pass parameters through options, specify enabling features, installation paths, etc. The execution will refer to the user's specification and the makefile.in file generation makefile (2) check the dependent external environment, such as dependent software package 2, make: build the application according to the makefile file 3, make install: copy the file to the appropriate path development tool: autoconf: generate configure script automake: generate Makefile.in Note: check INSTALL,README before installation

Before compilation, we need to prepare the development environment and development tools, development environment includes: development libraries, header files, glibc, standard libraries; development tools include: make, gcc, etc.; these development components are often provided through the "package group", so we only need to install the corresponding package group on it.

Implementation: provide development component CentOS 6:Development ToolsServer Platform DevelopmentCentOS 7:Development ToolsDevelopment and Creative Workstation through "package group"

During installation,. / configure-help can get the installation options it supports, at the same time, the installation path and the location of the configuration file can be specified manually, the optional features of the software can be selectively disabled, and dependent packages can of course be disabled. This is the personalized compilation installation:

Installation path setting:-- prefix=/PATH: specify the default installation location, default / usr/local/--sysconfdir=/PATH: configuration file installation location System types: support cross-compilation Optional Features: optional feature-- disable-FEATURE--enable-FEATURE [= ARG] Optional Packages: optional package,-- with-PACKAGE [= ARG], dependency package-- without-PACKAGE, disable dependencies

Here is a brief description of the general process of compiling and installing http:

Download httpd-2.2.29.tar.bz2 and decompress it, and enter the directory after decompression

[root@centos7 ~ / httpd-2.2.29] #. / configure-prefix=/usr/local/http2-sysconfdir=/etc/bin/http2

Make

[root@centos7 ~ / httpd-2.2.29] # make

Make install

[root@centos7 ~ / httpd-2.2.29] # make install

At this point, we can go to the installation directory and take a look at:

At this point, our installation process is over, and in order to use the features of the software more efficiently, we still need to "clean up the aftermath" after installation:

Configuration after installation: (1) Import the binary program directory into the PATH environment variable Edit file / etc/profile.d/NAME.shexport PATH=/PATH/TO/BIN:$PATH (2) Import library file path edit / etc/ld.so.conf.d/NAME.conf add new library file to this file to let the system regenerate the cache: ldconfig [- v] (3) Import header file based on link: ln-sv (4) Import help manual edit / etc/man.config | add a MANPATH to the man_db.conf file

Import the binary program directory into the PATH environment variable

Vim http2.shexport PATH=$PATH:/usr/local/http2

Import library file path

Vim http2.conf/usr/local/http2/lib [root@centos7 ~] # ldconfig # regenerate cache [root@centos7 ~] #

Import header file

[root@centos7 / usr/local/http2/include] # ln-sv / usr/local/http2/include / usr/include/http2.h

Import help manual

Now let's try using man help:

Apachectl-Apache HTTP Server Control Interfacestartstop restart

Now try to start http:

[root@centos7 ~] # apachectl start

Check to see if port 80 is open:

[root@centos7 ~] # netstat-ant

OK, let's take a look at the web page:

[root@centos7 ~] # links # this command is not installed directly on yum

Check the browser again (this step is not necessary)

At this point, the trial of source code compilation and installation is over!

In this paper, we mainly introduce the general command operation of rpm, the configuration file of yum and the creation of network yum source, the use of CD as Yum source, the creation of local yum source and its routine operation. Finally, we briefly introduce the three steps of compiling and installing the source code. In fact, make and make install can be executed together, that is, make & make install. This is the main content of our package management!

Stop the war

2016.8.26

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report