ZONE="Asia/Shanghai"
UTC=false
ARC=false
/bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
/etc/init.d/ntpd stop
ntpdate us.pool.ntp.org
hwclock -w
/etc/init.d/ntpd restart
chkconfig ntpd on
passwd nagios
usermod -G nagcmd nagios
usermod -G nagcmd apache
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#验证nagios.cfg文件是否有错,建议每次修改配置文件后都验证一下,确认无误后重启nagios服务
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#关闭selinux
vi /etc/selinux/config
将'SELINUX=enforcing'改成'SELINUX=disabled'
setenforce 0
#启动apache服务,并设置为开机启动
service httpd start
chkconfig httpd on
#启动nagios服务,并设置为开机启动
service nagios start
chkconfig nagios on
#检查开启情况
ps -ef //检查进程
访问:http://10.2.0.250/nagios/,输入用户名密码,便可打开nagios的web管理接口
至此,主监控服务器上的nagios配置完毕。
yum install -y sendmail*
2、开启服务,并设置为开机启动
service sendmail start
chkconfig sendmail on
3、设置sendmail邮件接收和转发功能
vi /etc/mail/access
添加如下内容:
Connect:http://www.163.com RELAY
Connect:nagios@localhost.localdomain RELAY
Connect:root@localhost RELAY
:wq
makemap -v hash /etc/mail/access.db < /etc/mail/access
4、更改mqueue权限
chmod 777 /var/spool/mqueue
5、检查所传送的电子邮件是否送出,或滞留在邮件服务器中
/usr/lib/sendmail -bp
若屏幕显示为“Mail queue is empty” 的信息,表示mail 已送出
6、发送邮件进行检查
echo testing | /usr/sbin/sendmail -v someone@somedomain.com
注释掉原来的define contact,并添加如下内容:
define contact{
contact_name yang_ang0219
use generic-contact
alias nagios admin
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email yang_ang0219@yeah.net
}
并修改联系人组,修改成如下内容:
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members yang_ang0219
}
安装pnp4nagios-0.6.7
tar zxvf pnp4nagios-0.6.7.tar.gz
cd pnp4nagios-0.6.7
./configure --with-nagios-user=nagios --with-nagios-group=nagcmd&& make all &&make install &&make install-webconf &&make install-config &&make install-init &&cd ..
4、修改配置
cd /usr/local/pnp4nagios/etc
cp misccommands.cfg-sample misccommands.cfg
cp nagios.cfg-sample nagios.cfg
cp npcd.cfg-sample npcd.cfg
cp process_perfdata.cfg-sample process_perfdata.cfg
cp rra.cfg-sample rra.cfg
cd pages
cp web_traffic.cfg-sample web_traffic.cfg
cd ../check_commands
cp check_all_local_disks.cfg-sample check_all_local_disks.cfg
cp check_nrpe.cfg-sample check_nrpe.cfg
cp check_nwstat.cfg-sample check_nwstat.cfg
5、启动npcd服务并设置为开机启动
service npcd start
6、修改nagios.cfg文件
cd /usr/local/nagios/etc
vi nagios.cfg
修改配置如下:
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
:wq
7、修改commands.cfg文件
cd /usr/local/nagios/etc/objects
vi commands.cfg
修改process-host-perfdata和process-service-perfdata为:
#'process-host-perfdata' command definitio
define command{
command_name process-host-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}
#'process-service-perfdata' command definition
define command{
command_name process-service-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl
}
:wq
8、修改模板,添加小太阳镶嵌在nagios页面上
vi templates.cfg
在最后添加:
define host{
name host-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}
define service{
name srv-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
:wq
9、修改主机配置文件:
define host{
use linux-server,host-pnp ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name localhost
alias localhost
address 127.0.0.1
}
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members localhost ; Comma separated list of hosts that belong to this group
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description Current Users
check_command check_local_users!20!50
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
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,srv-pnp ; Name of service template to use
host_name localhost
service_description Swap Usage
check_command check_local_swap!20!10
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 0
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description HTTP
check_command check_http
notifications_enabled 0
}
10、删除instal.php
cd /usr/local/pnp4nagios/share
rm -f install.php
11、验证配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
12、无误后重启nagios和httpd 服务
service nagios restart
service httpd restart
cat /usr/local/nagios/etc/ndo2db.cfg |grep -v '^#'|sed /^$/d
ndo2db_user=nagios
ndo2db_group=nagios
socket_type=tcp
socket_name=/usr/local/nagios/var/ndo.sock
tcp_port=5668
db_servertype=mysql
db_host=127.0.0.1
db_port=3306
db_name=cacti
db_prefix=npc_
db_user=cactiuer
db_pass=cactiuser
max_timedevents_age=1440
max_systemcommands_age=10080
max_servicechecks_age=10080
max_hostchecks_age=10080
max_eventhandlers_age=44640
debug_level=1
debug_verbosity=1
debug_file=/usr/local/nagios/var/ndo2db.debug
max_debug_file_size=1000000
instance_name=default
output_type=tcpsocket
output=127.0.0.1
tcp_port=5668
output_buffer_items=5000
buffer_file=/usr/local/nagios/var/ndomod.tmp
file_rotation_interval=14400
file_rotation_timeout=60
reconnect_interval=15
reconnect_warning_interval=15
data_processing_options=-1
config_output_options=2
command_check_interval=-1
event_broker_options=-1
process_performance_data=1
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
find / -name *json.so