nagios需要依赖lamp环境,全部我们先在nagios服务器上安装配置lamp环境。
[root@pc1 ~]# yum -y install httpd php* mariadb*
解压干系软件
[root@pc1 ~]# cd /root/桌面
[root@pc1 ~]# tar -zxvf nagios-4.0.1.tar.gz -C /usr/src
[root@pc1 ~]# tar -zxvf nagios-plugins-1.5.tar.gz -C /usr/src
[root@pc1 ~]# tar -zxvf nrpe-2.15.tar.gz -C /usr/src
2、安装依赖环境
yum -y install openssl-devel
3、编译安装nagois
[root@localhost ~]# useradd -M -s /sbin/nologin nagios
[root@localhost ~]# mkdir /usr/local/nagios
[root@localhost ~]# chown -R nagios:nagios /usr/local/nagios/
[root@localhost ~]# cd /usr/src/nagios-4.0.1/
配置编译环境
[root@pc1 nagios-4.0.1]# yum -y install gcc*
[root@localhost nagios-4.0.1]# ./configure --prefix=/usr/local/nagios
编译安装
[root@localhost nagios-4.0.1]# make all
[root@localhost nagios-4.0.1]# make install
[root@localhost nagios-4.0.1]# make install-init
[root@localhost nagios-4.0.1]# make install-commandmode
[root@localhost nagios-4.0.1]# make install-config
make install #安装主程序,CGI和HTML文件
make install-init #在/etc/rc.d/init.d安装启动脚本
make install-commandmode #安装command模板
make install-config #安装示例配置文件
6、编译安装nagios-plugins:
[root@localhost nagios-4.0.1]# cd /usr/src/nagios-plugins-1.5
[root@pc1 nagios-plugins-1.5]# ./configure --prefix=/usr/local/nagios
[root@pc1 nagios-plugins-1.5]# make && make install
7、编译安装nrpe:
[root@pc1 nagios-plugins-1.5]# cd /usr/src/nrpe-2.15/
[root@pc1 nrpe-2.15]# ./configure && make all
[root@pc1 nrpe-2.15]# make install-plugin
8、配置httpd.conf
添加nagios的访问界面
[root@pc1 nrpe-2.15]# vim /etc/httpd/conf/httpd.conf
在末了面添加:
ScriptAlias /nagios/cgi-bin/ "/usr/local/nagios/sbin/"
<Directory "/usr/local/nagios/sbin">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
| |
9、设置页面访问认证:
[root@localhost ~]# vim /usr/local/nagios/etc/cgi.cfg
修改:
use_authentication=0 (0:允许访问全部页面。1:禁止)
| | [root@pc1 nrpe-2.15]# systemctl restart httpd
[root@pc1 nrpe-2.15]# systemctl restart mariadb
+++++++++++++++++++++++++++++++++++++++++++++++++++++
pc2 被控端设置
1、安装依赖环境
[root@localhost ~]# yum -y install openssl openssl-devel gcc*
[root@localhost ~]# useradd -M -s /sbin/nologin nagios
安装nagios-plugins
[root@localhost ~]# cd /root/桌面
[root@localhost ~]# tar -zxvf nagios-plugins-1.5.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nagios-plugins-1.5/
[root@localhost nagios-plugins-1.5]# ./configure --prefix=/usr/local/nagios
[root@localhost nagios-plugins-1.5]# make && make install
[root@localhost nagios-plugins-1.5]# chown -R nagios:nagios /usr/local/nagios/
3、安装nrpe
[root@localhost ~]# tar -zxvf /root/桌面/nrpe-2.15.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nrpe-2.15/
[root@localhost nrpe-2.15]# ./configure --prefix=/usr/local/nagios/
[root@localhost nrpe-2.15]# make all
[root@localhost nrpe-2.15]# make install-plugin
[root@localhost nrpe-2.15]# make install-daemon
[root@localhost nrpe-2.15]# make install-daemon-config
4、配置
[root@localhost nrpe-2.15]# vim /usr/local/nagios/etc/nrpe.cfg
修改:
allowed_hosts=127.0.0.1,192.168.1.1 //添加监控服务器的IP地址
| |
[root@localhost nrpe-2.15]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d //启动nrpe
[root@localhost nrpe-2.15]# netstat -anp | grep nrpe //端标语是TCP5666
5、安装测试服务
[root@localhost ~]# yum -y install httpd vsftpd bind dhcp
[root@pc2 nrpe-2.15]# systemctl restart httpd
[root@pc2 nrpe-2.15]# systemctl restart named
[root@pc2 nrpe-2.15]# systemctl restart vsftpd
将以上为举行简单的配置,并启动服务
pc1添加被监控客户端的测试选项
[root@pc1 nrpe-2.15]# cd /usr/local/nagios/etc/
cp -p objects/localhost.cfg objects/192.168.1.2.cfg
vim objects/192.168.1.2.cfg
修改:
删除或者注释host group 选项
define host{
use linux-server
host_name server2
alias server2
address 192.168.1.2 //30行 将127.0.0.1修改为192.168.1.2
}
更换全部模块中的host_name 的名称为server2
:% s/localhost/server2/g
添加模块:
define service{
use local-service
host_name server2
service_description FTP
check_command check_ftp
notifications_enabled 0
}
define service{
use local-service
host_name server2
service_description DHCP
check_command check_dhcp
notifications_enabled 0
}
define service{
use local-service
host_name server2
service_description DNS
check_command check_dns
notifications_enabled 0
}
7、配置nagios.cfg,添加监控节点
vim /usr/local/nagios/etc/nagios.cfg
添加:
cfg_file=/usr/local/nagios/etc/objects/192.168.1.2.cfg
8、重启服务
killall -9 nagios
systemctl start nagios &
若无法启动,实验另一种启动方式
/etc/init.d/nagios start
Reloading systemd: [ 确定 ]
Starting nagios (via systemctl):
pc1 访问192.168.1.1/nagios
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |