htpasswd:无法创建文件 /etc/nagios/htpasswd.users

htpasswd:无法创建文件 /etc/nagios/htpasswd.users

我刚刚在 CentOS 6.5 上安装了 nagios。创建默认身份验证时。用户:

htpasswd –c /usr/local/nagios/etc/htpasswd.users nagiosadmin

这是我得到的:

htpasswd: cannot create file /usr/local/nagios/etc/htpasswd.users

该命令以 root 身份运行、/usr/local/nagios/etc/存在并且 SELinux 已启用。可能是什么问题?

答案1

我设法通过首先手动创建文件来解决该问题。这就是我所做的:我的 apache2 文件位于/usr/local/apache2/.因此,我mkdir passwd/apache2/目录中创建了一个目录,并通过运行在该 passwd 目录中创建了一个文件touch passwords。然后我终于跑了htpasswd -c /usrl/local/apache2/passwd/passwords flicker。请注意闪烁的是用户名。

答案2

只需手动创建所有后续文件夹和最终文件,然后重试该命令。我也做了同样的事情并且成功了。

答案3

htpasswd就我而言,在 Ubuntu 14.04 上,我发现应该在其中创建文件的目录不存在。只需创建文件夹并将所有权更改为 Nagios 即可解决问题。另请注意,同样的问题影响了配置文件的创建,因此make install-config可能需要在重新启动 Nagios 之前运行:

$ ls -al /usr/local/nagios/
total 28
drwxr-xr-x  7 root   root   4096 May 30 20:34 .
drwxr-xr-x 11 root   root   4096 May 30 20:34 ..
drwxrwxr-x  2 nagios nagios 4096 May 30 20:34 bin
drwxrwxr-x  2 nagios nagios 4096 May 30 20:34 libexec
drwxrwxr-x  2 nagios nagios 4096 May 30 20:34 sbin
drwxrwxr-x 14 nagios nagios 4096 May 30 20:34 share
drwxrwxr-x  5 nagios nagios 4096 May 30 20:34 var

$ sudo mkdir /usr/local/nagios/etc
[sudo] password ...
$ sudo chown -R nagios:nagios /usr/local/nagios/etc
$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:

$ sudo service nagios start
Configuration file /usr/local/nagios/etc/nagios.cfg not found. Exiting.
$ sudo make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

请记住,这些是样本配置文件。您需要阅读文档以获取有关如何实际定义服务、主机等的更多信息,以满足您的特定需求。

$ sudo service nagios start
Starting nagios: done.

相关内容