安装必要模块功能
apt-get install openssl perl make php5-gd libgd2-xpm-dev libapache2-mod-php5 libperl-dev libssl-dev daemon wget apache2-utils unzip

建立用户
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data

安装Nagios
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz
tar -zxvf /tmp/nagios-4.1.1.tar.gz
cd nagios-4.1.1/
./configure –with-nagios-group=nagios –with-command-group=nagcmd –with-httpd_conf=/etc/apache2/sites-enabled/
make all
make install
make install-init
make install-config
make install-commandmode
sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-enabled/nagios.conf

安装Nagios扩展功能
wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
tar xzf nagios-plugins-2.1.1.tar.gz
cd nagios-plugins-2.1.1
./configure –with-nagios-user=nagios –with-nagios-group=nagios
make
make install

编辑Nagios配置文件
vi /usr/local/nagios/etc/objects/contacts.cfg
email admin@idroot.net ;
更改为自己的email地址
email x@y.com;

vi /etc/apache2/sites-enabled/nagios.conf
AuthName “Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

开启apache的rewrite和cgi模块
sudo a2enmod rewrite
sudo a2enmod cgi

vi /usr/local/nagios/etc/cgi.cfg
use_authentication=1
更改为
use_authentication=0

重启apache服务
systemctl restart apache2

生成要监控的服务器配置信息:
echo “cfg_file=/usr/local/nagios/etc/objects/newhost.cfg " >> /usr/local/nagios/etc/nagios.cfg

define host{
use linux-server
host_name newhost
alias newhost
address X.X.X.X
}

define service{
use local-service
host_name newhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}

参考:https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/configmain.html

校验配置文件:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

重启nagios服务:
systemctl start nagios
http://x.x.x.x/nagios/