#16 yum 包管理系统

2016-05-02

关于 DNF 的更多信息,参考:2016/05/03 CentOS DNF

介绍

  1. .rpm 包,和 .deb 包是 Linux 生态中两种最主要的包格式。
  2. yum:
  3. 较新版本提供了 dnf 工具,改善 yum

包名

bash-4.2.46-35.el7_9.x86_64.rpm

其中:

  • bash 是名称
  • 4.2.46 是版本
  • 35.el7_9 是构建版本
  • x86_64 是服务器架构
  • rpm 是文件后缀
名称    :bash
架构    :x86_64
版本    :4.2.46
发布    :31.el7
大小    :3.5 M
源    :installed
来自源:anaconda
简介    : The GNU Bourne Again shell
网址    :http://www.gnu.org/software/bash
协议    : GPLv3+
描述    : The GNU Bourne Again shell (Bash) is a shell or command language
         : interpreter that is compatible with the Bourne shell (sh). Bash
         : incorporates useful features from the Korn shell (ksh) and the C shell
         : (csh). Most sh scripts can be run by bash without modification.

基本用法

yum help list # 查看帮助

yum search <package> # 搜索包

yum list
yum list installed
rpm -qa
yum list --upgradable

yum info <package>
rpm -qi <package>

rpm -ql <package> # 已安装包的文件列表
rpm -qd <package> # 已安装包的文件列表中的文档部分
rpm -qc <package> # 已安装包的文件列表中的配置部分

yum repolist

# repoquery 是 yum-utils 包提供的命令
repoquery -l <package> # 文件列表
repoquery -f <filepath> # 查看文件属于哪个包, 比如: `repoquery -f "*/repoquery"`
repoquery --location <package> # 查看包的下载地址

yum deplist <package> # 依赖
rpm -qR <package> # 已安装包的依赖
rpm -q --whatrequires <package> # 反向依赖
rpm -q --whatprovides <filepath>
rpm -qf <filepath>

yum provides <pattern>
yum whatprovides <patter>

yum check-update
yum updateinfo
yum update [package]
yum upgrade [package]
yum update-minimal
yum upgrade-minimal # 和 yum update-minimal 相同
yum downgrade <package>

yum install <package>
yum install <package-rpm-filepath>
yum reinstall

yum makecache
yum clean

yum erase
yum remove
yum autoremove

# list, info, summary, repeat, redo, undo, new, rollback, addon, addon-info, stats, statistics, sync, synchronizepkg, pkgs, pkg-list, pkgs-list, package, package-list, packages, packages-list, pkg-info, pkgs-info, package-info, packages-info
yum history
yum history list
yum history list all

yum versionlock <package>

安装组

RedHat 系列提供的,安装组(Group)的概念非常好。

安装组就是为了某一个目的需要的一组包,比如 gnome-desktop 组是安装一个完整的 gnome 桌面环境,web-server 组是安装 apache 和相关的几个包。

  1. 安装组中有必须安装的包(Mandatory Packages),默认安装的包(Default Packages),也有可选的包(Optional Packages)。
  2. 按我的理解,安装组分成三类:
  3. 可用组 Available Group,就是普通的安装组,包含部分包,可以 install。
  4. 环境组 Environment Group,就是安装组的组,group of goups,比如 minimal 环境组包含必须的 core 组和可选的 debugging 组。也可以 install。
  5. 基础组,比如 core,比如 php,是隐藏的,不可直接 install,用于构建环境组设计的。
    我实在想不到为什么这些组不直接暴露出来,这个设计有什么别的原因。
$ yum help groups
groups [list|info|summary|install|upgrade|remove|mark] [GROUP]

显示或使用、组信息

别名:group, grouplist, groupinfo, groupinstall, groupupdate, groupremove, grouperase
  • yum grouplist
  • yum group list ids 附带组 ID
  • yum group list hidden 列出所有组
  • yum groupinfo
  • yum groupinstall <group>
  • yum install @<group>
  • yum install @^<environment-group>
  • yum --setopt=group_package_types=mandatory,default,optional groupinstall "Web Server"
  • yum groupupdate
  • yum groupremove
  • yum grouperase

相关文件

  • /etc/yum.conf
  • /etc/yum.repos.d/
  • /etc/yum/

/etc/rpm 目录不知道是干什么的。

yum 插件

比如最常见的 fastestmirror,用于自动选择最快的镜像源。所以我们使用 CentOS 时,一般不需要去配置镜像源。

#14 删除文件属性

2016-03-15
# 时间清零
touch -amt 197001010000.00 <file>

sudo apt install -y xattr
xattr -l <file>
# 删除所有附加属性
xattr -c <file>

#13 Linux 文件描述符

2016-02-01

文件描述符

File Descriptor

“一切皆文件” 设计思想来自早期 Unix,这是现在 Unix/Linux 界的一个非常重要的概念(根据 Plan9 操作系统的相关资料,这一条没有得到彻底的贯彻)。

允许打开的最大文件数

系统限制

cat /proc/sys/fs/file-nr
# 17781 0   9223372036854775807
# 已分配, 已使用, 最大值

cat /proc/sys/fs/file-max
# 9223372036854775807

sudo sysctl -a | grep file
# fs.file-max = 9223372036854775807
# fs.file-nr = 17813    0   9223372036854775807

修改:

echo 100000000 > /proc/sys/fs/file-max
sysctl fs.file-max 100000000

进程限制

# ulimit 是一个 Shell 内建命令
ulimit -a       # 输出所有的相关限制
ulimit -n       # 当前进程的最大打开文件数
ulimit -n 10240 # 修改当前进程的最大打开文件数

ps -ef | grep sshd | grep -Fv 'grep '
root        1080       1  0 10月16 ?      00:00:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
sudo ls -l /proc/`pgrep sshd`/fd
总用量 0
lr-x------ 1 root root 64 10月 17 12:04 0 -> /dev/null
lrwx------ 1 root root 64 10月 17 12:04 1 -> 'socket:[25487]'
lrwx------ 1 root root 64 10月 17 12:04 2 -> 'socket:[25487]'
lrwx------ 1 root root 64 10月 17 12:04 3 -> 'socket:[28674]'
lrwx------ 1 root root 64 10月 17 12:04 4 -> 'socket:[28676]'

/etc/security/limits.conf

echo "* soft nofile 65535" | sudo tee -a /etc/security/limits.conf
echo "* hard nofile 65535" | sudo tee -a /etc/security/limits.conf

系统会根据 /etc/pam.d/login 中的 PAM 配置来为登录用户设置,
如果配置了 session required /lib/security/pam_limits.so, 就会加载 /etc/security/limits.conf 设置用户的各种限制值。

<domain>        <type>  <item>  <value>
  1. domain
  2. a user name
  3. a group name, with @group syntax
  4. the wildcard *, for default entry
  5. the wildcard %, can be also used with %group syntax, for maxlogin limit
  6. NOTE: group and wildcard limits are not applied to root.
    To apply a limit to the root user, must be the literal username root.
  7. type
  8. "soft" for enforcing the soft limits
  9. "hard" for enforcing hard limits
  10. item
  11. core - limits the core file size (KB)
  12. data - max data size (KB)
  13. fsize - maximum filesize (KB)
  14. memlock - max locked-in-memory address space (KB)
  15. nofile - max number of open file descriptors
  16. rss - max resident set size (KB)
  17. stack - max stack size (KB)
  18. cpu - max CPU time (MIN)
  19. nproc - max number of processes
  20. as - address space limit (KB)
  21. maxlogins - max number of logins for this user
  22. maxsyslogins - max number of logins on the system
  23. priority - the priority to run user process with
  24. locks - max number of file locks the user can hold
  25. sigpending - max number of pending signals
  26. msgqueue - max memory used by POSIX message queues (bytes)
  27. nice - max nice priority allowed to raise to values: [-20, 19]
  28. rtprio - max realtime priority
  29. chroot - change root to directory (Debian-specific)

#11 bc 计算器

2016-01-18

可能这是 Linux 命令行使用频率最高的一个计算器工具了。

其语法可以说比较复杂,可以定义变量,有各种逻辑控制语句,甚至可以定义函数,简直可以拿来做程序设计了。但是我们一般可能用不了这么多功能,就用来做一些简单计算就行。

PS:奇怪的是,有这么多复杂的功能,竟然没有包含位运算。

bc <<< "1 + 3 + 5 + 7 + 9"
26

bc <<< "scale=3; 1 / 3"
.333

bc <<< "obase=2; 14"
1110

bc <<< "ibase=16;obase=2; FF - 1A"
11100101

#10 Shell:长字符串切割成数组

2016-01-16
long_string="line 1
line 2
line 3"

# bash ========
# readarray -t lines <<< "$long_string"
# IFS=$'\n' lines=($long_string)

# zsh =========
# lines=("${(@f)long_string}")
setopt sh_word_split

for line in "${lines[@]}"
do
    echo "$line =="
done

#9 为 CentOS 升级 Linux 内核

2015-11-19

查看内核版本

  • cat /proc/version
  • uname -a-r 参数可以只查看内核版本号

查看发行版版本

  • lsb_release -a
  • cat /etc/redhat-release(CentOS)

升级

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -ivh https://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel install kernel-lt -y  # long-term 长期支持版本
# yum --enablerepo=elrepo-kernel install kernel-ml -y  # mainline 主线版本

参考

#8 使用 col 命令删除退格符

2015-09-12

如果通过定向符号输出 man 文档到文件,然后通过 vi 打开会看到很多蓝色的 ^H 符号。
如果是用 catlessmore 等命令查看(输出到屏幕)就不会看到。

#7 unzip 压缩工具

2015-01-19
zip -e archive.zip file1.txt file2.txt

unzip -l archive.zip # 列出

# 解压缩
unzip archive.zip
unzip -o archive.zip # 覆盖
unzip archive.zip file1.txt file2.txt -d /path/to/directory/ # 指定文件,指定目录
unzip -P password archive.zip # 有密码的压缩文件