Cao Gong's random talk -- with only one command, what software is installed in centos system and when it is installed are all clear

Keywords: RPM MySQL yum Linux

Preface

For a long time, the mastery of linux is the state of half bucket of water. Usually, you can load something from yum and rely on a bunch of things as a result. Then you can load something from the source code. You only know make and make install. What's behind it is unclear and it's inconvenient to unload.

These days, I need to write scripts more clearly. Because the main work of this time is to install and start the shell scripts of various basic services such as redis and mysql with one click, we need to download the rpm package, so there are some related contents below.

First of all, you need to know that there are three basic installation methods under linux (for example, centos is basically used by the server):

  1. Source installation, make, configure, make & install
  2. rpm package installation
  3. yum installation, which encapsulates a layer on the basis of rpm, helps us solve the dependency problem, and finally, rpm installation

Therefore, there are basically two types, rpm installation and source installation.

Give a man a fish and you feed him for a day. Teach him how to fish and you feed him for a lifetime.

The following parts are from the command of viewing man.

In the xshell and secureCRT terminals, I found that every time I went to man xxx to check the instructions, I cut them out to execute the command; then I forgot again later.

It's really troublesome, so I found the following online website, which is really great.

https://linux.die.net/man/

It's OK to search directly inside, and then you can watch and knock happily in the terminal at the same time.

Query what version of components can be installed in the warehouse

Download from yum when a warehouse is opened

During the installation of redis, a third-party repo is used. The repo is disable d by default, so the enablerepo option is added during command execution.

yum --enablerepo=remi install redis

View method 1

[root@localhost yum.repos.d]# yum  list available |grep mysql-community-client.x86_64
mysql-community-client.x86_64            5.7.29-1.el7                  mysql57-community

View method 2

[root@localhost rpm]# yum info gdb
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyuncs.com
 * extras: mirrors.aliyuncs.com
 * updates: mirrors.aliyuncs.com
Available Packages
Name        : gdb
Arch        : x86_64
Version     : 7.6.1
Release     : 115.el7
Size        : 2.4 M
Repo        : base/7/x86_64
Summary     : A GNU source-level debugger for C, C++, Fortran, Go and other languages
...

The following command can confirm that we have not installed:

[root@localhost rpm]# rpm -qa -last |grep gdb

[root@localhost rpm]# gdb
-bash: gdb: command not found

If you view an already installed:

[root@localhost redis]#yum info redis
Loaded plugins: fastestmirror                                                   
Loading mirror speeds from cached hostfile
* updates: mirrors.huaweicloud.com
Installed Packages
Name        : redis
Arch        : x86_64
Version     : 5.0.9
Release     : 1.el7.remi
Size        : 3.0 M
Repo        : installed

As you can see from the last line, the status is installed.

Download dependent rpm

Because we have to do one click installation and operation, we can't rely on the network. We have to download the rpm first. Then you know that an rpm, such as gcc, relies on a pile of its own. Isn't it inefficient to go down one by one.

Try the following command:

yum install --downloadonly --downloaddir=/root/mypackage/ tcpdump
yum install --downloadonly --downloaddir=/root/mypackage/ lrzsz

Thanks for your reference:

Yum automatically downloads RPM package and all its dependent packages

How to know your linux machine

You need to know which software is installed and when.

The following command is OK. The -- last option is seen in man rpm.

--last
Orders the package listing by install time such that the latest packages are at the top.

[root@localhost rpm]# rpm -qa --last
lsof-4.87-6.el7.x86_64                        Mon 27 Apr 2020 01:06:33 PM CST
mysql-community-server-5.7.27-1.el7.x86_64    Mon 27 Apr 2020 11:27:23 AM CST
net-tools-2.0-0.25.20131004git.el7.x86_64     Mon 27 Apr 2020 11:27:03 AM CST
mysql-community-client-5.7.27-1.el7.x86_64    Mon 27 Apr 2020 11:27:03 AM CST
mysql-community-libs-5.7.27-1.el7.x86_64      Mon 27 Apr 2020 11:27:00 AM CST
mysql-community-common-5.7.27-1.el7.x86_64    Mon 27 Apr 2020 11:27:00 AM CST
mysql80-community-release-el7-3.noarch        Fri 24 Apr 2020 05:33:14 PM CST
lrzsz-0.12.20-36.el7.x86_64                   Fri 24 Apr 2020 05:32:56 PM CST
yum-3.4.3-163.el7.centos.noarch               Fri 24 Apr 2020 09:24:24 AM CST
vim-enhanced-7.4.629-6.el7.x86_64             Thu 23 Apr 2020 10:37:44 AM CST
vim-common-7.4.629-6.el7.x86_64               Thu 23 Apr 2020 10:37:44 AM CST
vim-filesystem-7.4.629-6.el7.x86_64           Thu 23 Apr 2020 10:37:42 AM CST
perl-5.16.3-294.el7_6.x86_64                  Thu 23 Apr 2020 10:37:42 AM CST
gpm-libs-1.20.7-6.el7.x86_64                  Thu 23 Apr 2020 10:37:42 AM CST
perl-Pod-Simple-3.28-4.el7.noarch             Thu 23 Apr 2020 10:37:41 AM CST
perl-Getopt-Long-2.40-3.el7.noarch            Thu 23 Apr 2020 10:37:41 AM CST
...

Basically, I know when this command will be installed. If it is installed with gcc and a bunch of them, the installation time is the same.

View additional information about an installed rpm package

In the following commands, the option of - i xxx is put in front, which comes from man rpm.

To query an installed package:

[root@localhost rpm]# rpm -q mysql-community-server
mysql-community-server-5.7.27-1.el7.x86_64
[root@localhost rpm]# rpm -q mysql-community-server-5.7.27 
mysql-community-server-5.7.27-1.el7.x86_64

