linux不会自动停止敏感加固任务,需手动配置温度监控与条件触发机制,在cpu温度≥85℃时暂停audit-scan-thermal、lynis扫描等可中断加固任务,并在温度回落至75℃以下持续2分钟后再恢复。

Linux本身不会自动“停止敏感加固任务”——它没有内置的“加固任务”概念,也不主动识别哪些进程属于“敏感加固”。但你可以通过温度监控 + 条件触发机制,让系统在CPU温度超过安全阈值(如85℃)时,自动暂停或终止特定高负载、非关键、可中断的加固类操作(例如:实时入侵检测扫描、频繁的SELinux策略重载、自动化漏洞验证脚本、密钥轮转批量任务等)。这本质是“热感知的任务调度控制”,需手动配置。
CPU温度监控:确认读数准确可靠
先确保你能稳定获取真实温度:
- 安装并校准
lm-sensors:sudo apt install lm-sensors && sudo sensors-detect --auto,然后运行sensors查看输出中是否有Package id 0或Core类温度项 - 直接读取内核thermal接口更轻量:
cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null | awk '{if($1 > max) max=$1} END{print max/1000}',该命令返回当前最高温度(单位℃) - 注意区分传感器来源:优先选用
thermal_zone0(通常对应SoC封装温度)或coretemp驱动数据,避免误用主板芯片组温度(如it87)
定义“敏感加固任务”并标记其可控性
不是所有加固操作都适合自动暂停。你需要明确哪些任务满足三个条件:可识别、可中断、非核心依赖。例如:
-
适合暂停:每日凌晨执行的
auditctl -s | grep -q "enabled" && ausearch -m avc -ts yesterday | aureport -a(AVC日志分析)、后台运行的lynis audit system扫描、定时semodule -i *.pp策略安装 -
禁止暂停:正在运行的
systemd-journald、auditd守护进程、内核模块加载(insmod)、实时SELinux上下文重标定(restorecon -R) - 建议为可暂停任务加统一标识,比如启动时加上
--tag=thermal-safe参数,或在ps aux中可见的特征名(如audit-scan-thermal)
编写温度响应脚本并设置周期检查
写一个轻量级守护脚本(如/usr/local/bin/thermal-guard.sh),逻辑清晰、无依赖、不阻塞:
- 每30秒读取一次最高温度:
temp=$(cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null | sort -n | tail -1) - 若
$temp≥ 85000(即85℃),则查找并暂停匹配进程:pkill -f "audit-scan-thermal\|lynis.*scan\|semodule.*batch" - 恢复条件可设为温度回落至75℃以下持续2分钟,再用
systemctl start xxx.service或重新启动脚本 - 用
systemd托管该脚本:创建/etc/systemd/system/thermal-guard.service,启用Restart=always和StartLimitIntervalSec=0
与系统温控子系统协同,避免冲突
Linux Thermal子系统已接管CPU降频(cpufreq)和风扇调速(fan cooling device),你的脚本不应重复干预硬件层:
- 不要在脚本里执行
echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor——这应由thermald或内核thermal governor管理 - 确认
thermald已启用:sudo systemctl enable --now thermald,它会自动响应thermal_zone事件,比自定义脚本更稳定 - 你的脚本只做“软件层节流”:暂停用户态加固任务,而非替代内核温控逻辑











