背景介绍
- 在一次压力测试过程中,出现了文件句柄数超过配置的问题。当时自己使用ulimit命令修改了,后续与运维沟通的过程中,运维发我了一堆指令,具体内容见下文。
- 在压测过程中,建议先执行linux内核优化脚本,避免因压测机的环境影响压测执行和压测结果。
linux内核优化
脚本
#! /bin/bash
echo "* soft nofile 102400">>/etc/security/limits.conf
echo "* hard nofile 102400">>/etc/security/limits.conf
echo "* soft nproc 102400">>/etc/security/limits.conf
echo "* hard nproc 102400">>/etc/security/limits.conf
>/etc/security/limits.d/90-nproc.conf
echo "* soft nproc 102400">>/etc/security/limits.d/90-nproc.conf
echo "root soft nproc unlimited">>/etc/security/limits.d/90-nproc.conf
echo "iibs soft nproc unlimited">>/etc/security/limits.d/90-nproc.conf
echo "net.ipv4.tcp_keepalive_time = 1800
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 10
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_tw_recycle = 0
net.core.rmem_max = 16777216
net.core.rmem_default = 16777216
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_reuse = 1
kernel.pid_max = 4194304
net.core.wmem_default = 16777216
net.core.wmem_max = 16777216
net.ipv4.neigh.default.gc_interval = 30
net.ipv4.neigh.default.gc_stale_time = 120
net.ipv4.neigh.default.gc_thresh1 = 2048
net.ipv4.neigh.default.gc_thresh2 = 8192
net.ipv4.neigh.default.gc_thresh3 = 20480
net.ipv4.tcp_timestamps = 0
net.ipv4.ip_local_port_range = 1024 65535" >>/etc/sysctl.conf
脚本释义
- http://www.ttlsa.com/linux/linux-kernel-tuning-section-parameter-description/
- https://blog.csdn.net/qq_22310551/article/details/123449772
- 可能需要使用管理员账号,切换命令:sudo su -
- https://blog.csdn.net/weixin_44197719/article/details/124978890