以下是安装和配置Nagios的步骤:
安装必要的软件包:
sudo apt-get update
sudo apt-get install build-essential libgd2-xpm-dev openssl libssl-dev xinetd apache2 php libapache2-mod-php php-gd
sudo yum install gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix
创建Nagios用户:
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagios apache
下载Nagios核心软件包:
解压和编译Nagios软件包:
tar -xzf nagios-x.x.x.tar.gz
cd nagios-x.x.x
./configure --with-command-group=nagcmd
make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode
sudo make install-webconf
创建Nagios管理员账户:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
安装并配置Nagios插件:
tar -xzf nagios-plugins-x.x.x.tar.gz
cd nagios-plugins-x.x.x
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install
配置Nagios:
sudo vi /usr/local/nagios/etc/nagios.cfg
#cfg_dir=/usr/local/nagios/etc/servers
sudo mkdir /usr/local/nagios/etc/servers
define host {
use linux-server
host_name localhost
alias My localhost server
address 127.0.0.1
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
启动Nagios服务:
sudo service nagios start
sudo systemctl start nagios
配置Nagios Web界面:
sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/
sudo systemctl restart apache2
sudo ln -s /etc/httpd/conf.d/nagios.conf /etc/httpd/conf.d/nagios.conf
sudo systemctl restart httpd
访问Nagios Web界面: