CentOS如何设置才不卡:高效运行配置指南
系统更新与精简安装
安装时选择Minimal Install
基础环境,完成后执行:
yum update -y && yum upgrade -y
移除无用软件包:yum autoremove
服务管理策略
- 禁用非必要服务:
systemctl disable postfix cups abrtd
- 限制服务并发:
vim /etc/systemd/system.conf
修改DefaultLimitNOFILE
参数
内核参数调优
vim /etc/sysctl.conf
# 增加以下配置
vm.swappiness = 10
net.core.somaxconn = 4096
fs.file-max = 65536
net.ipv4.tcp_tw_reuse = 1
执行sysctl -p
立即生效
文件系统优化
修改/etc/fstab
挂载参数:
noatime,data=writeback,barrier=0
内存管理配置
- 调整缓存策略:
echo 3 > /proc/sys/vm/drop_caches
- 配置大页内存:
vim /etc/grub.conf
添加transparent_hugepage=always
资源监控方案
安装诊断工具:
yum install htop iotop iftop -y
配置日志轮转:vim /etc/logrotate.conf
调整保留周期
图形界面优化
- 服务器环境建议使用:
systemctl set-default multi-user.target
- 桌面环境可安装轻量级GUI:
yum groupinstall "Xfce"
定期维护建议
- 设置每周自动清理:
crontab -e
添加0 3 * * 6 yum clean all
- 监控启动项:
chkconfig --list | grep 3:on