内核参数调优
/etc/sysctl.conf,优化网络和内存参数:net.core.somaxconn=65535 # 提升TCP连接队列长度
vm.swappiness=10 # 降低内存置换倾向
vm.dirty_ratio=15 # 控制脏页比例,减少磁盘写入频率
执行sysctl -p使配置生效。文件描述符限制
ulimit -n 65535/etc/security/limits.conf,添加* soft nofile 65535。关闭非必要服务
systemctl stop firewalld NetworkManager # 关闭防火墙(根据实际需求)
systemctl disable firewalld NetworkManager
调整CPU调度策略
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governorecho performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
或通过cpupower工具:cpupower frequency-set -g performance。进程绑定与优先级
taskset -cp 0,1 <pid>。nice -n -5 <command>(提高优先级),renice -n 10 <pid>(降低优先级)。内存分配与回收
vm.overcommit_memory=1,避免OOM。echo 3 > /proc/sys/vm/drop_caches(谨慎使用,可能影响性能)。大页内存(Huge Pages)
echo 2048 > /proc/sys/vm/nr_hugepages # 设置大页数量
mount -t hugetlbfs hugetlbfs /dev/hugepages # 挂载大页文件系统
I/O调度器选择
cat /sys/block/sda/queue/schedulernoop或deadline(适合SSD):echo noop > /sys/block/sda/queue/scheduler
永久修改需在/etc/default/grub中添加elevator=noop并更新GRUB。文件系统优化
noatime参数:mount -o remount,noatime /dev/sda1 /。mkfs.xfs /dev/sdb1。TCP参数调优
/etc/sysctl.conf:net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_window_scaling=1
执行sysctl -p生效。网卡多队列与中断绑定
ethtool -l eth0(查看队列数),ethtool -L eth0 combined 4(设置多队列)。echo 1 > /proc/irq/XX/smp_affinity(XX为中断号)。top/htop:查看进程CPU/内存占用。iostat -x 1:监控磁盘I/O负载。vmstat 1:分析内存、CPU、I/O状态。perf top:定位CPU热点函数。strace/ltrace:跟踪系统调用,排查进程阻塞问题。参考来源: