如何在 Linux 上安裝 lm 傳感器

lm-sensors 為 Linux 提供了一個硬件健康監控驅動程序。 系統管理員使用它來檢查硬件的健康狀態。 它還用於監控服務器中的硬件基礎設施,並且在關鍵任務應用程序中非常有價值。 但是配置它以使用相對容易。 下面展示瞭如何在你的 Ubuntu/Debian 上安裝 lm 傳感器工具和 Fedora Linux 發行版。

1) 安裝

在 Ubuntu 和 Debian 發行版上

# apt install lm-sensors

在 Fedora 26 和 RPM Linux 發行版

# dnf install lm_sensors

安裝完成後,運行以下命令來檢查您當前的硬件規格。

# sudo sensors-detect

它會問你幾個問題。 對所有人都回答是。

```
[root@localhost bin]# sensors-detect
# sensors-detect revision 6284 (2015-05-31 14:00:33 +0200)
# System: ASUSTeK COMPUTER INC. X540LA [1.0] (laptop)
# Kernel: 4.11.11-300.fc26.x86_64 x86_64
# Processor: Intel(R) Core(TM) i3-5020U CPU @ 2.20GHz (6/61/4)

This program will help you determine which kernel modules you need
to load to use lm_sensors most effectively. It is generally safe
and recommended to accept the default answers to all questions,
unless you know what you're doing.

Some south bridges, CPUs or memory controllers contain embedded sensors.
Do you want to scan for them? This is totally safe. (YES/no): yes
Silicon Integrated Systems SIS5595... No
VIA VT82C686 Integrated Sensors... No
VIA VT8231 Integrated Sensors... No
AMD K8 thermal sensors... No
AMD Family 10h thermal sensors... No
AMD Family 11h thermal sensors... No
AMD Family 12h and 14h thermal sensors... No
AMD Family 15h thermal sensors... No
AMD Family 16h thermal sensors... No
AMD Family 15h power sensors... No
AMD Family 16h power sensors... No
Intel digital thermal sensor... Success!
 (driver `coretemp')
Intel AMB FB-DIMM thermal sensor... No
Intel 5500/5520/X58 thermal sensor... No
VIA C7 thermal sensor... No
VIA Nano thermal sensor... No

Some Super I/O chips contain embedded sensors. We have to write to
standard I/O ports to probe them. This is usually safe.
Do you want to scan for Super I/O sensors? (YES/no): yes
/dev/port: Operation not permitted

Some hardware monitoring chips are accessible through the ISA I/O ports.
We have to write to arbitrary I/O ports to probe them. This is usually
safe though. Yes, you do have ISA I/O ports even if you do not have any
ISA slots! Do you want to scan the ISA I/O ports? (YES/no): yes
/dev/port: Operation not permitted

Lastly, we can probe the I2C/SMBus adapters for connected hardware
monitoring devices. This is the most risky part, and while it works
reasonably well on most systems, it has been reported to cause trouble
on some systems.
Do you want to probe the I2C/SMBus adapters now? (YES/no): yes
Found unknown SMBus adapter 8086:9ca2 at 0000:00:1f.3.
Sorry, no supported PCI bus adapters found.
Module i2c-dev loaded successfully.

Next adapter: i915 gmbus vga (i2c-0)
Do you want to scan it? (yes/NO/selectively): yes

Next adapter: i915 gmbus dpc (i2c-1)
Do you want to scan it? (yes/NO/selectively): yes

Next adapter: i915 gmbus dpb (i2c-2)
Do you want to scan it? (yes/NO/selectively): yes

Next adapter: i915 gmbus dpd (i2c-3)
Do you want to scan it? (yes/NO/selectively): yes

Next adapter: DPDDC-A (i2c-4)
Do you want to scan it? (yes/NO/selectively): yes

Next adapter: DPDDC-B (i2c-5)
Do you want to scan it? (yes/NO/selectively): yes

Next adapter: SMBus I801 adapter at 4040 (i2c-6)
Do you want to scan it? (YES/no/selectively): yes
Client found at address 0x52
Probing for `Analog Devices ADM1033'... No
Probing for `Analog Devices ADM1034'... No
Probing for `SPD EEPROM'... Yes
 (confidence 8, not a hardware monitoring chip)

Next adapter: Synopsys DesignWare I2C adapter (i2c-7)
Do you want to scan it? (YES/no/selectively): yes
Adapter doesn't support all probing functions.
Some addresses won't be probed.

Next adapter: Synopsys DesignWare I2C adapter (i2c-8)
Do you want to scan it? (YES/no/selectively): yes
Adapter doesn't support all probing functions.
Some addresses won't be probed.

Now follows a summary of the probes I have just done.
Just press ENTER to continue:

Driver `coretemp':
 * Chip `Intel digital thermal sensor' (confidence: 9)

Do you want to overwrite /etc/sysconfig/lm_sensors? (YES/no): yes
Unloading i2c-dev... OK

[root@localhost bin]#

```

