ubuntu nagios 通过web界面修改服务时报错解决

通过web界面修改某个服务时报错 例如对某个服务进行临时安排其执行时间,或者不让它发警告,web页面上都有这样的设置.但是常常会有错误信息如下:

Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!
The permissions on the external command file and/or directory may be incorrect. Read the FAQs on how to setup proper permissions.
An error occurred while attempting to commit your command for processing.

关于这部分在nagios.cfg中有下面的内容

# EXTERNAL COMMAND FILE
# This is the file that Nagios checks for external command requests.
# It is also where the command CGI will write commands that are submitted
# by users, so it must be writeable by the user that the web server
# is running as (usually 'nobody'). Permissions should be set at the
# directory level instead of on the file, as the file is deleted every
# time its contents are processed.
command_file=/usr/local/nagios/var/rw/nagios.cmd

#这段话的核心意思是apache的运行用户要有对文件写的权限.权限应该设置在目录上,因为每次文件的内容被处理后文件就会被删掉

将apache2运行的用户www-data加到nagios组

$sudo usermod -aG nagios www-data
$sudo /etc/init.d/nagios restart
$sudo /etc/init.d/apache2 restart

这样就可以通过web界面修改服务了!