我需要调整内核参数,因为 Ubuntu 最小安装是为具有 256 MB RAM 的机器创建的,而我们的服务器有 32 GB。我遇到的问题是,当我执行命令 sysctl -p /etc/sysctl.conf 时,服务器会在一分钟内恢复到原始设置。
root@mino /scripts/crons/tweaks # sysctl -p /etc/sysctl.conf
vm.swappiness = 10
vm.dirty_ratio = 60
vm.dirty_background_ratio = 2
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.core.rmem_max = 12582912
net.core.rmem_default = 31457280
net.core.wmem_default = 31457280
net.core.wmem_max = 12582912
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 65536
net.core.optmem_max = 25165824
net.ipv4.tcp_rfc1337 = 1
net.ipv4.ip_local_port_range = 2000 65535
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_sack = 0
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_max_tw_buckets = 1440000
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_challenge_ack_limit = 999999999
net.nf_conntrack_max = 10000000
net.netfilter.nf_conntrack_tcp_loose = 0
net.netfilter.nf_conntrack_max = 10000000
net.netfilter.nf_conntrack_tcp_timeout_close = 10
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 10
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 10
net.netfilter.nf_conntrack_tcp_timeout_last_ack = 10
net.netfilter.nf_conntrack_tcp_timeout_syn_recv = 10
net.netfilter.nf_conntrack_tcp_timeout_syn_sent = 10
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 10
net.netfilter.nf_conntrack_tcp_timeout_established = 10
net.ipv4.tcp_mem = 65536 131072 262144
net.ipv4.udp_mem = 65536 131072 262144
net.ipv4.tcp_rmem = 8192 87380 16777216
net.ipv4.udp_rmem_min = 16384
net.ipv4.tcp_wmem = 8192 65536 16777216
net.ipv4.udp_wmem_min = 16384
fs.file-max = 3500000
root@mino /scripts/crons/tweaks # /sbin/sysctl -a|grep -i nf_conntrack_max
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.em1.stable_secret"
sysctl: reading key "net.ipv6.conf.em2.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
net.netfilter.nf_conntrack_max = 10000000
net.nf_conntrack_max = 10000000
root@mino /scripts/crons/tweaks # date
Sat Jan 27 08:30:50 PST 2018
root@mino /scripts/crons/tweaks # date
Sat Jan 27 08:30:57 PST 2018
root@mino /scripts/crons/tweaks # date
Sat Jan 27 08:31:02 PST 2018
root@mino /scripts/crons/tweaks # /sbin/sysctl -a|grep -i nf_conntrack_max
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.em1.stable_secret"
sysctl: reading key "net.ipv6.conf.em2.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
net.netfilter.nf_conntrack_max = 10000000
net.nf_conntrack_max = 10000000
root@mino /scripts/crons/tweaks # date
Sat Jan 27 08:31:20 PST 2018
root@mino /scripts/crons/tweaks # /sbin/sysctl -a|grep -i nf_conntrack_max
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.em1.stable_secret"
sysctl: reading key "net.ipv6.conf.em2.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
net.netfilter.nf_conntrack_max = 65536
net.nf_conntrack_max = 65536
net.nf_conntrack_max 设置为 65536 太低了,一个简单的 syn 攻击就会触发防火墙,所有数据包都会被丢弃。相当烦人。我的 /etc/rc.local fdile 中也有相同的命令,并在其他线程中阅读了有关 debian / ubuntu 错误的信息。
运行 Ubuntu 14.04 4.4.0-112-generic #135-Ubuntu SMP 2018 年 1 月 19 日星期五 11:48:36 UTC x86_64 x86_64 x86_64 GNU/Linux
我从以下网站进行了研究:
答案1
该系统及其文件是否受到、或其他类似自动化工具/etc/sysctl.conf
的控制?Puppet
SaltStack
Ansible
如果是这样,您将需要通过该软件进行更改,因为它将继续恢复任何手动更改以维持指定的配置。