K8S内核参数配置
内核参数 | 值 | 说明 |
net.bridge.bridge-nf-call-ip6tables | 1 | 要求iptables对bridge的数据进行处理。 |
net.bridge.bridge-nf-call-iptables | 1 | 要求iptables对bridge的数据进行处理。 |
net.ipv4.ip_forward | 1 | Linux系统具有路由转发功能,容器跨主机网络桥接模式,需要转发数据包。 |
net.ipv4.conf.all.forwarding | 1 | 开启所有网卡的转发功能 |
net.ipv4.neigh.default.gc_thresh1 | 4096 | 存在于ARP高速缓存中的最少个数,如果少于这个数,垃圾收集器将不会运行 |
net.ipv4.neigh.default.gc_thresh2 | 6144 | 保存在 ARP 高速缓存中的最多的记录软限制. 垃圾收集器在开始收集前,允许记录数超过这个数字,在创建新表项时如果发现5秒没有刷新过,那么进行强制回收 |
net.ipv4.neigh.default.gc_thresh3 | 8192 | ARP缓存中允许的最大IPV4条目; 达到这么多条目时,垃圾收集会运行。 |
net.ipv4.neigh.default.gc_interval | 60 | 清理间隔 (默认30s) |
net.ipv4.neigh.default.gc_stale_time | 120 | 检查过期邻居项arp条目频率 https://www.jianshu.com/p/78eeab8e5e64 |
kernel.perf_event_paranoid | -1 | 允许perf收集系统信息 (为了出问题快速定为) |
net.ipv4.tcp_slow_start_after_idle | 0 | 禁用TCP SSR(Slow-StartRestart,慢启动重启)对于那些会出现突发空闲的长周期TCP连接(比如HTTP的keep-alive连接)有很大的影响 |
net.core.rmem_max | 16777216 | 接收套接字缓冲区大小的最大值(以字节为单位)。 |
net.core.wmem_max | 16777216 | 定义发送窗口的最大大小;对于更大的 BDP 来说,这个大小也应该更大 |
net.core.somaxconn | 32768 | Linux kernel参数,表示socket监听的backlog(监听队列)上限 |
fs.inotify.max_user_watches | 524288 | 表示同一用户同时可以添加的watch数目(watch一般是针对目录,决定了同时同一用户可以监控的目录数量) 默认值 8192 在容器场景下偏小,在某些情况下可能会导致 inotify watch 数量耗尽,使得创建 Pod 不成功或者 kubelet 无法启动成功,将其优化到 524288 |
kernel.softlockup_all_cpu_backtrace | 1 | softlookup时捕获更多调试信息 (为了出问题快速定为) |
kernel.softlockup_panic | 0 | 关闭内核异常自动重启机制 |
kernel.watchdog_thresh | 30 | 循环超 |
fs.file-max | 2097152 | max-file 表示系统级别的能够打开的文件句柄的数量, 一般如果遇到文件句柄达到上限时,会碰到 # Too many open files 或者 Socket/File: Can’t open so many files 等错误 |
fs.inotify.max_user_instances | 8192 | 表示每一个real user ID可创建的inotify instatnces的数量上限,默认128. |
fs.inotify.max_queued_events | 16384 | 表示调用inotify_init时分配给inotify instance中可排队的event的数目的最大值,超出这个值的事件被丢弃,但会触发IN_Q_OVERFLOW事件 |
vm.max_map_count | 262144 | max_map_count文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量 |
fs.may_detach_mounts | 1 | 允许文件卸载 |
net.core.netdev_max_backlog | 16384 | 每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目 |
net.ipv4.tcp_wmem | 4096 12582912 16777216 | # 第一个值是为 socket 的发送缓冲区分配的最少字节数 # 第二个值是默认值(该值会被wmem_default覆盖),缓冲区在系统负载不重的情况下可以增长到这个值 # 第三个值是发送缓冲区空间的最大字节数(该值会被 wmem_max 覆盖 |
net.ipv4.tcp_max_syn_backlog | 8096 | 接受SYN同包的最大客户端数量 |
net.ipv4.tcp_rmem | 4096 12582912 16777216 | 与 tcp_wmem 类似,不过它表示的是为自动调优所使用的接收缓冲区的值 |
net.ipv6.conf.all.disable_ipv6 | 1 | 禁用ipv6 |
net.ipv6.conf.default.disable_ipv6 | 1 | 禁用ipv6 |
net.ipv6.conf.lo.disable_ipv6 | 1 | 禁用ipv6 |
kernel.yama.ptrace_scope | 0 | 这用于控制进程的追踪 (为了出问题快速定为方便应用软件的开发和调试) #0-默认附加安全权限。 #1-受限附件。只有子进程加上普通权限。 #2-仅限管理员附加。仅具有CAP_SYS_PTRACE的可执行文件。 #3-无附件。没有任何进程可以调用ptrace。在下一次启动前不可撤消。 |
vm.swappiness | 0 | 关闭swap |
kernel.core_uses_pid | 1 | 生成core文件,后缀是否带pid 1:带; 0 :不带(为了出问题快速定为方便应用软件的开发和调试) |
net.ipv4.conf.default.accept_source_route | 0 | 处理无源路由的包 |
net.ipv4.conf.all.accept_source_route | 0 | 处理无源路由的包 |
net.ipv4.conf.default.promote_secondaries | 1 | promote_secondaries为1,当Primary ip被删除后,它的第1个Secondary ip将继承为Primary ip。 |
net.ipv4.conf.all.promote_secondaries | 1 | promote_secondaries为1,当Primary ip被删除后,它的第1个Secondary ip将继承为Primary ip。 |
fs.protected_hardlinks | 1 | 用于限制普通用户建立硬链接 ,0表示限制,1表示不限制 |
fs.protected_symlinks | 1 | 用于限制普通用户建立软链接 0:不限制用户建立软链接 1:限制,允许用户建立软连接的情况是 软连接所在目录是全局可读写目录或者软连接的uid与跟从者的uid匹配,又或者目录所有者与软连接所有者匹配 |
net.ipv4.conf.all.rp_filter | 0 | 关闭反向路由校验 |
net.ipv4.conf.default.rp_filter | 0 | 关闭反向路由校验 |
net.ipv4.conf.default.arp_announce | 2 | 始终使用与目标IP地址对应的最佳本地IP地址作为ARP请求的源IP地址 |
net.ipv4.conf.lo.arp_announce | 2 | 始终使用与目标IP地址对应的最佳本地IP地址作为ARP请求的源IP地址 |
net.ipv4.conf.all.arp_announce | 2 | 始终使用与目标IP地址对应的最佳本地IP地址作为ARP请求的源IP地址 |
net.ipv4.tcp_max_tw_buckets | 5000 | 表示系统同时保持TIME_WAIT套接字的最大数量 |
net.ipv4.tcp_syncookies | 1 | 表示开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理 |
net.ipv4.tcp_fin_timeout | 30 | 表示如果套接字由本端要求关闭,这个参数决定了它保持在FIN-WAIT-2状态的时间。 |
net.ipv4.tcp_synack_retries | 2 | 活动TCP连接重传次数 |
kernel.sysrq | 1 | 关闭SysRq |
net.ipv4.route.gc_interval | 60 | (不存在,但生产系统有) |
fs.aio-max-nr | 1048576 | (不存在,但生产系统有) |
net.core.rmem_default | 129024 | (不存在,但生产系统有) (应该和net.core.rmem_max重复) |
net.core.wmem_default | 129024 | (不存在,但生产系统有) (应该和net.core.rmem_max重复) |
vm.drop_cache | 3 | (不存在,但生产系统有) |
kernel.pid_max | 102400 | (不存在,但生产系统有) |
net.ipv4.tcp_timestamps | 1 | (不存在,但生产系统有) |
net.ipv4.tcp_tw_recycle | 0 | (不存在,但生产系统有) |
net.ipv4.tcp_tw_reuse | 1 | (不存在,但生产系统有) |
vm.dirty_background_ratio | 5 | (不存在,但生产系统有) |
vm.dirty_ratio | 10 | (不存在,但生产系统有) |
一把搂
echo "
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.ip_forward=1
net.ipv4.conf.all.forwarding=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
net.ipv4.neigh.default.gc_interval=60
net.ipv4.neigh.default.gc_stale_time=120
kernel.perf_event_paranoid=-1
net.ipv4.tcp_slow_start_after_idle=0
fs.inotify.max_user_watches=524288
fs.file-max=2097152
fs.inotify.max_user_instances=8192
fs.inotify.max_queued_events=16384
kernel.softlockup_all_cpu_backtrace=1
kernel.softlockup_panic=1
vm.max_map_count=262144
net.core.netdev_max_backlog=16384
net.ipv4.tcp_wmem=4096 12582912 16777216
net.core.wmem_max=16777216
net.ipv4.tcp_rmem=4096 12582912 16777216
net.core.rmem_max=16777216
net.core.somaxconn=32768
net.ipv4.tcp_max_syn_backlog=8192
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1
vm.swappiness=0
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.all.accept_source_route=0
fs.protected_hardlinks=1
fs.protected_symlinks=1
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce=2
net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.all.arp_announce=2
net.ipv4.tcp_max_tw_buckets=55000
net.ipv4.tcp_fin_timeout=30
net.ipv4.tcp_synack_retries=2
kernel.sysrq=1
net.ipv4.route.gc_interval=60
fs.aio-max-nr=1048576
net.core.rmem_default = 129024
net.core.wmem_default = 129024
kernel.pid_max=102400
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 1
vm.dirty_background_ratio=5
vm.dirty_ratio=10
" >> /etc/sysctl.conf
sysctl -p
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。