曹工杂谈--只用一个命令,centos系统里装了啥软件,啥时候装的,全都清清楚楚
前言
一直以来,对linux的掌握就是半桶水的状态,经常yum装个东西,结果依赖一堆东西;然后再用源码装个东西,只知道make、make install,背后干了啥也不清楚了,卸载也不方便。
这几天工作需要,在写脚本,总算更加清晰了一些。因为这次的主要工作是,redis、mysql等各种基础服务的shell脚本一键安装及启动等,所以我们需要把rpm包下载下来,所以下面有一些相关的内容。
首先大家要知道,linux下(以centos举例,现在服务端基本都用这个)安装基本三种方式:
- 源码安装,make, configure, make & install
- rpm包安装
- yum安装,在rpm基础上封装了一层,帮我们自己解决依赖问题,最终还是rpm安装
所以,基本就两种,rpm安装和源码安装。
授人以鱼不如授人以渔
以下部分内容,来自于查看man这个命令。
在xshell、secureCRT这些终端中,我发现,每次去man xxx查看说明,再切出来执行命令;然后过一会又忘了。
真的很麻烦,于是,我找到了下面这个在线网站,真的很棒。
直接在里面搜索就可以了,然后就可以一边看,一边在终端里愉快地敲敲敲了。
查询仓库中,有什么版本的组件可以安装
开启某个仓库的情况下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
主要参考了,表示感谢:
怎么对自己的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
总结
写了一部分,就当一个简单的记录,后面持续更新