Skip to content

l2ktech/ubuntu-AutoTemp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ubuntu 自动温度/风扇控制系统

Public Portfolio Summary

This repository is a public workstation-operations support project for Ubuntu temperature monitoring and fan-control automation. It documents CPU/GPU fan-control scripts, systemd integration, temperature status commands, and practical hardware-tuning notes for GPU development workstations.

For interviews, use it as supporting evidence for infrastructure reliability around AI/robotics workstations: Linux service management, sensor tooling, NVIDIA fan-control automation, operational runbooks, and safe manual fallback commands.

Evidence Entry Points

Public Boundary

This repository should stay as a generic workstation automation reference. Do not publish private hostnames, live sensor dumps tied to a personal machine, remote access details, production monitoring logs, credentials, or hardware serial numbers. Hardware model names and example hwmon values are illustrative and must be revalidated per machine.

Ubuntu 22.04 自动温度监控和风扇控制解决方案,支持 CPU 和 NVIDIA GPU。

🎯 功能特性

  • CPU风扇自动控制 - 基于 fancontrol,根据温度自动调节
  • GPU风扇自动控制 - 基于 nvidia-settings,支持温度曲线
  • 实时温度监控 - 持续显示 CPU、GPU、主板、NVMe 温度
  • 静音优化 - 支持 10% PWM 低速运行,几乎无声
  • 开机自启 - systemd 服务管理,重启后自动生效
  • 快速查看 - 一键查看所有风扇和温度状态

💻 系统要求

  • 操作系统: Ubuntu 22.04 LTS (其他版本可能需要调整)
  • CPU: AMD Ryzen (已测试 5950X)
  • GPU: NVIDIA (已测试 RTX 4060 Ti)
  • 主板: 支持 PWM 风扇控制 (IT8688 或类似芯片)
  • 权限: root/sudo 权限

📦 安装

快速安装

# 克隆仓库
git clone https://github.com/l2ktech/ubuntu-AutoTemp.git
cd ubuntu-AutoTemp

# 运行安装脚本
sudo bash install.sh

手动安装

# 1. 安装依赖
sudo apt update
sudo apt install -y lm-sensors fancontrol

# 2. 检测传感器
sudo sensors-detect --auto

# 3. 复制脚本文件
sudo cp scripts/* /usr/local/bin/
sudo chmod +x /usr/local/bin/{gpu-fan-control.sh,temp-monitor,fan-status}

# 4. 复制配置文件(需根据你的硬件调整)
sudo cp config/fancontrol.example /etc/fancontrol

# 5. 配置 GPU 风扇控制
sudo nvidia-xconfig --cool-bits=28
# 或手动编辑 /etc/X11/xorg.conf,在 Device 段添加:
# Option "Coolbits" "28"

# 6. 安装 systemd 服务
sudo cp systemd/*.service /etc/systemd/system/
sudo cp systemd/*.timer /etc/systemd/system/
sudo systemctl daemon-reload

# 7. 启用服务
sudo systemctl enable fancontrol
sudo systemctl start fancontrol
sudo systemctl enable gpu-fan-control.timer
sudo systemctl start gpu-fan-control.timer

# 8. 重启(使 X11 配置生效)
sudo reboot

🎮 使用方法

查看温度和风扇状态

fan-status              # 快速查看所有状态
temp-monitor           # 实时监控(按Ctrl+C退出)
sensors                # 查看所有传感器
nvidia-smi             # GPU详细信息

服务管理

CPU风扇控制

sudo systemctl status fancontrol       # 查看状态
sudo systemctl restart fancontrol      # 重启服务
sudo journalctl -u fancontrol -f       # 查看日志

GPU风扇控制

sudo systemctl status gpu-fan-control.timer
sudo /usr/local/bin/gpu-fan-control.sh  # 手动运行一次
sudo journalctl -u gpu-fan-control.service -f

手动控制风扇

CPU风扇(临时)

# 停止自动控制
sudo systemctl stop fancontrol

# 手动设置 PWM (0-255)
echo 150 | sudo tee /sys/class/hwmon/hwmon4/pwm1

# 恢复自动控制
sudo systemctl start fancontrol

GPU风扇(临时)

# 手动设置转速
DISPLAY=:0 nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=50

# 恢复自动
DISPLAY=:0 nvidia-settings -a [gpu:0]/GPUFanControlState=0

⚙️ 配置调整

CPU风扇配置

编辑 /etc/fancontrol

MINTEMP=hwmon4/pwm1=45    # 45°C以下保持最低转速
MAXTEMP=hwmon4/pwm1=75    # 75°C以上全速运行
MINSTART=hwmon4/pwm1=100  # 启动PWM值 (39%)
MINSTOP=hwmon4/pwm1=26    # 维持运转PWM值 (10%)
MINPWM=hwmon4/pwm1=26     # 最低PWM值 (10%)
MAXPWM=hwmon4/pwm1=255    # 最高PWM值 (100%)

重启服务使配置生效:

sudo systemctl restart fancontrol

GPU风扇配置

编辑 /usr/local/bin/gpu-fan-control.sh

if [ $TEMP -lt 40 ]; then
    FAN_SPEED=0      # 自动模式
elif [ $TEMP -lt 60 ]; then
    FAN_SPEED=30     # 30%
elif [ $TEMP -lt 75 ]; then
    FAN_SPEED=60     # 60%
else
    FAN_SPEED=100    # 100%
fi

📊 默认风扇控制策略

CPU风扇

温度 PWM 转速 噪音
< 45°C 10% ~350 RPM 🔇 几乎无声
45-50°C 10-20% 350-500 RPM 🔈 非常安静
50-60°C 20-50% 500-900 RPM 🔉 轻微嗡嗡声
60-75°C 50-100% 900-2000+ RPM 🔊 明显风噪
> 75°C 100% 最大转速 🔊🔊 全速

GPU风扇

温度 转速
< 40°C 自动(通常停转)
40-60°C 30%
60-75°C 60%
> 75°C 100%

🔧 故障排查

CPU风扇不工作

# 1. 检查 PWM 接口
ls /sys/class/hwmon/hwmon*/pwm*

