nagios
- 一. 服务端安装准备
- 二. 安装配置 nagios服务端
环境为centos8.5,记得换指令
一. 服务端安装准备
需要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
- 解决perl软件编译问题
echo 'export LC_ALL=C' >>/etc/profile
source /etc/profile
- 关闭防火墙和selinux
/etc/init.d/iptables stop
chkconfig iptables offsed -i 's/SELINUX=enforcing/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
- 解决系统时间同步问题
crontab -e中添加
*/5 * * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1
systemctl restart chronyd
- 安装服务器所需软件包
yum install -y gcc glibc glibc-common gd gd-devel mysql-server httpd php php-gd -y
- 创建nagios服务器所需用户及组
useradd nagios
useradd apache -M -s /sbin/nologin
groupadd nagcmd
usermod -aG nagcmd nagios
usermod -aG nagcmd apache
- 启动HTTP服务
/etc/init.d/httpd start
检查 lsof -i :80
二. 安装配置 nagios服务端
- 下载nagios并编译
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
- 安装nagios web配置文件及创建登陆用户
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=pshyms@163.com
set smtp=smtp.163.com
set smtp-auth-user=pshyms
set smtp-auth-password=xxxx #这里要写SMTP授权码,需要到邮箱设置中开通
set smtp-auth=login使用mail命令发送邮件:
echo "邮件内容"|mail -s 标题 xxx@163.com
mail -s 标题 xxx@163.com < file
- 配置启动Apache服务
/etc/init.d/httpd start
chkconfig httpd on
此时浏览器访问http://192.168.0.236/nagios(ip 为服务端地址)会出现用户名和密码提示窗口
- 安装nagios插件软件包
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 installls /usr/local/nagios/libexec/| wc -l
- 安装nrpe软件
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.gztar zxvf nrpe-2.14.tar.gz
cd nrpe-2.14
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
- 配置并启动nagios服务
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
- 安装nrpe软件
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脚本插件
- 配置nagios客户端nrpe服务
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开机自启动