版本信息:
Ubuntu 16.04
参考文献:
安装依赖
sudo apt-get install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail unzip
添加group和user
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios,nagcmd www-data
安装 Nagios
-
step 1
下载源码&解压:
cd /usr/local
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.0.tar.gz
tar -xzvf nagios-4.2.0.tar.gz
-
step 2
编译&安装
cd nagios-4.2.0
./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
复制文件到目录下&修改权限
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
-
Step 3
安装nagios补丁文件
wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
tar -xzf nagios-plugins-2.1.2.tar.gz
编译安装
cd nagios-plugin-2.1.2/
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make
make install
-
Step 4
配置nagios文件
vim /usr/local/nagios/etc/nagios.cfg
去掉原文件里面下面内容前面的"#"
cfg_dir=/usr/local/nagios/etc/servers
保存退出
新建文件夹
mkdir -p /usr/local/nagios/etc/servers
修改contacts.cfg配置文件
vim /usr/local/nagios/etc/objects/contacts.cfg
图片.png
配置Apache
-
Step 1
启动Apache模块
sudo a2enmod rewrite
sudo a2enmod cgi
创建密码
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
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
使之可执行并开启服务
chmod +x /etc/init.d/nagios
service apache2 restart
servuce nagios start
若nagios开启失败,可尝试下面的方法:
/etc/init.d/nagios start
开启成功后,可用网页进行查看
输入网址:http://192.168.3.12/nagios
弹出登录的框框
图片.png用户名:nagiosadmin
密 码:justdoit
将主机添加到监视器
因为只有一台服务器,尝试可否在同台电脑上配置nagios服务
Nagios Server IP : 192.168.3.12
Ubuntu Host IP : 192.168.3.12
-
Step 1
在主机上安装NRPE Service
sudo apt-get install nagios-nrpe-server nagios-plugins
-
Step 2
配置 NRPE
vim /etc/nagios/nrpe.cfg
在server_address添加Nagios Server IP 192.168.3.12
server_address=192.168.3.12
图片.png
-
Step 3
Restart NRPE
sudo /etc/init.d/nagios-nrpe-server start
注(NRPE之关闭和重启):
sudo /etc/init.d/nagios-nrpe-server stop
sudo /etc/init.d/nagios-nrpe-server restart
-
Step 4
在主机上添加Nagios Server
vim /usr/local/nagios/etc/servers/ubuntu_host.cfg
# Ubuntu Host configuration file
define host {
use linux-server
host_name ubuntu_host
alias Ubuntu Host
address 192.168.3.12
register 1
}
define service {
host_name ubuntu_host
service_description PING
check_command check_ping!100.0,20%!500.0,60%
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name ubuntu_host
service_description Check Users
check_command check_local_users!20!50
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name ubuntu_host
service_description Local Disk
check_command check_local_disk!20%!10%!/
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name ubuntu_host
service_description Check SSH
check_command check_ssh
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name ubuntu_host
service_description Total Process
check_command check_local_procs!250!400!RSZDT
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
注:define host里面的额address需要该成被检测计算机的id
查看配置是否正确
图片.png/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
-
Step 6
重启各种服务
(1) NRPE Service
sudo /etc/init.d/nagios-nrpe-server restart
(2) Apache and Nagios
service apache2 restart
sudo /etc/init.d/nagios restart
-
Step 7
测试是否配置成功:
图片.png总结:
这个样子好像就是配置成功了吧!自己半道出家,对这些还不太了解具体是搞毛的,说不出123来。但是,看结果应该是完成了检测的功能。
应该就是可以在同台计算机上配置这个冬冬了,那么,在两台电脑上配置的话,把被检测计算机的id换上就应该没问题了。
Peopel people for me ,me for people people!!
网友评论