# 2. 检查传感器
sensors

# 3. 查看服务日志
sudo journalctl -u fancontrol -n 50

# 4. 手动测试
echo 150 | sudo tee /sys/class/hwmon/hwmon4/pwm1

GPU风扇不工作

# 1. 检查 Coolbits 是否启用
grep Coolbits /etc/X11/xorg.conf

# 2. 检查 DISPLAY 环境变量
echo $DISPLAY

# 3. 手动测试
DISPLAY=:0 nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=50

# 4. 查看日志
sudo journalctl -u gpu-fan-control.service -n 50

hwmon 编号变化

如果重启后 hwmon4 变成 hwmon5,需要:

# 1. 查找正确的编号
ls -l /sys/class/hwmon/

# 2. 更新 fancontrol 配置
sudo nano /etc/fancontrol
# 修改所有 hwmon4 为新编号

# 3. 重启服务
sudo systemctl restart fancontrol

🗑️ 卸载

sudo bash uninstall.sh

或手动卸载:

# 停止并禁用服务
sudo systemctl stop fancontrol gpu-fan-control.timer
sudo systemctl disable fancontrol gpu-fan-control.timer

# 删除文件
sudo rm /usr/local/bin/{gpu-fan-control.sh,temp-monitor,fan-status}
sudo rm /etc/systemd/system/gpu-fan-control.{service,timer}
sudo rm /etc/fancontrol

# 恢复 GPU 自动风扇控制
DISPLAY=:0 nvidia-settings -a [gpu:0]/GPUFanControlState=0

# 重载 systemd
sudo systemctl daemon-reload

📝 文件结构

ubuntu-AutoTemp/
├── README.md                      # 本文档
├── install.sh                     # 一键安装脚本
├── uninstall.sh                   # 卸载脚本
├── scripts/
│   ├── gpu-fan-control.sh        # GPU风扇控制脚本
│   ├── temp-monitor              # 实时温度监控
│   └── fan-status                # 快速状态查看
├── config/
│   ├── fancontrol.example        # CPU风扇配置示例
│   └── xorg.conf.example         # X11配置示例
└── systemd/
    ├── gpu-fan-control.service   # GPU服务文件
    └── gpu-fan-control.timer     # GPU定时器

⚠️ 注意事项

  1. 备份配置: 修改系统配置前请备份
  2. 硬件差异: 不同主板/CPU/GPU 可能需要调整参数
  3. 温度监控: 安装后请监控温度,确保配置合理
  4. hwmon编号: 可能因硬件或启动顺序变化,需要调整
  5. X11环境: GPU风扇控制需要 X11 图形环境

🐛 已知问题

  • hwmon编号变化: 重启后可能需要更新配置文件中的 hwmon 编号
  • headless系统: 无显示器的服务器需要配置虚拟显示器
  • NVIDIA驱动: 需要使用专有驱动,开源驱动不支持风扇控制

📄 许可证

MIT License

👤 作者

wzy04

🙏 致谢

  • lm-sensors 项目
  • NVIDIA Linux 驱动团队
  • Ubuntu 社区

📮 反馈

如有问题或建议,请提交 Issue 或 Pull Request。


最后测试时间: 2025-11-14
测试环境: Ubuntu 22.04.5 LTS, Ryzen 9 5950X, RTX 4060 Ti

About

Ubuntu fan and temperature automation utility for CPU/GPU workstation operations.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages