Program installation and management
1. Linux Application Basics
The relationship between Linux commands and applications
1): file location
System commands: generally in the /bin and /sbin directories, or internal shell commands
Applications: usually in the /usr/bin and /usr/sbin directories
2): Main use
System commands: complete the basic management of the system, such as IP configuration tools
Application: Complete other relatively independent auxiliary tasks, such as a web browser
3): Applicable environment
System commands: generally only run in the character operation interface
Application: According to actual needs, some programs can be run in the graphical interface
4): run format
System commands: generally include command words, command options and command parameters
Application: Usually no fixed execution format
Directory structure of a typical application
file type |
save directory |
common executable file |
/usr/bin |
Server Executor Files and Management Program Files |
/usr/sbin |
application configuration file |
/etc |
log file |
/ var / log |
application documentation file |
/usr/share/doc |
application man page file |
/usr/share/man |
2. Common package packaging types
Package type |
illustrate |
rpm package |
extension ".rpm " |
deb package |
extension ".deb " |
source code package |
Compressed packages in formats such as ".tar.gz " and ".tar.bz2 " generally contain the original code of the program |
package with installer |
Provide installation programs such as install.sh and setup in the compressed package or provide a single executable file in ".bin " format |
Green free installation software package |
Provide the compiled executable program file in the compressed package. After unzipping the compressed package, the file can be used directly |
Package packaging types include rpm packages. Deb packages. Source code packages. Packages with installers.
Source code: The initial code written by the programmer cannot be read by the computer and needs to be compiled into a binary computer language. The C language compiler in Linux is gcc.
3. RPM package management tool
RPM Package Manager
Proposed by Red Hat and used by many Linux distributions
Establish a unified database file, record the software package installation, uninstallation and other change information in detail, and automatically analyze software package dependencies
RPM contains three parts: RPM database, RPM package file and RPM command
RPM package
Software material reference: http://rpmfind.net / www.rpw.org
General naming format: software name - software version - number of releases. operating system type. hardware architecture type. rpm
Note: Execute the "man rpm" command for detailed help on the rpm command
4. Query RPM package information
1): Query installed rpm software information
Syntax: rpm -q [ suboptions] [ software name]
Usage: Combine different sub-options to complete different queries
-qa: View a list of all RPM packages installed in the system
-qi: View detailed information of the specified software (--info)
-ql: Query the list of directories and files installed by the specified software package (--list)
-qc: show only configuration files installed by the specified package
-qd: show only documentation files installed by the specified package
-qf: View the specified file or directory installed by which package (--file)
2): Query which RPM software the file or directory belongs to
Syntax: rpm - qf file or directory name
3): Query the RPM package file that is not installed
Syntax: rpm - qp [ suboption] RPM package file
Usage: Combine different sub-options to complete different queries
-qpi: View the details of the software through the .rpm package file
-qpl: View the list of directories and files contained in the .rpm installation package
-qpc: View the list of configuration files contained in the .rpm installation package
-qpd: View the list of documentation files contained in the .rpm installation package
Note: Using the r pm command can only query the information of the software packages installed by RPM and the software packages installed in the system by other means. The rpm command will not be able to obtain relevant information.
3. Install, upgrade and uninstall RPM packages
Install or upgrade RPM software
Syntax: rpm [ options] RPM package file...
Usage: Different options for different situations
-i: install a new rpm package
-U: upgrade a rpm software, if it is not installed, install it
-F: Update a certain rpm software, if it is not installed, abandon the installation
-h: Display the progress of the installation with a "#" sign
-v: Display detailed information during installation
Uninstall the specified RPM software
Syntax: rpm -e software name
--nodeps: remove packages, even if dependencies are still installed on the system
--test: do nothing, just print the output
5. Maintain the RPM database
A database of currently installed software is maintained in linux , which is located in the /var/lin/rpm/ directory. Use the file /var/lib/rpm/* command to view the contents of the directory, and you can see that the hash database files are all in binary form.
View digital signatures
6. Resolve package dependencies
When installing multiple software with dependencies: the dependent software packages need to be installed first; multiple .rpm package files can be specified for installation at the same time
When uninstalling multiple software with dependencies: software packages that depend on other programs need to be uninstalled first; you can specify multiple software names to uninstall at the same time
Ignore dependencies: combined with "--nodeps" option, but may cause software exceptions
For example: Demonstrate the uninstallation and installation process of the vim-common and vim-enhanced packages. The reference steps are as follows:
1) First uninstall vim-common normally, it should be prompted to be dependent on vim-enhanced and fail
2) So the normal uninstall sequence: uninstall vim-enhanced first, then uninstall vim-common
3) Then reinstall these two packages from the CD, first install vim-enhanced, you should be prompted to install vim-common first
4) Therefore, the normal installation sequence: install vim-common first, and then install vim-enhanced. You can also specify these two files in one rpm command during demonstration.
- Reminder: If you need to install dozens of .rpm packages that depend on each other at the same time, you can specify these files as parameters in combination with the Shell wildcard "*"
Execute the rpm command to complete management operations such as query, installation, upgrade, and uninstallation of rpm packages.
Extended: RPM related considerations
The prerequisites of RPM packages can be viewed directly using the command line options --requires and --provides
Prerequisites for installing vsftpd: command rpm -q -requires vsftpd
Display package explicitly provided content: command rpm -q -provides vsftpd
Display the installation script of vsftpd: command rpm -q --scripts vsftpd
Display RPM packages installed on the system in chronological order: command rpm -qa --last
Solve some common problems with RPM (access database)
Killall-9 rpm command kills all currently hung rpm processes
Delete all files starting with _db. in the RPM database directory (/var/lib/rpm/)
7. Overview of source code compilation
1): Advantages
Obtain the latest software version and fix bugs in time; flexibly customize software functions according to user needs
2): example of application
When installing a newer version of an application; most recent versions of free software are first released as source code
When the currently installed program cannot meet the needs; the compilation and installation can be modified and customized by the user
When new functions need to be added to the application; users can reconfigure, freely modify the source code, and add new functions
8. Compile and install the source code package
Tarball package: Most of the formats are .tar.gz and .tar.bz2; software material reference: http://sourceforge.net
Integrity check
md5sum verification tool; calculate the MD5 checksum and compare it with the official value to determine whether it is consistent
[root@localhost ~]# md5sum axel-1.0a.tar.gz
2d94c0b36b374834567f1fcec5f89119 ( MD5 checksum ) axel-1.0a.tar.gz
For the downloaded package file, if the MD5 checksum is inconsistent with the official one, it means that the package may have been illegally altered during network transmission.
For software packages with inconsistent checksums, try not to use them to avoid unsafe factors such as viruses and Trojans.
The basic process of compiling and installing
Environment: A compiler that supports C/C++ programming language needs to be installed, such as: gcc-4.4.7-4.el6, gcc-c++-4.4.7-4.el6; make-3.81-20.el6. …
Process:
Step 1. Unpack : It is customary to release the software package to the /usr/src/ directory; the location of the unpacked source code file: /usr/src/software name-version number/
Step 2. Configuration: use the configure script in the source directory; execute "./configure --help" to view the help; typical configuration options: --prefix=software installation directory
When installing software through source code in Linux system, you can also install all program files into the same folder, such as: (/configure-prefix=/usr/local/apache).
Step 3. Compile: Execute the make command
Step 4. Installation: Execute the make install command
Compiling source code in linux requires the use of the gcc.Make compilation environment; the basic process of installing an application from source code includes the four steps of unpacking, configuring, compiling, and installing.
Account and Permission Management
1. Overview of user accounts and group accounts
user account:
Super user, that is, the root user: similar to the Administrator user in the Windows system, it is not recommended to use the root user to log in to the system when not performing administrative tasks
Ordinary user: the account generally only has full permissions in the user's own home directory
Program user: used to maintain the normal operation of the system or a program, and is generally not allowed to log in to the system. For example: bin, daemon, ftp, mail, etc.
Group account:
Basic group (private group): Each account belongs to at least one group.
Additional group (public group): After an account belongs to a basic group, it joins another group.
UIDs and GIDs
UID (User IDentity, user identification number)
GID (Group IDentify, group identification number)
Note: The UID of the root user has a fixed value of 0 , and the GID number of the root group account is a fixed value of 0 ; UIDs and GIDs from 1 to 499 are reserved for program users by default, and UIDs and GIDs used by ordinary users / groups are between 500 and 500 . Between 60000
2. User account file /etc/passwd
Save basic information such as user name, host directory, login shell; each line corresponds to a user's account record; all users can access the contents of the passwd file, but only the root user can change
The meaning of the seven fields of the Password file configuration: account name; user password or password placeholder; uid number of user account; gid number of basic group account; user description; host directory; login shell.
3. User account file /etc/shadow
Save the user's password, account validity period and other information; each line corresponds to a user's password record; each line of the file contains nine configuration fields separated by colon ":"
The meaning of the nine fields configured in the shadow file: account name; md5 value. If it is "*/!!", it indicates that the user cannot log in, if it is empty, no password is required; the last password modification time; the minimum valid number of days for the password, the default is 0; the maximum number of days the password is valid, the default is 99999; the number of days in advance to warn the user that the password is about to expire, the default is 7; the number of days after the password expires to disable the account; the account expiration time, the default is empty, indicating permanent use; reserved field.
1 ): useradd command: add user account
In rhel 6, the useradd command is used to add the user's account record at the end of the /etc/passwd and /etc/shadow files; if the user's home directory is not specified, a host directory with the same name as the account is created in the /home directory; If the group to which the user belongs is not specified, a basic group with the same name as the user account is automatically created and saved in /etc/group./etc/gshadow.
Syntax : useradd [options]...username
Common command options
-u: Specifies the UID tag number
-d: Specify the home directory, the default is /home/username
-e: Specify the account expiration time
-g: Specifies the user's base group name (or UID number)
-G: Additional group name (or GID number) for the specified user
-M: Do not create and initialize the host directory for the user
-s: Specifies the user's login shell
2) : The initial configuration file of the user account
File source : When creating a new user account, it is copied from the /etc/skel directory
Primary user initial profile
~/.bash_profile: executed every time the user logs in
~/.bashrc: executed each time a new Bash environment is entered
~/.bash_logout: executed every time the user logs out
3 ): passwd command: set password for user account
Syntax: passwd [options]...username
Common command options : -d: clear the user's password so that they can log in without a password; -l: lock the user account; -S: check the status of the user account (whether it is locked); -u: unlock the user account
Note: The user account locked by the password command will not be able to log in to the system (the "!!" character will be added before the corresponding password string in the shadow file), and can only be unlocked by the administrator.
4 ): usermod command: modify user account attributes
Syntax: usermod [options]...username
Common command options
-l: Change the login name of the user account
-L: lock user account
-U: Unlock user account
The following options have the same meaning as in the useradd command (change the designation to modification): -u, -d, -e, -g, -G, -s
5 ): userdel command: delete user account
Syntax: userdel [-r] username
When adding the -r option, it means to delete the user's home directory together
4. Group account file
/etc/group: saves the basic information of the group account; /etc/gshadow: saves the password information of the group account
1 ): groupadd command: add group account
Syntax: groupadd [-g GID] group account name
2 ): gpasswd command : add.set.remove group member
Syntax: gpasswd [options]...group account name
Common command options: -a: add a user to the group; -d: delete a user member from the group; -M: define a list of group members, separated by commas
3 ): groupdel command: delete group account
Syntax: groupdel group account name (after deleting the group account, the corresponding record will not be found in the /etc/group file)
5. Query account information
id command : Purpose: Query user identity; syntax: id [username]
groups command : purpose: query the group to which the user belongs; syntax: groups [username]
finger command : Purpose: Query the detailed information of a user account; syntax: finger [username]
users , w , who commands : Purpose: Query information about users who have logged in to the host
6. Permissions and attribution of files / directories
access permission
Read r: Allows viewing file contents and displaying directory listings
Write w: Allows to modify file content, allows to create, move, delete files or subdirectories in the directory
Executable x: Allows to run programs, switch directories
Attribution (ownership)
Owner: The user account that owns the file or directory
Group: The group account that owns the file or directory
7. Set permissions for directories and files chmod
Syntax 1 : chmod [ugoa] [+-=] [rwx] file or directory... (+, -, = represent adding, removing, and setting permissions respectively) (u, g, o, a represent owner, Group, other users, all users (sum of ugo)) (r,w,x permission characters can be represented as octal characters 4, 2, 1 respectively, indicating that the numbers need to be accumulated when a permission combination is required; for example, rwx=7 , rw-rr=644)
Syntax 22 : chmod nnn file or directory... (3 octets)
Common command options : -R: recursively modify the permissions of all subkeys in the specified directory
8. Set the attribution of directories and files to chown
Syntax: chown owner file or directory
Chown: belongs to the group file or directory
Chown owner: belongs to the group file or directory
Common command options : -R: recursively modify the ownership of all files and subdirectories in the specified directory