问题描述
我需要知道Linux的所有发行版是否都具有 sysctl.conf ,位于 /etc/sysctl.conf
下有人告诉我,Arch Linux没有。在某些发行版中,可以将上述路径下设置的配置替换为另一个文件吗?
解决方法
并非总是如此。 RHEL8有一个虚拟文件,引用了sysctl.d
的手册页。
man sysctl.d
可以阅读很多地方。
NAME
sysctl.d - Configure kernel parameters at boot
SYNOPSIS
/etc/sysctl.d/*.conf
/run/sysctl.d/*.conf
/usr/lib/sysctl.d/*.conf
在框中运行sysctl --system
的RHEL8会按以下顺序评估文件:
sysctl --system
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
* Applying /usr/lib/sysctl.d/50-coredump.conf ...
* Applying /usr/lib/sysctl.d/50-default.conf ...
* Applying /usr/lib/sysctl.d/50-libkcapi-optmem_max.conf ...
* Applying /etc/sysctl.d/50-libreswan.conf ...
* Applying /usr/lib/sysctl.d/50-pid-max.conf ...
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.conf ...
,
/etc/sysctl.d/*.conf
/run/sysctl.d/*.conf
/usr/local/lib/sysctl.d/*.conf
/usr/lib/sysctl.d/*.conf
/lib/sysctl.d/*.conf
/etc/sysctl.conf
The paths where sysctl preload files usually exist. See also sysctl
option --system.
来自man sysctl:
--system
Load settings from all system configuration files. Files are
read from directories in the following list in given order
from top to bottom. Once a file of a given filename is
loaded,any file of the same name in subsequent directories is
ignored.
/etc/sysctl.d/*.conf
/run/sysctl.d/*.conf
/usr/local/lib/sysctl.d/*.conf
/usr/lib/sysctl.d/*.conf
/lib/sysctl.d/*.conf
/etc/sysctl.conf
在现代系统上,sysctl
配置是在使用systemd-sysctl.service
启动时加载的。来自man systemd-sysctl:
systemd-sysctl.service is an early boot service that configures sysctl(8) kernel parameters by invoking
/usr/lib/systemd/systemd-sysctl.
When invoked with no arguments,/usr/lib/systemd/systemd-sysctl applies all directives from configuration files listed in
sysctl.d(5).
据我了解,文件是从上到下加载的,因此存储在/etc/sysctl.conf
中的配置可能会覆盖之前设置的配置。
专业提示:/usr/lib/systemd/systemd-sysctl --cat-config
任何分发,供应商和程序包管理器以及其他已分发文件的人都可以在任何这些目录中存储配置。软件包会将配置存储在/usr/lib/sysctl.d/*.conf
中。通常,/etc/sysctl.conf
和/etc/sysctl.d/*.conf
只留给手动管理员工作。