nagiosでフリーな監視をしてみよう!~nagiosの設定(3)~
(3)Apacheの起動ユーザapacheがNagiosを再起動できるようにsudoersを編集します。
# visudo
・sudo設定変更前の内容
## Allows members of the users group to shutdown this system # %users localhost=/sbin/shutdown -h now ## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment) #includedir /etc/sudoers.d
・sudo設定変更後の内容
## Allows members of the users group to shutdown this system # %users localhost=/sbin/shutdown -h now ## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment) #includedir /etc/sudoers.d apache ALL=(ALL) NOPASSWD: /etc/rc.d/init.d/nagios reload
(4)nconfが生成した設定ファイルをNagiosの設定ファイルディレクトリ(cd /usr/local/nagios/etc)に配置できるように設定します。
# cd /usr/local/nagios/etc # mkdir Default_collector global # chown apache. Default_collector global nagios.cfg
(5)nconfからnagios.cfgを編集・配置することもできるので、念のため、nconfのディレクトリ配下に「nagios.cfg」をコピーします。
# cp /usr/local/nagios/etc/nagios.cfg /usr/local/apache2/htdocs/nconf/static_cfg/ # chown -R apache. /usr/local/apache2/htdocs/nconf/static_cfg/
(6)nconfが配置するファイルを設定ファイルとして使用するように、コピーした先の「/usr/local/apache2/htdocs/nconf/static_cfg/nagios.cfg」を編集します。
# vi /usr/local/apache2/htdocs/nconf/static_cfg/nagios.cfg
・「nagios.cfg」ファイル変更前の内容
※cfg_fileとcfg_dirを全てコメントアウトします。
# You can specify individual object config files as shown below: cfg_file=/usr/local/nagios/etc/objects/commands.cfg cfg_file=/usr/local/nagios/etc/objects/contacts.cfg cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg cfg_file=/usr/local/nagios/etc/objects/templates.cfg # Definitions for monitoring the local (Linux) host cfg_file=/usr/local/nagios/etc/objects/localhost.cfg # Definitions for monitoring a Windows machine #cfg_file=/usr/local/nagios/etc/objects/windows.cfg # Definitions for monitoring a router/switch #cfg_file=/usr/local/nagios/etc/objects/switch.cfg # Definitions for monitoring a network printer #cfg_file=/usr/local/nagios/etc/objects/printer.cfg # You can also tell Nagios to process all config files (with a .cfg # extension) in a particular directory by using the cfg_dir # directive as shown below:
・「nagios.cfg」ファイル変更後の内容
# You can specify individual object config files as shown below: #cfg_file=/usr/local/nagios/etc/objects/commands.cfg #cfg_file=/usr/local/nagios/etc/objects/contacts.cfg #cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg #cfg_file=/usr/local/nagios/etc/objects/templates.cfg # Definitions for monitoring the local (Linux) host #cfg_file=/usr/local/nagios/etc/objects/localhost.cfg # Definitions for monitoring a Windows machine #cfg_file=/usr/local/nagios/etc/objects/windows.cfg # Definitions for monitoring a router/switch #cfg_file=/usr/local/nagios/etc/objects/switch.cfg # Definitions for monitoring a network printer #cfg_file=/usr/local/nagios/etc/objects/printer.cfg # You can also tell Nagios to process all config files (with a .cfg # extension) in a particular directory by using the cfg_dir # directive as shown below: cfg_dir=/usr/local/nagios/etc/global cfg_dir=/usr/local/nagios/etc/Default_collector
(7)ApacheとNagiosを再起動します。
# service httpd stop # service nagios restart # service httpd start