1.Nagios需要用于编译的gcc编译器和build-essentials,用于Nagios Web界面的LAMP(Apache,PHP,MySQL)和Sendmail从服务器发送警报。 要安装所有这些软件包,请运行此命令:
# sudo apt-get install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail unzip
2.对于Nagios运行,您必须为Nagios创建一个新用户。 我们将命名用户“nagios” ,并另外创建一个名为“nagcmd”的组。 我们将新用户添加到组中:
# 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
5.安装Nagios:
# 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
6.并将evenhandler目录复制到nagios目录中:
# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
7.下载并提取Nagios插件:
# cd ~
# wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
# tar -xzf nagios-plugins*.tar.gz
# cd nagios-plugin-2.1.2/
8.使用以下命令安装Nagios插件:
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
# make
# make install
9.使用vim编辑默认的nagios配置:
# vim /usr/local/nagios/etc/nagios.cfg
取消注释线路51为主机监视器配置:
cfg_dir=/usr/local/nagios/etc/servers
10.添加名为servers的新文件夹:
# mkdir -p /usr/local/nagios/etc/servers
11.可以在contact.cfg文件中配置Nagios联系人。 打开它使用:
# vim /usr/local/nagios/etc/objects/contacts.cfg
替换电子邮箱
12.启动apache2模块:
# sudo a2enmod rewrite
# sudo a2enmod cgi
13.您可以使用htpasswd命令为nagios Web界面配置用户nagiosadmin:
# sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
14.启用Nagios虚拟主机:
# sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/
15.启动Apache和Nagios:
# service apache2 restart
# service nagios start
16.当Nagios启动时,您可能会看到以下错误:
Starting nagios (via systemctl): nagios.serviceFailed
解决:
# cd /etc/init.d/
# cp /etc/init.d/skeleton /etc/init.d/nagios
# vim /etc/init.d/nagios
添加代码:
DESC="Nagios"
NAME=nagios
DAEMON=/usr/local/nagios/bin/$NAME
DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg"
PIDFILE=/usr/local/nagios/var/$NAME.lock
使其可执行并启动Nagios:
# chmod +x /etc/init.d/nagios
# service apache2 restart
# service nagios start
打开浏览器,输入http://(本机ip)/nagios,账号nagiosadmin,密码在安装步骤中已设置,即进入nagios的web操作页面。