包管理工具 Linux CentOS RHEL DNF Yum RPM
2016-05-02
关于 DNF 的更多信息,参考:2016/05/03 CentOS DNF
介绍
.rpm 包,和 .deb 包是 Linux 生态中两种最主要的包格式。
- yum:
- 较新版本提供了 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 和相关的几个包。
- 安装组中有必须安装的包(Mandatory Packages),默认安装的包(Default Packages),也有可选的包(Optional Packages)。
- 按我的理解,安装组分成三类:
- 可用组 Available Group,就是普通的安装组,包含部分包,可以 install。
- 环境组 Environment Group,就是安装组的组,group of goups,比如 minimal 环境组包含必须的 core 组和可选的 debugging 组。也可以 install。
- 基础组,比如 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 时,一般不需要去配置镜像源。
Linux wget 开发工具 HTTP
2016-04-26
复制指定 URL 路径下的所有文件到本地目录 HTML 下:
wget -m -p -k -np -P <HTML> <URL>
Linux
2016-03-15
# 时间清零
touch -amt 197001010000.00 <file>
sudo apt install -y xattr
xattr -l <file>
# 删除所有附加属性
xattr -c <file>
Linux 定时任务
2016-03-01
https://mp.weixin.qq.com/s/EJGz2koxuvLzJhnKXUBiAA
任何一本 Linux 书籍都会讲到 Cron 和 At 两个命令,都是定时执行命令,不同的是 at 执行一次,cron 周期性执行。
我们常见的 cron 应该是有这 3 种:
- vixie cron
- 支持 @yearly @monthly 等关键字
- @reboot 关键字,用于系统启动之后执行
- 环境变量
- crontab
- 邮件通知
- 日志记录
- 多任务并发
- anacron
- systemd-cron
cron 是一个知名的定时任务服务,大多数 UNIX / Linux 系统都已经预装了。
cron 包包含两个可执行文件:
- /usr/bin/cron 后台程序(系统服务),定期执行命令或脚本,可精确到分钟
- /usr/bin/crontab 管理定时任务(增删改查),每个用户都有自己的 crontab 文件
检查是否安装:
which crontab
cron
定时任务定义语法(分时日月周):
* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of the week (0 - 6) (Sunday is both 0 and 7)
| | | ------- Month (1 - 12)
| | --------- Day of the month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
比如:0 23 * * * bash /path/to/backup-script.sh 表示每晚 11 点运行一个备份脚本。
, 表示多个值
- 表示一个范围
/ 表示每隔多长时间
问题:cron 只能执行简单任务,不支持交互、错误处理、日志等功能。
crontab
crontab -e:编辑
crontab -l:列出
crontab -r:删除
脚本中可以使用 TZ 指定时区,如下(没用实操过):
TZ=UTC
0 0 * * * /path/to/backup-script.sh
配置文件
在大多数 UNIX 和类 UNIX 系统中,cron 会从多个文件中读取定时任务的配置。这些文件通常包括:
/etc/crontab 系统级,需要指定执行用户
/etc/cron.d/
/var/spool/cron/ 每个用户有一个自己名字的文件
anacron
好像 CentOS 中默认安装的是这货。
和 cron 相比,是基于时间间隔来的,也就是说发现距离上一次执行的时间超过了定义的间隔就再次执行。
cron 是指定到具体的时间点,如果那个时间点系统关机了,这个任务就错误了,不会执行。
提供 anacron,anacrontab 两个命令。
anacron [-s] [-f] [-n] [-d] [-t] [-S] [-T] [-u] [-r] [-V] [job] ...
-s:以非安静模式运行,输出详细信息。
-f:强制运行所有作业,忽略上次运行时间间隔。
-n:以模拟模式运行,输出将要运行的作业信息。
-d:以调试模式运行,输出调试信息。
-t:测试配置文件中所有作业是否可运行。
-S:停止所有正在运行的作业。
-T:将所有正在运行的作业的运行时间戳更新为当前时间。
-u:指定运行作业的用户。
-r:重新载入配置文件。
-V:显示版本信息。
cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
systemd-cron
Systemd 这个大管家引入之后,当然定时任务这点小事也可以顺带着就给做了。
采用和系统服务相同格式的 unit file 来声明定时任务,可以定义依赖关系,精度到毫秒。从各方面来看都应该强大得多,但是大多数使用场景下简单的 cron 足够了,所以我还没有使用过 systemd-cron。
systemd-cron 也提供一个 crontab 命令,可以兼容原来的语法。
systemctl list-units | grep cron
cron.service loaded active running Regular background program processing daemon
anacron.timer loaded active waiting Trigger anacron every hour
测试
# ll /opt/cron_test.sh /etc/cron.d/test
-rw-r--r-- 1 root root 33 Jun 8 12:53 /etc/cron.d/test
-rwxr-xr-x 1 root root 184 Jun 8 12:52 /opt/cron_test.sh
# cat /etc/cron.d/test
* * * * * root /opt/cron_test.sh
# cat /opt/cron_test.sh
#!/bin/bash
{
echo "===================="
echo "TIME: $(date '+%F %T')"
echo "USER: $(whoami)"
echo "PWD : $(pwd)"
echo "PATH: $PATH"
} >> /tmp/cron_test.log 2>&1
# tail -f /tmp/cron_test.log
====================
TIME: 2026-06-08 12:54:01
USER: root
PWD : /root
PATH: /usr/bin:/bin
^C
# journalctl -u cron
-- No entries --
# journalctl -u crond | grep test
Jun 08 12:54:01 iZt4nerpnxvn37c1tlx3brZ CROND[1376687]: (root) CMD (/opt/cron_test.sh)
Jun 08 12:54:01 iZt4nerpnxvn37c1tlx3brZ CROND[1376686]: (root) CMDEND (/opt/cron_test.sh)
Jun 08 12:55:01 iZt4nerpnxvn37c1tlx3brZ CROND[1376701]: (root) CMD (/opt/cron_test.sh)
Jun 08 12:55:01 iZt4nerpnxvn37c1tlx3brZ CROND[1376700]: (root) CMDEND (/opt/cron_test.sh)
Jun 08 12:56:01 iZt4nerpnxvn37c1tlx3brZ CROND[1376711]: (root) CMD (/opt/cron_test.sh)
Jun 08 12:56:01 iZt4nerpnxvn37c1tlx3brZ CROND[1376710]: (root) CMDEND (/opt/cron_test.sh)
Jun 08 12:57:01 iZt4nerpnxvn37c1tlx3brZ CROND[1376750]: (root) CMD (/opt/cron_test.sh)
Jun 08 12:57:01 iZt4nerpnxvn37c1tlx3brZ CROND[1376749]: (root) CMDEND (/opt/cron_test.sh)
Linux
2016-02-09
Linux 系统启动时,内核首先启动用户空间第一个进程 PID 1,即初始化系统(init system)。历史上常见实现包括 SysVinit、Upstart 和 systemd。初始化系统负责根据配置和依赖关系启动系统组件。之后,任何已启动的进程都可以在权限允许的情况下创建新的子进程,因此系统中的程序启动来源并不局限于 init system,例如桌面环境、cron、supervisor 等都可能成为程序启动入口。
Linux 中常见的程序自动启动方式主要包括:
- systemd 服务:用于系统服务和后台进程管理;
- 桌面环境自启动:用户登录图形桌面后启动应用;
- 定时任务:通过 cron 或 systemd timer 按时间启动任务;
- 登录脚本:通过 shell profile 等方式在用户登录时执行。
Systemd
PS:截止到 2026 年,除了少数发行版和部分老版本 Linux(如 CentOS 6、Debian 7 及更早版本)使用源自 UNIX System V 的 SysVinit,绝大多数主流 Linux 发行版已经采用 Systemd 作为初始化系统(兼容 SysVinit)。Ubuntu 比较另类的一点是从 6 ~ 14 一直采用的是 Canonical 自研的 Upstart(兼容 SysVinit),最终没有竞争过红帽家的 Systemd,从 15 开始转 Systemd 阵营。
在 Linux 社区,对 Systemd 最主要的批评之一,是它被认为违反了 Unix 的设计哲学——"Do one thing and do it well"。SysVinit 只有几万行代码,本质上只是负责按顺序执行启动脚本,而 Systemd 整个项目的代码规模达到数百万行,除了初始化系统,还集成了日志、登录管理、DNS、网络、定时器等众多功能。因此,不少开发者认为,它已经不仅仅是一个 init 系统,而更像是一个覆盖系统多个基础设施的框架。
-> % cat /etc/systemd/system/multi-user.target.wants/cron.service
[Unit]
Description=Regular background program processing daemon
Documentation=man:cron(8)
After=remote-fs.target nss-user-lookup.target
[Service]
EnvironmentFile=-/etc/default/cron
ExecStart=/usr/sbin/cron -f -P $EXTRA_OPTS
IgnoreSIGPIPE=false
KillMode=process
Restart=on-failure
SyslogFacility=cron
[Install]
WantedBy=multi-user.target
# 查看所有开机启动的服务:
-> % systemctl list-unit-files --state=enabled
# 查看正在运行的服务:
-> % systemctl --type=service --state=running
# 查看某个服务是否开机启动:
-> % systemctl is-enabled cron
enabled
列出 Systemd 定时任务:
-> % systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES
Wed 2026-07-15 12:50:00 CST 9min Wed 2026-07-15 12:40:00 CST 56s ago sysstat-collect.timer sysstat-collect.service
Wed 2026-07-15 13:04:57 CST 23min Wed 2026-07-15 12:32:54 CST 8min ago fwupd-refresh.timer fwupd-refresh.service
Wed 2026-07-15 13:32:44 CST 51min Wed 2026-07-15 12:34:02 CST 6min ago anacron.timer anacron.service
Wed 2026-07-15 14:32:24 CST 1h 51min Wed 2026-07-15 11:32:24 CST 1h 8min ago apport-autoreport.timer apport-autoreport.service
Wed 2026-07-15 16:23:05 CST 3h 42min Wed 2026-07-15 05:50:18 CST - motd-news.timer motd-news.service
Wed 2026-07-15 16:50:48 CST 4h 9min Wed 2026-07-15 10:38:46 CST 2h 2min ago ua-timer.timer ua-timer.service
Thu 2026-07-16 00:00:00 CST 11h Wed 2026-07-15 00:00:00 CST - dpkg-db-backup.timer dpkg-db-backup.service
Thu 2026-07-16 00:00:00 CST 11h Wed 2026-07-15 00:00:00 CST - privoxy-cleanup.timer privoxy-cleanup.service
Thu 2026-07-16 00:00:00 CST 11h - - sysstat-rotate.timer sysstat-rotate.service
Thu 2026-07-16 00:07:00 CST 11h - - sysstat-summary.timer sysstat-summary.service
Thu 2026-07-16 00:30:52 CST 11h Wed 2026-07-15 00:29:04 CST - plocate-updatedb.timer plocate-updatedb.service
Thu 2026-07-16 00:39:05 CST 11h Wed 2026-07-15 00:29:04 CST - logrotate.timer logrotate.service
Thu 2026-07-16 01:57:49 CST 13h Wed 2026-07-15 06:06:45 CST - apt-daily.timer apt-daily.service
Thu 2026-07-16 05:50:05 CST 17h Wed 2026-07-15 06:54:49 CST - man-db.timer man-db.service
Thu 2026-07-16 06:07:09 CST 17h Wed 2026-07-15 06:47:46 CST - apt-daily-upgrade.timer apt-daily-upgrade.service
Thu 2026-07-16 10:37:23 CST 21h Wed 2026-07-15 10:37:23 CST 2h 3min ago update-notifier-download.timer update-notifier-download.service
Thu 2026-07-16 10:47:22 CST 22h Wed 2026-07-15 10:47:22 CST 1h 53min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Sat 2026-07-18 06:10:20 CST 2 days Tue 2026-07-07 20:21:04 CST - update-notifier-motd.timer update-notifier-motd.service
Sun 2026-07-19 03:10:35 CST 3 days Sun 2026-07-12 03:10:22 CST - e2scrub_all.timer e2scrub_all.service
Mon 2026-07-20 00:21:23 CST 4 days Mon 2026-07-13 01:29:24 CST - fstrim.timer fstrim.service
20 timers listed.
Pass --all to see loaded but inactive timers, too.
-> % cat /etc/systemd/system/timers.target.wants/anacron.timer
[Unit]
Description=Trigger anacron every hour
[Timer]
OnCalendar=*-*-* 07..23:30
RandomizedDelaySec=5m
Persistent=true
[Install]
WantedBy=timers.target
更多选项可以参考:金步国 systemd.timer 中文手册。
桌面环境自动启动
systemd -> gdm3 (显示管理器) -> gnome-session -> GNOME Session Manager -> 读取 ~/.config/autostart/*.desktop
-> % find ~/.config/autostart -type f
/home/catroll/.config/autostart/com.github.hluk.copyq.desktop
/home/catroll/.config/autostart/remmina-applet.desktop.save
/home/catroll/.config/autostart/remmina-applet.desktop
/home/catroll/.config/autostart/nutstore-daemon.desktop
-> % ps -ef | grep remmina | grep -Fv grep
catroll 5357 4639 0 10:34 ? 00:00:00 /usr/bin/remmina -i
-> % ps -fp 4639
UID PID PPID C STIME TTY TIME CMD
catroll 4639 1 0 10:34 ? 00:00:00 /usr/lib/systemd/systemd --user
定时任务
cron 这个命令自 Unix 系统开始开发就存在。
后来被广泛采纳的是 Paul Vixie 开发的版本,被称之为 Vixie Cron。
- /etc/crontab
- /etc/cron.d
- 支持分钟级调度
配置格式就是大家熟悉的:
* * * * * <command to execute>
# | | | | |
# | | | | day of the week (0–6) (Sunday to Saturday;
# | | | month (1–12) 7 is also Sunday on some systems)
# | | day of the month (1–31)
# | hour (0–23)
# minute (0–59)
Vixie Cron 有两个影响大的分叉:
-
红帽系:Cronie
[root@iZt4nerpnxvn37c1tlx3brZ ~]# yum list --installed | grep cron
cronie.x86_64 1.5.7-15.el9 @System
cronie-anacron.x86_64 1.5.7-15.el9 @System
crontabs.noarch 1.11-27.20190603git.el9 @System
-
Debian 系:Debian cron
-> % apt list --installed | grep cron
anacron/resolute,now 2.3-45ubuntu1 amd64 [installed]
cron-daemon-common/resolute,now 3.0pl1-200ubuntu1 all [installed,automatic]
cron/resolute,now 3.0pl1-200ubuntu1 amd64 [installed,automatic]
简单使用没有什么太大区别。
值得注意的是,anacron 也是 cronie 项目组维护,所以在红帽系 anacron 的包名是 cronie-anacron。
anacron 也是一个知名的定时任务工具,它不是用来取代 cron,而是作为 cron 的补充机制。
按照 cron 的设计,任务会在预定时间点执行;如果系统在该时间点处于关机状态,任务就会被直接跳过,不会补执行。例如,将备份任务设置为每天凌晨 0 点执行,如果电脑在 23:59 关机、00:01 开机,那么当天的备份就会被错过。
对于服务器而言,这通常不是问题,因为服务器很少关机;但对于个人电脑、笔记本等经常关机或休眠的设备,这种情况十分常见。anacron 的作用就是记录这些周期性任务是否已经执行,如果发现因为关机而错过了执行时机,就会在系统下次启动后适时补执行一次,从而保证每天、每周或每月的维护任务不会遗漏。
anacron 并不支持分钟级调度,它主要面向 daily、weekly、monthly 等周期性任务。
比如:/etc/anacrontab
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
这里面就是定义了三条补救策略。
参考:Linux 定时任务(cron/crontab)
登录脚本
登录脚本(Login Script)本质上就是 Shell 在用户登录时自动执行的脚本。如果在这些脚本中启动程序,那么程序就会随着登录自动启动。
需要注意的是,登录脚本属于 Shell 的机制,而不是 Linux 内核或 systemd,因此具有以下特点:
- 只有启动 Login Shell 时才会执行。
- 每次启动 Login Shell 都会执行,因此使用这种方式实现自启动时,需要自行处理程序重复启动的问题。
- 不同 Shell(如 Bash、Zsh)使用的登录脚本不同,配置方法略有差异。
- 图形登录是否会执行登录脚本,取决于登录管理器(Display Manager)和桌面会话的具体实现,不同发行版和桌面环境可能存在差异。
- 没有生命周期管理能力,程序退出后不会自动重启,也无法方便地控制依赖关系和启动顺序。
注意: ~/.bashrc 是 非 Login Shell 的初始化脚本。如果在其中启动程序,那么每打开一个新的 Bash 终端都会再次执行一次,因此通常不适合作为程序自启动的配置文件。
例如使用 Bash:
用户登录
│
▼
bash
│
├── /etc/profile
├── ~/.bash_profile
├── ~/.bash_login
├── ~/.profile
└── 执行其中的命令
如果这些文件中有:
~/bin/my-agent &
那么登录后就会自动启动 my-agent。
# find ~/.*profile* ~/.bash* /etc/profile* -type f | sort -u
/etc/profile
/etc/profile.d/bash_completion.sh
/etc/profile.d/colorgrep.csh
/etc/profile.d/colorgrep.sh
/etc/profile.d/colorls.csh
/etc/profile.d/colorls.sh
/etc/profile.d/colorsysstat.csh
/etc/profile.d/colorsysstat.sh
/etc/profile.d/colorxzgrep.csh
/etc/profile.d/colorxzgrep.sh
/etc/profile.d/colorzgrep.csh
/etc/profile.d/colorzgrep.sh
/etc/profile.d/csh.local
/etc/profile.d/debuginfod.csh
/etc/profile.d/debuginfod.sh
/etc/profile.d/gawk.csh
/etc/profile.d/gawk.sh
/etc/profile.d/lang.csh
/etc/profile.d/lang.sh
/etc/profile.d/less.csh
/etc/profile.d/less.sh
/etc/profile.d/sh.local
/etc/profile.d/which2.csh
/etc/profile.d/which2.sh
/root/.bash_history
/root/.bash_logout
/root/.bash_profile
/root/.bashrc
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>
- domain
- a user name
- a group name, with
@group syntax
- the wildcard
*, for default entry
- the wildcard
%, can be also used with %group syntax, for maxlogin limit
- NOTE: group and wildcard limits are not applied to root.
To apply a limit to the root user, must be the literal username root.
- type
- "soft" for enforcing the soft limits
- "hard" for enforcing hard limits
- item
core - limits the core file size (KB)
data - max data size (KB)
fsize - maximum filesize (KB)
memlock - max locked-in-memory address space (KB)
nofile - max number of open file descriptors
rss - max resident set size (KB)
stack - max stack size (KB)
cpu - max CPU time (MIN)
nproc - max number of processes
as - address space limit (KB)
maxlogins - max number of logins for this user
maxsyslogins - max number of logins on the system
priority - the priority to run user process with
locks - max number of file locks the user can hold
sigpending - max number of pending signals
msgqueue - max memory used by POSIX message queues (bytes)
nice - max nice priority allowed to raise to values: [-20, 19]
rtprio - max realtime priority
chroot - change root to directory (Debian-specific)
Linux
2016-01-28
先说明一下 Linux 的运行级别,然后使用 runlevel、init、chkconfig 等几个命令实现开机启动任务的管理。
Linux
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
Linux ShellScripting
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
Linux CentOS
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 主线版本
参考