瑞安人才网:曹工杂谈--只用一个下令,centos系统里装了啥软件,啥时候装的,全都清清楚楚

admin 4周前 (04-28) 科技 7 0

前言

一直以来,对linux的掌握就是半桶水的状态,经常yum装个器械,效果依赖一堆器械;然后再用源码装个器械,只知道make、make install,背后干了啥也不清楚了,卸载也不方便。

这几天事情需要,在写剧本,总算加倍清晰了一些。由于这次的主要事情是,redis、mysql等种种基础服务的shell剧本一键安装及启动等,以是我们需要把rpm包下载下来,以是下面有一些相关的内容。

首先人人要知道,linux下(以centos举例,现在服务端基本都用这个)安装基本三种方式:

  1. 源码安装,make, configure, make & install
  2. rpm包安装
  3. yum安装,在rpm基础上封装了一层,帮我们自己解决依赖问题,最终照样rpm安装

以是,基本就两种,rpm安装和源码安装。

授人以鱼不如授人以渔

以下部分内容,来自于查看man这个下令。

在xshell、secureCRT这些终端中,我发现,每次去man xxx查看说明,再切出来执行下令;然后过一会又忘了。

真的很贫苦,于是,我找到了下面这个在线网站,真的很棒。

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

直接在里面搜索就可以了,然后就可以一边看,一边在终端里愉快地敲敲敲了。

查询堆栈中,有什么版本的组件可以安装

开启某个堆栈的情况下yum下载

这次安装redis时,用了第三方repo,这个repo默认是disable的,以是是在执行下令时,加了enablerepo选项。

yum --enablerepo=remi install redis

查看方式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

查看方式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
...

下面这个下令可以证实,我们是没有安装的:

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

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

若是查看一个已经安装了的:

[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

最后一行可以看到,状态是已安装。

下载依赖的rpm

由于我们要做一键安装、运行,一定不能依赖于网络,得先把rpm下载下来。然后人人知道,有个rpm,好比gcc,自己就依赖了一堆,岂非一个一个去下吗,那效率太低了。

试试下面的下令:

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

主要参考了,表示感谢:

Yum自动下载RPM包及其所有依赖的包

怎么对自己的linux机械,心里有数

那一定是需要知道,装了哪些软件,啥时候装的。

就下面这个下令就可以了,其中的--last选项,是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
...

这个基本就知道,这个下令啥时候装的了,若是是那种装个gcc,顺带装一堆的,安装时间都是一样的。

查看一个已安装的rpm包的分外信息

以下下令中,前面都放了-i xxx这样的选项,这个选项来自于man rpm。

查询一个已经安装的包:

[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

#若是查不到,会打印响应信息
[root@localhost rpm]# rpm -q mysql-community-server-5.7.27xx 
package mysql-community-server-5.7.27xx is not installed

查看配置文件信息

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

查看文档信息,包罗man辅助文档

-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

列出内部的所有文件

--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

查看包的信息,包罗安装时间

-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
...

查看所有包,凭据安装日期倒序排列

--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
...

查看指定包,要依赖的器械

-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)
...

查看指定包的一些安装卸载过程中的剧本

--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

总结

写了一部分,就当一个简朴的纪录,后面连续更新

,

诚信在线

诚信在线(www.cx11yx.cn)现已开放诚信在线手机版下载。游戏公平、公开、公正,用实力赢取信誉。

网友评论

  • (*)

最新评论

文章归档

站点信息

  • 文章总数:445
  • 页面总数:0
  • 分类总数:8
  • 标签总数:815
  • 评论总数:110
  • 浏览总数:3801