測試lm傳感器

最後得到你的CPU溫度類型 sensors 在您的終端中。 這測試了 lm-sensors 工具正常工作。 此外,要檢查 CPU 溫度、風扇速度和其他數據,請運行以下命令:

[root@localhost bin]# sensors
asus-isa-0000
Adapter: ISA adapter
cpu_fan: 2100 RPM
temp1: +49.0°C

acpitz-virtual-0
Adapter: Virtual device
temp1: +49.0°C (crit = +108.0°C)

coretemp-isa-0000
Adapter: ISA adapter
Package id 0: +50.0°C (high = +105.0°C, crit = +105.0°C)
Core 0: +49.0°C (high = +105.0°C, crit = +105.0°C)
Core 1: +50.0°C (high = +105.0°C, crit = +105.0°C)

pch_wildcat_point-virtual-0
Adapter: Virtual device
temp1: +47.0°C

該傳感器的輸出顯示兩個設備:asus-isa-0000(主板傳感器)和 ccoretemp-isa-0000(英特爾酷睿傳感器)。 主板傳感器設備具有有關主板(in1-6)從電源單元接收到的電壓、風扇速度(帶有 RPM 的條目)和各種內部溫度的信息。

2)安裝和自定義lm-sensor GUI:Psensor

a) 安裝 psensor

如果您不想在終端中使用 lm-sensor,您可以安裝 psensor,它是 lm-sensors 的 GUI。

在 Debian 系統上

# apt install psensor
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following additional packages will be installed:
 libappindicator3-1 libdbusmenu-glib4 libdbusmenu-gtk3-4 libindicator3-7 libjson-c3 libxnvctrl0 psensor-common
The following NEW packages will be installed:
 libappindicator3-1 libdbusmenu-glib4 libdbusmenu-gtk3-4 libindicator3-7 libjson-c3 libxnvctrl0 psensor psensor-common

在 Redhat 系統上,默認系統存儲庫中不提供 psensor,因此您需要從源代碼編譯它。 我們首先需要安裝 wget

# dnf install wget
Last metadata expiration check: 0:24:13 ago on Wed 23 Aug 2017 03:54:38 AM UTC.
Dependencies resolved.
======================================================================================================================================================
 Package                         Arch                              Version                                    Repository                         Size
======================================================================================================================================================
Installing:
 wget                            x86_64                            1.19.1-3.fc26                              fedora                            725 k

現在安裝編譯所需的包

# dnf group install 'Development Tools'
Last metadata expiration check: 0:50:12 ago on Wed 23 Aug 2017 03:54:38 AM UTC.
Dependencies resolved.

現在寫這篇文章的時候可以從源碼下載最新版本的psensor(1.2.0)

# wget https://wpitchoune.net/psensor/files/psensor-1.2.0.tar.gz
--2017-08-23 04:31:01-- https://wpitchoune.net/psensor/files/psensor-1.2.0.tar.gz
Resolving wpitchoune.net (wpitchoune.net)... 92.243.29.231

現在你可以解壓縮它

# tar xvf psensor-1.2.0.tar.gz 
psensor-1.2.0/
psensor-1.2.0/test-driver
psensor-1.2.0/ar-lib

現在我們可以編譯 psensor

# cd psensor-1.2.0
# ./configure 
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
# make install
Making install in doc
make[1]: Entering directory '/root/psensor-1.2.0/doc'
make[2]: Entering directory '/root/psensor-1.2.0/doc'

b) 啟動和自定義 psensor

現在安裝了 psensor,您可以通過圖形菜單啟動它,結果如下:

您可以通過在下面取消選擇 temp1、Core1 和 ST500LT012-1DG142 的右側取消粘貼來選擇哪個元素將出現在圖表上

您可以編輯 psensor 首選項。 你可以編輯

  • 喜好: 您可以在其中修改工具的啟動方式、界面或圖形表示,如下所示 傳感器 -> 偏好
  • 傳感器首選項: 在這裡,您可以編輯 psensor 工具如何對受監控的服務進行操作,例如警報以發出通知或修改服務名稱,如下所示 傳感器 -> 傳感器首選項

然後你可以看到一個通知,它可以顯示如下

lm-sensors 是執行硬件健康檢查的非常有用的工具。 但是,由於 CLI 界面較​​差,大多數用戶更喜歡基於 GUI 的應用程序。 但是,lm-sensor 可以配置為使用 GUI 工具,例如 sensors-applet, psensor 這是一個 GTK 應用程序,可顯示 CPU、硬盤溫度、風扇速度等圖表。 lm-sensors 可以進一步配置為使用控制系統風扇 fancontrol 腳本。 這可以很容易地完成運行 sudo pwmconfig 命令並仔細按照說明進行操作。