引用大神文章出处:https://blog.51cto.com/12173069/2070827
安装环境
服务端:docker 环境 centos7 IP 172.172.0.110
客户端:docker 环境 centos7 IP 172.172.0.40
一、更改yum源
1.删除旧的源
rm -rf /etc/yum.repos.d/*
2.下载repo文件
wget -O /etc/yum.repos.d/centos7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/centos7-epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
3.生成缓存
yum clean all
yum makecache
二、服务端配置
1.安装软件
yum -y install nagios nagios-plugins nagios-plugins-all nagios-plugins-nrpe nrpe
2.修改nagios主配置文件
vi /etc/nagios/nagios.cfg
添加该行
cfg_dir=/etc/nagios/conf.d #确保其中有这行代码
3.修改cgi配置文件,添加用户
vi /etc/nagios/cgi.cfg
authorized_for_system_information=nagiosadmin,lee
authorized_for_configuration_information=nagiosadmin,lee
authorized_for_system_commands=nagiosadmin,lee
authorized_for_all_services=nagiosadmin,lee
authorized_for_all_hosts=nagiosadmin,lee
authorized_for_all_service_commands=nagiosadmin,lee
authorized_for_all_host_commands=nagiosadmin,lee
4.修改命令配置文件command.cfg
vi /etc/nagios/objects/commands.cfg
#添加
define command{
command_name check_nrpe
command_line $USER1/check_nrpe -H $HOSTADDRESS -c $ARG1
}
5.修改联系人配置文件:
vi /etc/nagios/objects/contacts.cfg
define contact{
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
email 696721**@qq.com
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}
6.添加远程主机的监控指令(可以用本地配置文件/etc/nagios/objects/localhost.cfg作为模板)
创建目录
mkdir /etc/nagios/conf.d/
cp -arf /etc/nagios/objects/localhost.cfg /etc/nagios/conf.d/lee.cfg
vi /etc/nagios/conf.d/lee.cfg
define host{
use linux-server
host_name lee
alias lee
address 172.172.0.40 #被监控客户机
}
#去掉这组定义
#define hostgroup{
# hostgroup_name linux-servers
# alias Linux Servers
# members lee
# }
define service{
use local-service
host_name lee
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service
host_name lee
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
define service{
use local-service
host_name lee
service_description Current Users
check_command check_local_users!20!50
}
define service{
use local-service
host_name lee
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}
define service{
use local-service
host_name lee
service_description Current Load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
define service{
use local-service
host_name lee
service_description Swap Usage
check_command check_local_swap!20!10
}
define service{
use local-service
host_name lee
service_description SSH
check_command check_ssh
notifications_enabled 0
}
define service{
use local-service
host_name lee
service_description HTTP
check_command check_http
notifications_enabled 0
}
7.检查配置文件语法:
nagios -v /etc/nagios/nagios.cfg
8.修改nagios相关目录权限:
chown nagios.nagios /etc/logrotate.d/nagios
chmod g+w /etc/logrotate.d/nagios
chown -R nagios.nagios /etc/nagios
9.设置apache账户密码:
htpasswd -c /etc/nagios/passwd lee
10.启动服务:
systemctl start httpd
systemctl start nagios
三、客户端配置
1.客户端同步修改yum源操作
2.安装软件
yum -y install nagios-plugins nagios-plugins-nrpe nrpe
3.修改 nrpe 主配置文件
vi /etc/nagios/nrpe.cfg
#添加服务端ip
allowed_hosts=127.0.0.1,172.172.0.110
4.启动nrpe服务
systemctl start nrpe
5.测试