In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Part one: the process of program compilation
I. introduction of the software running environment
The operating system kernel, libraries and programs are all binary files. Whether the application program can run across platforms depends on whether the calling binary library files that the program depends on are compatible. The development perspective API:Application Program Interface application program interface, the programmer faces the programming interface. Interface between application system and operating system
Application perspective ABI:Application Binary Interface applies the binary interface, the program application faces the interface of the running program, and the interface between the application and the calling library.
Linux:ELF (Executable and Linkable Format)
Windows:PE (Portable Executable)
Solution: unified application development call library interface standard, that is: unified API standard, POSIX standard: Portable Operating System portable operating system. The application code that follows this standard can be installed and used only by recompiling under the operating system platform of the application. The standard is still a compatibility solution at the API level.
II. Software compilation process
after we get the source code package of the application, we cannot run it directly on the operating system platform. We need to compile it to support ABI in different operating systems in order to run on different operating system platforms.
Program source code-- > preprocessing-- > compilation-- > assembly-- > link
1. Preprocessing: format the source code according to the preprocessing instructions in the program source code and output the file ending with .i in preparation for compilation
two。 Compile: compile the preprocessed file, generate the assembly file, and generate the .s file based on the precompiled instructions in the .i file, in which the assembly code is saved.
3. Assembler: compiles the assembly file, generates the object file, converts the assembly code in the .s file generated by the compilation process into binary machine code, and finally outputs it to a .o file.
4. Link: link the target file, generate the executable file, package the binary file generated by assembly and the library file link called by the program to generate the execution file, the link is divided into two kinds, so the compilation is divided into two kinds: one is static compilation, the other is dynamic compilation.
Static compilation: the third-party library files called by the program are found together to generate executable files, which is characterized in that the dependent third-party library files are released and installed together during installation to solve the problem that the target operating system platform fails to run because there are no dependent library files. However, the executable programs generated by static links are large and need to be recompiled if the program is updated. Static library suffix is .a file dynamic compilation: just make a link to the third-party library file called by the program, and do not really package the dependent library file in the executable file, but do a dynamic link. It is OK to call the library in the target operating system while the target system program is running, but it will fail if there is no dependent library. The dynamic library is a .so file
5.GCC compilation process
Preprocessing: generate precompiled files (. File): gcc-E hello.c-o hello.i (preprocess the hello.c file to generate the hello.i file) compile: generate assembly code (.s file): gcc-S hello.i-o hello.s (compile the preprocessing file to generate the assembly file) assemble: generate the object file (.o file): gcc-c hello.s-o hello.o (compile the assembly file Generated target file) link: generate executable file: gcc hello.o-o hello (link the target file to generate the executable file)
III. Introduction of application programs in Linux system
The program installed in the system stores information in two parts, one is the metadata information of the program, and the other is the application data.
1. Program metadata:
The rpm package information (name, version, dependency, description, etc.) installed in the system is registered in the rpm database. Each installation of the rpm package will query whether the database program already exists, and if so, the rpm package manager will feedback different information. The database is located at / var/lib/rpm
A description of the package name and version, dependency, and function.
File paths and check code information generated after the installation of the ZIP package
There is a problem with the rpm system and cannot be installed and queried. There may be a problem with the database. You can use the following command to rebuild
Rpm-- initdb: if there is no database in advance, a new one will be created. If the database already exists, nothing will be done. Rpm-rebuilddb: rebuild the database and overwrite the original database.
two。 Application data:
application data is the program file that we really use that can be requested to the operating system as a process.
3. Library files:
Many applications under Linux are dynamically compiled and generated, so many programs rely on the basic library files provided by the system, and there are dependencies among many applications, which provides the system with efficient and standardized handling of these dependencies. All available library file names and file path mappings are stored in specified locations in the form of modular configuration files. The command interface for querying the dependency relationship between the application and the library file is provided to the user, as follows:
Configuration file location: / etc/ld.so.conf / etc/ld.so.conf.d/*.conf 0.cache file location: / etc/ld.so.cache 0.ldd command: view the library files that the binary depends on: ldd / usr/bin/cat @ manage and view the library text ldconfig-p specified in the local loaded library file ldconfig loading configuration file shows all available library file names and file path mapping relationships that have been cached on this machine
Introduction to 4.rpm package
1.rpm package name package name-[functional remarks]-major version number. The second edition number. Revision number-number of compilations-release number customized by the distributor-hardware architecture platform .rpm functional remarks: tools toolkit, devel development package, libs library, utils functional package, major version number: there are large changes in functional modules or architectures. Version number: functional module enhancements: bug repair 2. Rpm package structure: the metadata of the program file in the RPM package, such as the name A script that runs when installing or uninstalling versions, dependencies, descriptions, etc. (used to customize configuration files, such as creating users, etc.)
Part II: package management
The rpm package management tool packages one or more package files from each component file of the compiled application, thus easily and quickly realizing the management operations such as installation, uninstallation, query, upgrade and verification of the package.
I. introduction to the rpm option
There are many options for rpm package management tools, so here's a summary of the matching relationships between the options in rpm's man manual. We can divide the options of rpm into three levels to understand memory. The first level is the package management options required on the command line, the second level is the optional functional fine-tuning options, and the third level is auxiliary general options:-v displays details and-h shows processing progress.
1. Required options for first-level package management class:
-I installation,-e uninstall,-U-F upgrade,-V check,-Q query
Query and verification operations can be matched with [select-options] package installation and upgrade operations can be matched with [install-options] package uninstall operations, but the options are confusing. We just need to remember-e.
two。 Optional options for secondary functional fine tuning:
Installation options, query options, verification options, selection options. For more information, see the appendix to the fine-tuning options at the end of the article.
3. The collocation relationship of primary and secondary options:
1. Package query operation: match the selection or query option rpm {- Q |-- query} [select-options] [query-options] 2. Package check operation: match the option or check option rpm {- V |-- verify} [select-options] [verify-options] 3. Package installation operation: with the installation option rpm {- I |-- install} [install-options] PACKAGE_FILE … 4. Package reinstallation: with the installation option rpm {--reinstall} [install-options] PACKAGE_FILE. 5. Package upgrade operation: with the installation option rpm {- U |-- upgrade} [install-options] PACKAGE_FILE … Rpm {- F |-- freshen} [install-options] PACKAGE_FILE. 6. Package uninstall operation: rpm {- e |-- erase} [--allmatches] [--justdb] [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME...
4. General options: both uninstall and installation apply
General options can assist first-level options such as installation and uninstallation to show the process of rpm in more detail.
ZR-v verbose displays details, which can be superimposed by multiple v, showing different levels of detail, and showing the processing progress of the package manager.
II. Package management operation
1. Package installation
Program installation process:
Z. execute pre-installation script files, such as creating users, creating necessary directories, and unpacking permissions to copy various files to the appropriate directory. After installation, the 0.rpm package is automatically registered in the RPM public database / var/lib/rpm to facilitate later uninstallation and query operations.
Syntax:
Rpm {- I |-- install} [install-options] PACKAGE_FILE...
-- test: test the installation, but do not actually perform the installation, that is, dry run mode-- nodeps: ignore dependencies and force the package-- force forced installation-- replacepkgs | replacefiles replacement package or file for use. Replace the original package and overwrite the installation. -- nosignature: do not check source validity-- nodigest: do not check package integrity-- noscripts: do not execute package script% pre: pre-installation script-- nopre% post: post-installation script-- nopost% preun: pre-uninstall script-- nopreun% postun: post-uninstall script-- nopostun
Common option combination
Replacepkgs overwrite the original package: modify rpm-ivh tree-1.7.0-15.el8.x86_64.rpm-- reinstall failed due to erroneous deletion of the package file-- overwrite the original file: rpm-ivh tree-1.7.0-15.el8.x86_64.rpm-- replacefiles «skip package signature verification rpm-ivh tree-1.7.0-15.el8.x86_64.rpm-- nosignature
Practical tips
Determine whether a package exists, and if not, install the corresponding package rpm-Q tree > / dev/null | | rpm-ivh. /.. / BaseOS/Packages/tree-1.7.0-15.el8.x86_64.rpm
two。 Package uninstall
Syntax:
Rpm {- e |-- erase} [--allmatches] [--justdb] [--nodeps] [--noscripts]
Uninstall-- allmatches unloads all matching packages, and all packages that match the specified keywords uninstall-- justdb-- nodeps ignores dependencies and forcefully uninstalls-- noscripts does not execute the uninstall script during the uninstall process.
Tip: when the package is uninstalled, the corresponding configuration file will not be deleted, and the http.conf file such as httpd will be retained in FILENAME.rpmsave form.
3. Package upgrade
Syntax:
Upgrade: if a legacy package is installed, "upgrade" if there is no legacy package, then "install"
Rpm {- U |-- upgrade} [install-options] PACKAGE_FILE...
Freshen: if a legacy package is installed, upgrade will not be performed if the legacy package does not exist
Rpm {- F |-- freshen} [install-options] PACKAGE_FILE...
4. Package degradation
Downgrading is generally used for business test software version switching, or version fallback operation is performed if an exception occurs in business node upgrade. In fact, the old version of the package is installed normally, but the two fine-tuning options-- oldpackage-- force are required at the same time. After the upgrade, the two version packages coexist. You can decide whether to uninstall the new version of the package according to your actual needs.
Rpm-ivh tree-1.6.0-10.el7.x86_64.rpm-oldpackage-force
Tip: if only-- oldpackage will prompt for file conflicts, you need to specify-- replacefiles for file replacement at the same time. At this time, through the rpm-Q query, we will find that the two versions of the software coexist, but the installed application files overwrite the original application files, and the software is indeed degraded successfully. Reason:-I is that the installation operation registers the new software version information with the rpm database. Therefore, the uninstall and query operation needs to add the version number.
5. Package query
Frankly speaking, I think that the query function of the rpm package management tool is used most frequently at work. Of course, yum also has a query function, but unpopular packages also have to be used by yum and rpm.
Syntax: rpm {- Q |-- query} [select-options] [query-options]
Common option combination
The @ rpm-Q httpd query is whether the system has installed a package. When multiple versions co-exist, you need to specify the version number angular rpm-q httpd-tools-scripts to view the script file in the installation package. Grep httpd all view all installed packages and filter the configuration file location of an application. The location of the configuration file of an application, the location of the rpm- qd httpd doc, the location of the help document of an application, the location of the help document, the location of the file, the location of the rpm file, the location of the rpm package, the file, the file, the file El7.noarch View details of installed rpm-ql httpd-tools View list of files generated by installed package rpm-qpl yum-4.0.9.2-5.el8.noarch.rpm View list of files in uninstalled rpm package rpm-qpi yum-4.0.9.2-5.el8.noarch.rpm View metadata information of uninstalled rpm package
Function query
This ability query function is the longest.
_
Examples of skills:
@ rpm-Q httpd-- provides: list the CAPABILITY provided by httpd. * rpm-Q httpd-- whatprovides: query httpd from which package the ability to query the httpd comes from. The whatprovides query bash command is provided by which package. The whatprovides query which packages depend on bash.
6. Package check
Although the verification of this package is simple, we should pay attention to the security issues in the practical application, especially now the network ISP may have domain name hijacking or HTTPS phase agent in order to provide user experience. If we use yum to download and install rpm package, and then the yum client warehouse configuration file is configured with gpgcheck=1,gpgkey and online acquisition, then if the yum source server domain name is hijacked Then the illegal key will be automatically imported into the system when there is yum for the first time, even if the gpgcheck function is enabled. Here is a knowledge point to be confirmed: data signature technology, rpm package verification, that is, the basic data signature technology. It's the same as Microsoft's digital signature technology.
The general principle is that the official hash the rmp package to get the hash value A, and then use the private key to encrypt the ciphertext information obtained by encrypting the hash value as an additional attribute in the rpm package. After the client gets the rpm package, the data part of the rpm package is calculated by hash to get the hash value B, and then the official public key is used to decrypt the ciphertext carried in the rpm package to get the original hash A, if the rpm package has not been modified since it was officially released. And it must be officially released, otherwise the public key cannot decrypt the ciphertext to get A.
The installation package released officially uses asymmetric key encryption technology, private key plus password public key decryption-digital signature technology. After the public key is imported into the system and then installed with the official rpm, there will be no signature alarm. If the official public key is not imported into the system or the public key has been imported, but signature alarm is provided every time the rpm package is installed, you should really pay attention to it.
Public key Management:
The official public key is carried with the CD-ROM. You need to import the system: install the public key: rpm--import RPM-GPG-KEY-CentOS-7 @ search the public key: rpm- qa "* pubkey*" @ view the public key: the storage location in the rpm- qi gpg-pubkey-f4a80eb5-53a7ff4b @ CentOS is: / etc/pki/rpm-gpg to uninstall the public key: rpm- e gpg-pubkey
Verification program file attribute change: when the calculation changes from the system installation to the query time point, it will be marked up and down.
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 rpm-V tree
Rpm unpacking operation
Rpm2cpio / misc/cd/BaseOS/Packages/tree-1.7.0-15.el8.x86_64.rpm | cpio-idv. /
Third, rpm fine-tuning options
Select-options as a fine-tuning option for package query and verification operations
[PACKAGE_NAME] [- a mai muri all [SELECTOR]] [- f mae Murray file FILE] [- gje Murray group GROUP] {- p -- package PACKAGE_FILE] [--hdrid SHA1] [--pkgid MD5] [--tid TID] [--querybynumber HDRNUM] [--triggeredby PACKAGE_NAME] [--whatprovides CAPABILITY] query which packages provide the specified CAPABILITY [--whatrequires CAPABILITY] query which packages rely on this CAPABILITY [--whatrecommends CAPABILITY] [--whatsuggests CAPABILITY] [--whatsupplements CAPABILITY] [-- -whatenhances CAPABILITY] [--whatobsoletes CAPABILITY] [--whatconflicts CAPABILITY]
Query-options as a fine-tuning option for package query operations
General: the general query option [--changelog] displays the change record of the package [--changes] [--dupes] [--iQuery WhisperInfo] displays the package information [--last] [--qf,--queryformat QUERYFMT] [--xml] Dependencies: [--conflicts] [--enhances] [--obsoletes] [--provides] [--recommends] [- R] -- requires] [--suggests] [--supplements] Files: query the configuration file storage location of the installed package. Example: rpm-qc bash [- d -- docfiles] query the help document storage location of the installed package example: rpm-qd bash [--dump] [--fileclass] query the type of files related to the installed package rpm-Q bash-- fileclass [--filecolor] [--fileprovide] [--filerequire] rpm-Q yum-- filerequire [--filecaps] [--filesbypkg] [- l -- list] View the list of files related to the package [--list] View the file status related to the package [--noartifact] [--noghost] [--noconfigScripts and triggers: [--filetriggers] [--scripts] View the script rpm-Q bash-- scripts [--triggers,--triggerscripts] executed before and after the package installation
Verify-options
[--nodeps] does not verify software dependencies [--nofiles] [--noscripts] [--nodigest] [--nosignature] does not verify digital signatures [--nolinkto] [--nofiledigest] [--nosize] [--nouser] [--nogroup] [--nomtime] [--nomode] [--nordev] [--nocaps]
Install-options
[--allfiles] all packages [--badreloc] [--excludepath OLDPATH] [--excludedocs] [--force] are forcibly installed, and the combination of-- replacefiles and-replacepkgs [--replacefiles] [--ignoresize] [--ignorearch] ignores the hardware architecture platform [--ignoreos] ignores the operating system [--includedocs] [--justdb] to update the database. Install [--nodigest] directly install [--nodigest] without changing any file [--nodeps] ignore dependencies, do not verify package integrity [--noplugins] [--nocaps] [--noorder] [--noverify] [--nosignature] ignore verification digital signature For installation of third-party package [--noscripts] does not execute pre-and post-installation scripts in the package [--notriggers] [--oldpackage] for downgrading [--percent] installation of the package to display the percentage of completion [--prefix NEWPATH] specified installation directory, put the files in the specified directory [--relocate OLDPATH=NEWPATH] put the files that would have been placed in the original directory to the new directory. [--replacefiles] replace file [--replacepkgs] replace package [--test] test installation, but do not actually perform installation, that is, dry run mode
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.