当前位置:网站首页>Smartctl opens the device and encounters permission denied problem troubleshooting process record

Smartctl opens the device and encounters permission denied problem troubleshooting process record

2022-06-25 02:10:00 InfoQ

Use today  Zabbix  The monitoring system found a problem while monitoring the disk ,smartctl  Commands cannot be executed by ordinary users .

smartcl  Is a disk management tool  Smart  The order provided , Use this command to get some status information about the disk , Like the following :

[[email protected] ~]# smartctl -A /dev/nvme0n1
smartctl 7.0 2018-12-30 r4883 [x86_64-linux-3.10.0-693.el7.x86_64] (local build)
Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF SMART DATA SECTION ===
SMART/Health Information (NVMe Log 0x02)
Critical Warning: 0x00
Temperature: 29 Celsius
Available Spare: 100%
Available Spare Threshold: 10%
Percentage Used: 0%
Data Units Read: 80 [40.9 MB]
Data Units Written: 0
Host Read Commands: 1,897
Host Write Commands: 10
Controller Busy Time: 0
Power Cycles: 10
Power On Hours: 923
Unsafe Shutdowns: 7
Media and Data Integrity Errors: 0
Error Information Log Entries: 0
Warning Comp. Temperature Time: 0
Critical Comp. Temperature Time: 0

[[email protected] ~]#

Smart  The tool  smartctl  The command can only be used  root  To carry out , It cannot be executed by ordinary users .

But when  Zabbix  When the monitoring system uses this command to monitor , The default is to use  zabbix  The user created in this system will execute , You can only use  root  Permission to execute , For example, add  sudo  Give authority to  zabbix  User to execute this command .

to  zabbix  user root  Permission to continue executing this command , This is the time to report a mistake :

[[email protected] ~]$ smartctl -A /dev/nvme0n1
smartctl 7.0 2018-12-30 r4883 [x86_64-linux-3.10.0-693.el7.x86_64] (local build)
Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org

Smartctl open device: /dev/nvme0n1 failed: Permission denied

Here is another one without permission , This is not authorized  /dev/nvme0n1  This block device does not have permission . Looking at the block device, we find that its array is  disk , This group has read and write permissions , So here you are  zabbix  Users adding to  disk  In the group , Then we can solve the above problem .

[[email protected] ~]# ll -h /dev/nvme0n1
brw-rw---- 1 root disk 259, 0 5 month  31 10:43 /dev/nvme0n1
[[email protected] ~]#

To add to a group, you can use this command :

usermod -a -G disk zabbix

If your problem is solved here , So congratulations .

I then encountered a new problem :


[[email protected] ~]$ smartctl -A /dev/nvme0n1
smartctl 7.0 2018-12-30 r4883 [x86_64-linux-3.10.0-693.el7.x86_64] (local build)
Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org

Read NVMe Identify Controller failed: NVME_IOCTL_ADMIN_CMD: Permission denied

NVME_IOCTL_ADMIN_CMD  yes  NVME  A function of , I don't know how to authorize functions .

So I used the ultimate trick , I modified  Zabbix Agent  Start user of , To modify a  root , The problem will be solved at once .

about  Zabbix  I have a permission problem ,Zabbix  The official advice is to  sudo  The document of the order  /etc/sudoers  The command is authorized in the file , And it is best to follow the principle of minimum authorization . This time in the course of implementation , Finally, I entered the function permission management , There is no way , Only use  root  The user solved the problem .

If you have other ways , Welcome to exchange and discussion .
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242152387986.html