thinkfan快速上手教程:5分钟从零编译安装这款极简Linux风扇控制程序
【免费下载链接】thinkfanThe minimalist fan control program项目地址: https://gitcode.com/gh_mirrors/th/thinkfan
thinkfan 是一款极简主义的 Linux 风扇控制程序(fan control program),它通过读取 CPU、GPU、硬盘等硬件温度,按你设定的温度阈值自动调节风扇转速,小巧、轻量、无依赖包袱。本教程带你从安装依赖、编译构建到开机自启,5 分钟从零完成 thinkfan 的完整安装。
为什么选择 thinkfan?30 秒了解这款风扇控制程序
- 轻量无负担:纯 C++17 编写,主程序入口仅一个文件 src/thinkfan.cpp,资源占用极低
- 多传感器源:支持 LM-sensors、hwmon、nVidia NVML、thinkpad_acpi 等多种温度读取方式,风扇控制模块见 src/fans.cpp
- 配置友好:除传统格式外,还支持更灵活的 YAML 配置文件(
src/yamlconfig.cpp) - 自动安装服务:编译时自动检测 systemd 或 OpenRC 并装好对应的服务文件,开机自启零配置
⚠️官方提示:thinkfan 只对配置做最基本的合理性检查。把温度阈值设置得"离谱"并不会被拦截——温度过高会缩短硬件寿命。动手前请先了解你系统的正常温度范围。
第一步:一键安装 thinkfan 编译依赖
thinkfan 的构建依赖非常少:C++ 编译器(GCC ≥ 4.8 或 clang)、cmake、pkg-config,可选 yaml-cpp(YAML 配置支持)与 libsensors(LM-sensors 支持)。
Debian / Ubuntu 系,一条命令搞定:
sudo apt install -y cmake-curses-gui build-essential cmake g++ \ libyaml-cpp-dev pkgconfig libsensors-devFedora / EL 系:
sudo dnf install -y cmake g++ pkgconfig yaml-cpp-devel lm_sensors-devel第二步:克隆源码,用 CMake 完成 thinkfan 编译
git clone https://gitcode.com/gh_mirrors/th/thinkfan cd thinkfan mkdir build && cd build cmake .. makecmake ..会按默认选项完成配置。想交互式配置可改用ccmake ..(就是那个终端图形界面,新手很友好)。
几个常用 CMake 选项,按需追加,例如cmake -DUSE_YAML=OFF ..:
| 选项 | 默认 | 作用 |
|---|---|---|
USE_YAML | ON | 启用新的 YAML 配置文件格式(需 libyaml-cpp) |
USE_LM_SENSORS | ON | 通过 LM-sensors 读取内核温度(需 libsensors) |
USE_NVML | ON | 读取 nVidia 显卡温度,运行时动态加载驱动,编译无需驱动 |
USE_ATASMART | OFF | 从硬盘 S.M.A.R.T 读温度,CPU 开销大,非必要不开 |
构建类型默认为RelWithDebInfo(已优化且可调试),在 CMakeLists.txt 中可见默认逻辑;想彻底优化可加-DCMAKE_BUILD_TYPE:STRING=Release。
第三步:安装 thinkfan 并快速验证
sudo make install未修改CMAKE_INSTALL_PREFIX时,程序会装到/usr/local/sbin/thinkfan,同时安装 man 手册页(thinkfan(1)、thinkfan.conf(5))。
最快验证方法——前台跑一次,看它能否正确读取传感器与风扇:
thinkfan -n # 前台模式,日志直接打印到终端 thinkfan -h # 查看全部命令行选项-n:不进入守护进程模式,适合调试-s <秒>:调节轮询间隔(默认 5 秒)-b <值>:温度偏置,微调阈值(-10 ~ 30)
第四步:快速上手 thinkfan 的 YAML 配置文件
安装后,建议参考示例配置 examples/thinkfan.yaml 编写自己的配置(/etc/thinkfan.conf.yaml)。它只有三个核心区块:
sensors:声明温度传感器,如 LM-sensors 芯片、/sys/class/hwmon路径、nVidia 显卡等fans:声明风扇驱动,如 hwmon 的pwm1文件,或 ThinkPad 的tpacpi接口levels:风扇调速规则,即"温度区间 → 风扇转速"的映射表
levels: - [0, 0, 50] # 50°C 以下停转 - [100, 45, 65] # 45~65°C 转速 100 - [255, 60, 255] # 60°C 以上全速📌重要:示例文件只是演示,不要直接复制粘贴风扇转速配置!不同机器硬件差异巨大,请先观察自己系统的实际温度再设定阈值。
开机自启:systemd 与 OpenRC 服务说明
CMake 会自动检测你的 init 系统并安装对应服务文件:
systemd:安装
thinkfan.service以及休眠/唤醒用的thinkfan-sleep.service、thinkfan-wakeup.service(源自 rcscripts/systemd/),服务模板见 thinkfan.service.cmake。之后用一条命令即可自定义启动参数:systemctl edit thinkfanOpenRC:安装纯净的 initscript 到
/etc/init.d/thinkfan,编辑该文件即可修改选项
常见编译问题速查(thinkfan 新手必看)
| 报错关键词 | 原因 | 解决方法 |
|---|---|---|
yaml-cpp not found | 缺 YAML 库 | 安装libyaml-cpp-dev,或cmake -DUSE_YAML=OFF .. |
libsensors not found | 缺传感器库 | 安装libsensors-dev,或cmake -DUSE_LM_SENSORS=OFF .. |
| 编译通过但读不到温度 | 驱动未加载 | 运行sensors-detect(来自 lm-sensors 包),再执行sensors确认可读 |
| yaml-cpp 版本过旧警告 | 低于 0.5.3 | 可忽略,仅影响 YAML 错误定位提示 |
总结:安装依赖 →cmake .. && make→sudo make install→ 写一份 YAML 配置 → 交给 systemd 自启,这就是 thinkfan 风扇控制程序的完整上手路径。全程 5 分钟,你就能获得一个安静又恒温的 Linux 系统。动手前记得:先读懂自己机器的温度,再大胆调风扇🌡️
【免费下载链接】thinkfanThe minimalist fan control program项目地址: https://gitcode.com/gh_mirrors/th/thinkfan
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考