标签:options ini conf 1.5 监控主机 mkdir Opens mat nagios配置
Nagios 简介 :主机 | 系统 | IP地址 |
---|---|---|
nagios | CentOS 7.4 | 192.168.100.130 |
被监控 | CentOS 7.4 | 192.168.100.131 |
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
useradd -M -s /sbin/nologin nagios
mkdir /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios
yum -y install gcc gcc-c++ make perl openssl-devel
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.1.tar.gz
tar zxvf nagios-4.3.1.tar.gz
cd nagios-4.3.1/
./configure --prefix=/usr/local/nagios
make all
make install
make install-init # 把nagios做成一个运行脚本,使nagios随系统开机启动
make install-commandmode # 给外部命令访问nagios配置文件的权限
make install-config # 把配置文件样例复制到nagios的安装目录
chkconfig --add /etc/rc.d/init.d/nagios
chkconfig --level 35 nagios on
chkconfig --list nagios
[root@localhost nagios-4.3.1]# ls /usr/local/nagios/
bin etc libexec sbin share var #查看文件是否存在
tar zxvf nagios-plugins-1.5.tar.gz -C /opt/
cd /opt/nagios-plugins-1.5
./configure --prefix=/usr/local/nagios
make && make install
yum -y install httpd php
vim /etc/httpd/conf/httpd.conf
User nagios #管理用户和组修改成nagios
Group nagios
DirectoryIndex index.html index.php #添加 index.php
AddType application/x-httpd-php .php #添加可识别 php
# 为了安全起见,一般情况下要让nagios 的web 监控页面必须经过授权才能访问
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" #末尾添加
<Directory "/usr/local/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
[root@localhost ]# htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadm #用户名 nagiosadm
New password: #密码
Re-type new password:
Adding password for user nagiosadm
systemctl start httpd.service
systemctl start nagios.service
cd /usr/local/nagios/etc/objects
vim templates.cfg #定义主机和服务模板的配置文件
contact_groups test #5个全部修改 定义联系组的名称
vim hosts.cfg #hosts.cfg主要用来指定被监控的主机地址以及相关属性信息(不能有任何空格)
define host{
use linux-server #引用主机linux-server的属性信息,linux-server主机在templates.cfg文件中进行了定义。
host_name Nagios-Linux #主机名
alias Nagios-Linux #主机别名
address 192.168.100.131 #被监控的主机地址,这个地址可以是ip,也可以是域名。
}
#定义一个主机组
define hostgroup{
hostgroup_name bsmart-servers#主机组名称,可以随意指定。
alias bsmart servers#主机组别名
members Nagios-Linux#主机组成员,其中“Nagios-Linux”就是上面定义的主机。
}
vim services.cfg #主要用于定义监控的服务和主机资源
define service{
use local-service #引用local-service服务的属性值,local-service在templates.cfg文件中进行了定义。
host_name Nagios-Linux #指定要监控哪个主机上的服务,“Nagios-Server”在hosts.cfg文件中进行了定义。
service_description check-host-alive #对监控服务内容的描述,以供维护人员参考。
check_command check-host-alive #指定检查的命令。
}
vim contacts.cfg #定义联系人和联系人组的配置文件(不能有空格)
define contact{
contact_name nagiosadm #联系人的名称,这个地方不要有空格
use generic-contact #引用generic-contact的属性信息,其中“generic-contact”在templates.cfg文件中进行定义
alias Nagios Admin
email xxxxxx@xx.com #邮箱
}
define contactgroup{
contactgroup_name test #联系人组的名称,同样不能空格
alias Technical Support #联系人组描述
members nagiosadm #联系人组成员,其中“nagiosadm”就是上面定义的联系人,如果有多个联系人则以逗号相隔
}
cd /usr/local/nagios/etc/
vim cgi.cfg #文件用来控制相关cgi脚本
#由于nagios的web监控界面验证用户为nagiosadm,所以只需在cgi.cfg文件中添加此用户的执行权限
#末尾添加
default_user_name=nagiosadm
authorized_for_system_information=nagiosadmin,nagiosadm
authorized_for_configuration_information=nagiosadmin,nagiosadm
authorized_for_system_commands=nagiosadm
authorized_for_all_services=nagiosadmin,nagiosadm
authorized_for_all_hosts=nagiosadmin,nagiosadm
authorized_for_all_service_commands=nagiosadmin,nagiosadm
authorized_for_all_host_commands=nagiosadmin,nagiosadm
vim nagios.cfg #将对象配置文件在Nagios.cfg文件中进行引用
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg #添加
cfg_file=/usr/local/nagios/etc/objects/services.cfg #添加
command_check_interval=10s #该变量用于设置nagios对外部命令检测的时间间隔
[root@localhost ]# /etc/init.d/nagios checkconfig
Running configuration check...
OK.
systemctl restart nagios.service
标签:options ini conf 1.5 监控主机 mkdir Opens mat nagios配置
原文地址:http://blog.51cto.com/13640803/2164499