【问题标题】:Is the sysctl.conf file always structured as /etc/sysctl.conf?sysctl.conf 文件的结构是否始终为 /etc/sysctl.conf?
【发布时间】:2021-01-23 14:17:36
【问题描述】:

我需要知道是否所有 Linux 发行版的 sysctl.conf 都在 /etc/sysctl.conf

有人告诉我 Arch Linux 没有。某些发行版中的其他文件是否可以覆盖上述路径下设置的配置?

【问题讨论】:

  • 你做了什么研究?您至少阅读过手册页吗?
  • 是的,如果我问是因为我找不到明确的答案。

标签: linux sysctl


【解决方案1】:

并非总是如此。 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

在 RHEL8 上运行sysctl --system 按以下顺序评估文件:

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 但我无法确认哪个优先于另一个。你知道 /etc/sysctl.conf 是否会覆盖其他文件(如果存在)?
  • 如果您运行(注意它不是空运行命令)sysctl --system,它将加载内容并告诉您按哪个顺序运行,我已经在我的一台服务器上使用示例运行更新了答案。
【解决方案2】:

来自man 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 仅供手动管理员工作。

【讨论】:

  • 谢谢,我错过了
猜你喜欢
  • 2014-04-16
  • 2015-10-16
  • 2012-03-04
  • 2020-07-19
  • 1970-01-01
  • 1970-01-01
  • 2015-11-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多