#If not, the corresponding information will be printed
[root@localhost rpm]# rpm -q mysql-community-server-5.7.27xx 
package mysql-community-server-5.7.27xx is not installed

View profile information

Package Query Options:
-c, --configfiles
List only configuration files (implies -l).

[root@localhost rpm]# rpm -q mysql-community-server -c
/etc/logrotate.d/mysql
/etc/my.cnf

View document information, including man help documents

-d, --docfiles
List only documentation files (implies -l).

[root@localhost rpm]# rpm -q mysql-community-server -d
/usr/share/doc/mysql-community-server-5.7.27/COPYING
...
/usr/share/man/man8/mysqld.8.gz

List all internal files

--filesbypkg
List all the files in each selected package.

[root@localhost rpm]# rpm -q mysql-community-server --filesbypkg
mysql-community-server    /etc/logrotate.d/mysql
mysql-community-server    /etc/my.cnf
mysql-community-server    /etc/my.cnf.d

View package information, including installation time

-i, --info
Display package information, including name, version, and description. This uses the --queryformat if one was specified.

[root@localhost rpm]# rpm -q mysql-community-server -i
Name        : mysql-community-server
Version     : 5.7.27
Release     : 1.el7
Architecture: x86_64
Install Date: Mon 27 Apr 2020 11:27:23 AM CST
...

View all packages in reverse order according to installation date

--last
Orders the package listing by install time such that the latest packages are at the top.

[root@localhost rpm]# rpm -qa --last
lsof-4.87-6.el7.x86_64                        Mon 27 Apr 2020 01:06:33 PM CST
mysql-community-server-5.7.27-1.el7.x86_64    Mon 27 Apr 2020 11:27:23 AM CST
net-tools-2.0-0.25.20131004git.el7.x86_64     Mon 27 Apr 2020 11:27:03 AM CST
mysql-community-client-5.7.27-1.el7.x86_64    Mon 27 Apr 2020 11:27:03 AM CST
mysql-community-libs-5.7.27-1.el7.x86_64      Mon 27 Apr 2020 11:27:00 AM CST
mysql-community-common-5.7.27-1.el7.x86_64    Mon 27 Apr 2020 11:27:00 AM CST
mysql80-community-release-el7-3.noarch        Fri 24 Apr 2020 05:33:14 PM CST
lrzsz-0.12.20-36.el7.x86_64                   Fri 24 Apr 2020 05:32:56 PM CST
yum-3.4.3-163.el7.centos.noarch               Fri 24 Apr 2020 09:24:24 AM CST
vim-enhanced-7.4.629-6.el7.x86_64             Thu 23 Apr 2020 10:37:44 AM CST
vim-common-7.4.629-6.el7.x86_64               Thu 23 Apr 2020 10:37:44 AM CST
vim-filesystem-7.4.629-6.el7.x86_64           Thu 23 Apr 2020 10:37:42 AM CST
perl-5.16.3-294.el7_6.x86_64                  Thu 23 Apr 2020 10:37:42 AM CST
gpm-libs-1.20.7-6.el7.x86_64                  Thu 23 Apr 2020 10:37:42 AM CST
perl-Pod-Simple-3.28-4.el7.noarch             Thu 23 Apr 2020 10:37:41 AM CST
perl-Getopt-Long-2.40-3.el7.noarch            Thu 23 Apr 2020 10:37:41 AM CST
...

View the specified package, what to depend on

-R, --requires
List capabilities on which this package depends.

[root@localhost rpm]# rpm -q mysql-community-server -R
/bin/bash
/bin/sh
/bin/sh
/bin/sh
/bin/sh
/usr/bin/perl
config(mysql-community-server) = 5.7.27-1.el7
coreutils
grep
ld-linux-x86-64.so.2()(64bit)
ld-linux-x86-64.so.2(GLIBC_2.3)(64bit)
...

View some scripts during the installation and uninstallation of the specified package

--scripts
List the package specific scriptlet(s) that are used as part of the installation and uninstallation processes.

[root@localhost rpm]# rpm -q mysql-community-server --scripts
preinstall scriptlet (using /bin/sh):
/usr/sbin/groupadd -g 27 -o -r mysql >/dev/null 2>&1 || :
/usr/sbin/useradd -M -N -g mysql -o -r -d /var/lib/mysql -s /bin/false \
    -c "MySQL Server" -u 27 mysql >/dev/null 2>&1 || :
postinstall scriptlet (using /bin/sh):
[ -e /var/log/mysqld.log ] || install -m0640 -omysql -gmysql /dev/null /var/log/mysqld.log >/dev/null 2>&1 || :

if [ $1 -eq 1 ] ; then 
        # Initial installation 
        systemctl preset mysqld.service >/dev/null 2>&1 || : 
fi 

/usr/bin/systemctl enable mysqld >/dev/null 2>&1 || :
preuninstall scriptlet (using /bin/sh):

if [ $1 -eq 0 ] ; then 
        # Package removal, not upgrade 
        systemctl --no-reload disable mysqld.service > /dev/null 2>&1 || : 
        systemctl stop mysqld.service > /dev/null 2>&1 || : 
fi
postuninstall scriptlet (using /bin/sh):

systemctl daemon-reload >/dev/null 2>&1 || : 
if [ $1 -ge 1 ] ; then 
        # Package upgrade, not uninstall 
        systemctl try-restart mysqld.service >/dev/null 2>&1 || : 
fi

summary

When a part is written, it becomes a simple record, which is continuously updated later

Posted by baseballkid420 on Tue, 28 Apr 2020 04:30:24 -0700