Debian系统中哪些配置可以优化
导读:Debian系统可优化的关键配置 一 软件源与更新 更换为就近镜像源(如清华/中科大),显著提升 apt 下载速度;备份原文件后再编辑 /etc/apt/sources.list。示例(Debian 12 Bookworm): deb...
Debian系统可优化的关键配置
一 软件源与更新
- 更换为就近镜像源(如清华/中科大),显著提升 apt 下载速度;备份原文件后再编辑 /etc/apt/sources.list。示例(Debian 12 Bookworm):
- deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
- deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free
- deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free
- deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm/updates main contrib non-free
- 更新索引并全量升级:sudo apt update & & sudo apt upgrade -y
- 清理无用包与缓存:sudo apt autoremove -y & & sudo apt clean
- 如安装介质源干扰,注释掉 /etc/apt/sources.list 中以 deb cdrom: 开头的行,避免从光盘源取包。
二 启动与服务精简
- 查看与禁用不需要的服务:sudo systemctl list-unit-files --type=service;对桌面或服务器场景可关闭如 cups(打印)、bluetooth(蓝牙)等无用服务:sudo systemctl disable --now cups bluetooth(按需执行)。
- 精简开机自启:仅保留必要服务,减少并行启动与常驻占用,缩短开机时间并降低内存常驻。
三 内核与网络参数
- 内存与VFS缓存策略(/etc/sysctl.conf):
- vm.swappiness=10(更倾向使用内存而非交换)
- vm.vfs_cache_pressure=50(平衡目录/索引节点缓存回收)
- 使配置生效:sudo sysctl -p
- 网络与文件句柄(按需):
- 复用 TIME_WAIT 连接:sudo sysctl -w net.ipv4.tcp_tw_reuse=1
- 提升系统文件描述符上限:sudo sysctl -w fs.file-max=65536
- 网卡队列优化(示例网卡名 ens33):sudo ethtool -G ens33 rx 2048 tx 1024(提升高并发网络吞吐,需网卡与驱动支持)。
四 存储与文件系统
- 使用 LVM 便于在线扩容、快照与灵活分区管理(适合系统盘与数据盘分层的场景)。
- 选择高性能文件系统(如 ext4 或 xfs),并结合工作负载设置合适的挂载选项(如 noatime 减少元数据写入;barrier 与日志策略按数据安全与性能权衡)。
- 例行维护:核对磁盘空间(df -h)、I/O 与延迟(iostat),及时扩容或迁移热点数据,避免 I/O 瓶颈。
五 安全与运维实践
- 最小权限与加固:创建普通管理员用户并加入 sudo 组,避免直接使用 root 登录;定期应用安全补丁(sudo apt update & & sudo apt upgrade)。
- 防火墙:安装并启用 UFW,仅放行必要端口(如 OpenSSH 22、HTTP 80、HTTPS 443):sudo apt install ufw & & sudo ufw enable & & sudo ufw allow 22,80,443/tcp。
- 监控与告警:部署 htop/vmstat/iostat/netstat/free/df 等工具做基线观测,结合阈值告警与日志审计,持续优化资源配置。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: Debian系统中哪些配置可以优化
本文地址: https://pptw.com/jishu/774754.html
