-
利用 yum 進行相關套件安裝:
#yum -y httpd-tool gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget unzip spawn-fcgi perl-FCGI fcgi fcgi-devel
-
設定 Nagios 專用帳號與群組:
#useradd nagios
#passwd nagios
#groupadd nagcmd
#usermod -a -G nagcmd nagios
#usermod -a -G nagcmd nginx
-
下載 Nagios 的最新版本:
# cd /tmp
#wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.1.tar.gz
#wget https://nagios-plugins.org/download/nagios-plugins-2.1.3.tar.gz
-
解開 Nagios 壓縮檔:
#tar zxvf nagios-4.2.1.tar.gz
#tar zxvf nagios-plugins-2.1.3.tar.gz
-
編譯 Nagios 原始碼:
#cd nagios-4.2.1
#./configure --sysconfdir=/etc/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagcmd
#make all
#make install
#make install-init
#make install-commandmode
-
編譯 Nagios-plugins 原始碼:
#cd ../nagios-plugins-2.1.3
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make all
#make install
-
修改 Nagios 相關設定檔:
#vim /etc/nagios/nagios.cfg
(修改下列設定:)
log_file=/var/log/nagios/nagios.log
-
配合設定檔,新增目錄及檔案:
#mkdir /var/log/nagios
#touch /var/log/nagios/nagios.log
#chown -R nagios:nagios /var/log/nagios/
-
新增帳密,鎖住 Nagios 網頁:
#htpasswd -cb /etc/nagios/htpasswd.users nagiosadmin !AGoodPassword
-
設定 fcgiwrap:
#cd /etc/yum.repos.d/
#wget https://copr.fedorainfracloud.org/coprs/jorti/fcgiwrap/repo/epel-7/jorti-fcgiwrap-epel-7.repo
#yum install fcgiwrap
#vim /etc/init.d/fcgiwrap
(編寫內容如下:)
#!/usr/bin/perl
use strict;
use warnings FATAL => qw( all );
use IO::Socket::UNIX;
my $bin_path = '/usr/sbin/fcgiwrap';
my $socket_path = $ARGV[0] || '/tmp/cgi.sock';
my $num_children = $ARGV[1] || 1;
close STDIN;
unlink $socket_path;
my $socket = IO::Socket::UNIX->new(
Local => $socket_path,
Listen => 100,
);
die "Cannot create socket at $socket_path: $!\n" unless $socket;
for (1 .. $num_children) {
my $pid = fork;
die "Cannot fork: $!" unless defined $pid;
next if $pid;
exec $bin_path;
die "Failed to exec $bin_path: $!\n";
}
(存檔後離開)
# chmod +x /etc/init.d/fcgiwrap
#vim /etc/rc.local
(加入下列該行指令:)
sudo -u nginx /etc/init.d/fcgiwrap
-
設定 Nginx 內容:
#cd /etc/yum.repos.d/
-
起動 Nagios :
#
#chmod +x /etc/init.d/nagios
#chkconfig --add nagios
#service nagios start