本文基于以下部分编辑:
Nagios的安装和配置
Nagios的插件监控
Nagios的扩展
注:本环境默认安装在/usr/local/nagios中 nagios版本:nagios-4.2.4 插件版本:nagios-plugins-2.1.2实验环境如下:
Host Name | OS | IP | Software |
---|---|---|---|
Nagios-Server | CentOS 7 | 192.168.32.129 | Apache、Php、Nagios、nagios-plugins |
Nagios-Client | CentOS 7 | 192.168.32.138 | nagios-plugins、nrpe |
Nagios的安装和配置
nagios-server
Nagios的组成部分: 守护进程 web界面 插件
LAMP环境的部署
yum install gcc php httpd php-gd gd gd-devel mysql* -y
ntpdate统一系统时间
yum install -y ntpdate
ntpdate cn.pool.ntp.org
安装nagios的相关依赖库文件
yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel unzip
添加用户并授权
mkdir /usr/local/nagios
useradd nagios -s /sbin/nologin -M
chown nagios:nagios /usr/local/nagios/
ll -d /usr/local/nagios/
下载并安装
chmod a+x nagios-4.2.4.tar.gz
tar zxvf nagios-4.2.4.tar.gz -C /usr/local/src
cd /usr/local/src/nagios4.2.4/
./configure --prefix=/usr/local/nagios
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
检查是否生成了对应httpd的web配置文件
ls -al /etc/httpd/conf.d/
结果如下:
cd /usr/local/nagios/ #查看是否有以下几个目录
bin:Nagios可执行程序所在目录
etc:Nagios配置文件所在目录
sbin:nagios CGI文件所在目录,也就是执行外部命令所需要文件的所在的目录
share: nagios网页文件所在的目录
libexec: nagios外部插件 所在目录
var: nagios日志文件,lock等文件所在的目录
为nagios添加默认登陆名nagiosadmin 并设置密码
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
启动nagios服务和httpd服务并设置为开启自启
/etc/init.d/httpd start
/etc/init.d/nagios start
chkconfig httpd on
chkconfig nagios on
安装nagios-plugin
chmod a+x nagios-plugins-2.1.2.tar.gz
tar zxvf nagios-plugins-2.2.1.tar.gz -C /usr/local/src/
cd /usr/local/src/nagios-plugins-2.2.1
./configure --prefix=/usr/local/nagios/
make && make install
登陆网页localhost/nagios输入用户名和密码进入网站
Nagios-Client
ntpdate统一系统时间
yum install -y ntpdate
ntpdate cn.pool.ntp.org
安装nagios的相关依赖库文件
yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel unzip
添加用户并授权
mkdir /usr/local/nagios
useradd nagios -s /sbin/nologin -M
chown nagios:nagios /usr/local/nagios/
ll -d /usr/local/nagios/
安装nagios-plugin
chmod a+x nagios-plugins-2.1.2.tar.gz
tar zxvf nagios-plugins-2.2.1.tar.gz -C /usr/local/src/
cd /usr/local/src/nagios-plugins-2.2.1
./configure --prefix=/usr/local/nagios/
make && make install
安装NRPE服务
tar zxvf nrpe-3.2.1.tar.gz -C /usr/local/src/
cd /usr/local/src/nrpe-3.2.1
./configure --prefix=/usr/local/nagios/
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
修改守护进程
参考:http://blog.51cto.com/yangrong/1408526
Nagios-Service
If you plan on running nrpe under inetd or xinetd and making use of TCP wrappers, you need to add a line to your /etc/services file as follows (modify the port number as you see fit)
nrpe 5666/tcp # NRPE
#在only from处添加监控主机的IP地址
[root@Nagios-Client]# vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 192.168.32.129,192.138.32.138
}
在/etc/services中添加nrpe和端口号
[root@localhost nrpe-2.13]# /etc/init.d/xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@localhost nrpe-2.13]# netstat -lntup | grep 5666
tcp 0 0 :::5666 :::* LISTEN 26483/xinetd
Nagios-Client
#在only from处添加监控主机的IP地址
[root@localhost nrpe-2.13]# vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 192.168.10.7
}
在/etc/services中添加nrpe和端口号
nrpe2.PNG
确认已经监听5666端口,服务端安装nrpe不需要添加主机ip,客户机需要添加主机ip
[root@localhost nrpe-2.13]# /etc/init.d/xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@localhost nrpe-2.13]# netstat -lntup | grep 5666
tcp 0 0 :::5666 :::* LISTEN 26483/xinetd