我正试着尽可能的清楚:我的大脑会爆炸,就像那些爆炸的小猫一样。
两台机器Centos 7:
[root@192.168.10.2]# cat /proc/version
Linux version 3.10.0-693.11.6.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Thu Jan 4 01:06:37 UTC 2018以及来自EPEL的最新NRPE:
[root@192.168.10.1]# ./check_nrpe -H 192.168.10.2
NRPE v3.2.0我正在尝试从nagios服务器重新启动一个服务,这样我就可以设置一个事件处理程序。所有这些都是从大量脚本开始的,但现在我将问题缩小到以下几个方面:
[root@192.168.10.1]# ./check_nrpe -H 192.168.10.2 -c restart
NRPE: Unable to read output
[root@192.168.10.1]# ./check_nrpe -H 192.168.10.2 -c status
(... correct service status output ...)
Loaded: loaded (/usr/lib/systemd/system/cachefilesd.service
(... correct service status output ...)因此,我可以状态服务,但不能启动或重新启动。
[root@192.168.10.2]# cat /etc/nagios/nrpe.conf:
[...]
nrpe_user=nrpe
nrpe_group=nrpe
allowed_hosts=127.0.0.1,192.168.10.1
command[status]=/lib64/nagios/plugins/status.sh
command[restart]=/lib64/nagios/plugins/restart.sh
[...]
[root@192.168.10.2]# cat /lib64/nagios/plugins/status.sh
#!/bin/bash
sudo systemctl status cachefilesd
exit 0和
[root@192.168.10.2]# cat /lib64/nagios/plugins/restart.sh
#!/bin/bash
sudo systemctl restart cachefilesd
exit 0sudoers:
[root@192.168.10.2]# cat /etc/sudoers
# Defaults specification
Defaults: nrpe !requiretty
Defaults: nagios !requiretty
nagios ALL = NOPASSWD: /sbin/service,/usr/bin/systemctl,/usr/sbin/service
nrpe ALL = NOPASSWD: /sbin/service,/usr/bin/systemctl,/usr/sbin/service如果我输入:
[root@192.168.10.2]# sudo -u nrpe -H ./restart-cachefilesd.sh一切都很好。
我在NRPE中启用了调试,我得到:
nrpe[5431]: Host address is in allowed_hosts
nrpe[5431]: Host 192.168.10.1 is asking for command 'restart' to be run...
nrpe[5431]: Running command: /lib64/nagios/plugins/restart.sh
nrpe[5432]: WARNING: my_system() seteuid(0): Operation not permitted
nrpe[5431]: Command completed with return code 0 and output:
nrpe[5431]: Return Code: 3, Output: NRPE: Unable to read output
nrpe[5431]: Connection from 192.168.10.1 closed.我试着strace输出,但是对我来说太多了.
发布于 2018-02-10 21:27:22
与其将sudo放入脚本中,不如将sudo包含在nrpe.cfg文件中:
command[status]=sudo /lib64/nagios/plugins/status.sh而不是
command[status]=/lib64/nagios/plugins/status.shhttps://serverfault.com/questions/894226
复制相似问题