设置 Linux 内核运行时参数的规定方法是什么?我有时看到人们会将这些设置在诸如/etc/rc.local.
这真的是这样做的正确方法吗?
我在 Arch Linux 计算机上运行的内核版本如下:
[root@router ~ ]$ uname -a
Linux router 4.2.5-1-ARCH #1 SMP PREEMPT Tue Oct 27 08:13:28 CET 2015
Run Code Online (Sandbox Code Playgroud)
我注意到每次我通过sysctl -a管道输入 grep 命令时我都会收到以下消息
[root@router ~ ]$ sysctl -a | grep no_meaning
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
...
Run Code Online (Sandbox Code Playgroud)
对这些文件运行 cat:
[root@router ~ ]$ cat /proc/sys/net/ipv6/conf/all/stable_secret
cat: /proc/sys/net/ipv6/conf/all/stable_secret: Input/output error
[root@router ~ ]$ ls -hl /proc/sys/net/ipv6/conf/all/stable_secret
-rw------- 1 root root 0 Dec 24 14:57 /proc/sys/net/ipv6/conf/all/stable_secret
Run Code Online (Sandbox Code Playgroud)
到目前为止我还没有看到任何不良影响,但我想知道这是否正常,特别是这些stable_secret键的功能是什么?提前致谢。
这是在 Linux 操作系统上。
我发现在某些机器上,在过滤net.bridge.bridge-nf-call-iptables之前变量并不存在。我还看到有些机器加载了模块并且本身引入了这个变量。modprobebr_netfilterbridge
有没有办法知道我应该加载哪个模块才能获取特定变量?
我在哪里可以找到sysctl.conf基于最后一场比赛的官方文档?
因此,/etc/sysctl.conf文件中有两个条目:
vm.swappiness=10
vm.swappiness=11
Run Code Online (Sandbox Code Playgroud)
哪个会赢?最后一个?如果/etc/sysctl.d目录中有文件会发生什么?
当我们sysctl -p在我们的 rhel 7.2 上运行时,server1我们得到
sysctl -p
fs.file-max = 500000
vm.swappiness = 10
vm.vfs_cache_pressure = 50
sysctl: cannot stat /proc/sys/pcie_aspm: No such file or directory
net.core.somaxconn = 1024
# ls /proc/sys/pcie_aspm
ls: cannot access /proc/sys/pcie_aspm: No such file or directory
Run Code Online (Sandbox Code Playgroud)
但是,当我们运行sysctl -p其他的server2如
我们得到了没有错误的好结果
sysctl -p
fs.file-max = 500000
vm.swappiness = 10
vm.vfs_cache_pressure = 50
net.core.somaxconn = 1024
Run Code Online (Sandbox Code Playgroud)
该文件 -/proc/sys/pcie_aspm此服务器上也不存在 ( server2)
那么为什么sysctl -p失败server1呢?
当我运行lsmod或 时sudo lsmod,我收到一条错误消息:
libkmod: ERROR ../libkmod/libkmod-module.c:1655 kmod_module_new_from_loaded: could not open /proc/modules: No such file or directory
Error: could not get list of modules: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我在很多论坛上搜索过,但无法找到解决方案。我在 Linux 的 Windows 子系统上运行 Debian。
我最近还试图编辑该sysctl.conf文件以禁用ipv6。我添加了以下几行:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
Run Code Online (Sandbox Code Playgroud)
当我尝试时sudo sysctl -p,它返回了这个错误:
sysctl: cannot stat /proc/sys/net/ipv6/conf/all/disable_ipv6: No such file or directory
sysctl: cannot stat /proc/sys/net/ipv6/conf/default/disable_ipv6: No such file or directory
sysctl: cannot stat /proc/sys/net/ipv6/conf/lo/disable_ipv6: No …Run Code Online (Sandbox Code Playgroud) 我想使用 sysctl 更改两个值。一个是sysctl vm.swappiness=10和其他sysctl kernel.sysrq=1。但是,当我运行时sysctl -p,它告诉我sysctl: cannot open "/etc/sysctl.conf": No such file or directory,但sysctl -a返回this。所以,我想问一下我的系统存储sysctl配置在哪里?
在尝试解决问题的过程中,当我打算删除/etc/sysctl.conf时,我不小心删除了/sbin/sysctl。
当我运行时sysctl,我收到错误消息
The program 'sysctl' is currently not installed. You can install it by typing:
sudo apt-get install procps
Run Code Online (Sandbox Code Playgroud)
当我尝试两者时install,upgrade它说procps is already the newest version。我也尝试删除 procps 并重新安装它,但出现此错误:
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to …Run Code Online (Sandbox Code Playgroud) 我在我的系统日志中kernel.perf_event_max_sample_rate看到发生了变化。
我想知道我是否可以编写一个快速脚本来每隔几分钟记录一次这个变量。目前是:
sysctl -a | grep kernel.perf_event_max_sample_rate
Run Code Online (Sandbox Code Playgroud)
在手册页 sysctl 中说
sysctl- 在运行时配置内核参数
这是否意味着我的脚本将获得内核启动时设置的参数?它会带来变化吗?
我想要grep一个特定的内核设置如下
$ sudo sysctl -a --ignore | grep -i max_map_count 2>/dev/null
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.docker0.stable_secret"
sysctl: reading key "net.ipv6.conf.enp2s0.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
sysctl: reading key "net.ipv6.conf.wlp3s0.stable_secret"
vm.max_map_count = 262144
Run Code Online (Sandbox Code Playgroud)
由于我既忽略了关于未知键的信息(即--ignore选项),又将潜在的错误输出重定向到/dev/null,这些reading jey行打印了什么?
我这样做是为了在我的新安装的 Debian 中执行“brave browser”。
sudo sysctl -w kernel.unprivileged_userns_clone=1
Run Code Online (Sandbox Code Playgroud)
我已经读过这可能对我的机器安全存在潜在风险,如何恢复此命令?
谢谢。
sysctl 实用程序允许 Linux 管理员在运行时查询和修改内核参数。例如,要将 Linux 系统的 swappiness 更改为 0,我们可以:
echo 0 > /proc/sys/vm/swappiness或者我们可以使用sysctl:
sysctl -w vm.swappiness=0为了使值持久,Archwiki建议写入vm.swappiness=0 到/etc/sysctl.d/99-swappiness.conf文件中。
对于持久无声开机,Archwiki建议将写入kernel.printk = 3 3 3 3到/etc/sysctl.d/20-quiet-printk.conf
同样99-sysrq.conf,我的系统上有一个也可以在没有号码的情况下工作。
Archwiki 有一个sysctl 页面,其中提到了数字的重要性:
注意:从 207 和 21x 版本开始,systemd仅应用来自
/etc/sysctl.d/*.conf和 的设置/usr/lib/sysctl.d/*.conf。如果您已自定义/etc/sysctl.conf,则需要将其重命名为/etc/sysctl.d/99-sysctl.conf. 如果您有 eg/etc/sysctl.d/foo,则需要将其重命名为/etc/sysctl.d/foo.conf.
这里的99-swappiness.conf和中的数字20-quiet-printk.conf表示什么?
sysctl ×12
kernel ×4
linux ×3
debian ×2
apt ×1
arch-linux ×1
ipv6 ×1
linux-kernel ×1
magic-sysrq ×1
modprobe ×1
parameter ×1
perf-event ×1
proc ×1
rhel ×1
security ×1