1.先安装这个
sudo apt-get install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail unzip
2.用户和组配置
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios,nagcmd www-data
3.安装nagios
cd ~
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.0.tar.gz
tar -xzf nagios*.tar.gz
cd nagios-4.2.0
4.编译nagios
./configure --with-nagios-group=nagios --with-command-group=nagcmd
make all
sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
并将evenhandler目录复制到nagios目录中:
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
5.安装Nagios插件
wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
tar -xzf nagios-plugins*.tar.gz
cd nagios-plugins-2.1.2/
以下命令安装nagios插件:
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make
make install
6.安装阶段完成之后,配置nagios
vim /usr/local/nagios/etc/nagios.cfg
将下面这行cfg_dir=.......取消注释
添加名为servers的新文件夹:
mkdir -p /usr/local/nagios/etc/servers
然后
vim /usr/local/nagios/etc/objects/contacts.cfg
更改为自己的电子邮箱
7.配置Apache
启动apache模块
sudo a2enmod rewrite
sudo a2enmod cgi
可以使用htpasswd命令为nagios Web界面配置用户nagiosadmin:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
启用Nagios虚拟主机:
sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/
启动Apache和Nagios
service apache2 restart
service nagios start
在这里遇到了问题:
解决方法:
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
创建这个文件,并添加内容:
sudo vi /etc/systemd/system/nagios.service
8.添加主机监控(通过nrpe对主机进行监控):
服务器是:192.168.121.27
客户端:192.168.121.28
配置nrpe
vim /etc/nagios/nrpe.cfg
service nagios-nrpe-server restart
9.在服务器中创建一个新文件并添加内容:
vim /usr/local/nagios/etc/servers/ubuntu_host.cfg
检查配置:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
10.启动服务:
服务器:
客户端:
登录网页:
用户名是:nagiosadmin
密码:123456(刚刚有个命令让输入的密码)