需要LNMP环境
sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/*
[BaseOS]
name=BaseOS
baseurl=file:///media/cdrom/BaseOS
enabled=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=file:///media/cdrom/AppStream
enabled=1
gpgcheck=0
echo 'export LC_ALL=C' >>/etc/profile
source /etc/profile
/etc/init.d/iptables stop
chkconfig iptables off
sed -i 's/SELINUX=enforcing/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
systemctl restart chronyd
yum install -y gcc glibc glibc-common gd gd-devel mysql-server httpd php php-gd -y
useradd nagios
useradd apache -M -s /sbin/nologin
groupadd nagcmd
usermod -aG nagcmd nagios
usermod -aG nagcmd apache
/etc/init.d/httpd start
检查 lsof -i :80
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.0.tar.gz(需FQ)
tar xf nagios-3.5.0.tar.gz
cd nagios
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
htpasswd -bc /usr/local/nagios/etc/htpasswd.users syh 123 #设置nagios页面用户名和密码
/etc/init.d/httpd reload
添加监控报警信息接收的email地址
vim /usr/local/nagios/etc/objects/contacts.cfg +35
******@qq.com
修改原email地址为接收报警的邮箱地址
安装第三方邮件服务
yum install mailx
修改/etc/mail.rc,添加如下配置
set from=[email protected]
set smtp=smtp.163.com
set smtp-auth-user=pshyms
set smtp-auth-password=xxxx #这里要写SMTP授权码,需要到邮箱设置中开通
set smtp-auth=login
使用mail命令发送邮件:
echo "邮件内容"|mail -s 标题 [email protected]
mail -s 标题 [email protected] < file
/etc/init.d/httpd start
chkconfig httpd on
此时浏览器访问http://192.168.0.236/nagios(ip 为服务端地址)会出现用户名和密码提示窗口
yum install perl-devel openssl-devel -y
wget http://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
tar xf
cd
./configure --with-nagios-user=nagios \
--with-nagios-group=nagios \
--enable-perl-modules \
--with-mysql
make && make install
ls /usr/local/nagios/libexec/| wc -l
wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
或wget https://jaist.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz
tar zxvf nrpe-2.14.tar.gz
cd nrpe-2.14
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
chkconfig nagios on
或者 echo "/etc/init.d/nagios start >> /etc/rc.local
验证nagios配置文件(检查语法) /etc/init.d/nagios checkconfig
使用命令检查报错 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
启动nagios服务 /etc/init.d/nagios start
三. 客户端安装
yum install gcc glibc glibc-common mysql-server perl-devel perl-CPAN openssl-devel -y
添加nagios用户
useradd nagios -M -s /sbin/nologin
安装nagios-plugins插件
wget http://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
tar xf
cd
./configure --with-nagios-user=nagios \
--with-nagios-group=nagios \
--enable-perl-modules \
--with-mysql
make && make install
wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
tar zxvf nrpe-2.14.tar.gz
cd nrpe-2.14
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
yum install sysstat -y #系统监控包
配置监控内存,磁盘I/O脚本插件
cd /usr/local/nagios/etc/nrpe.cfg的79行添加监控端IP,例如allowed_hosts=127.0.0.1,192.168.0.236
在199-203行为监控内容,需要根据需求进行调整修改
注释掉老的
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 15% -c 7% -p /
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
启动nrpe守护进程
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrep.cfg -d
netstat -lntup | grep nrpe
ps -ef | grep nrpe
需要注意的是每次修改nrpe.cfg文件都需要重启守护进程,可以pkill nrpe,再执行上面命令
可将上面命令加入/etc/rc.local中进行nrpe开机自启动