四、nagios服务端配置与启动
1)、文件说明
nagios.cfg #nagios主配置文件
cgi.cfg #cgi配置文件 commands.cfg #命令配置文件 contacts.cfg #联系人配置文件 resource.cfg #定义插件路径文件 templates.cfg、timeperiods.cfg 组,监控时间段等配置文件 linux.cfg #用户自定义文件,监控linux主机,定义主机配置文件 windows.cfg #用户自定义文件,监控windows主机,定义主机配置文件 l-services.cfg #用户自定义文件,定义linux主机服务配置文件 w-services.cfg #用户自定义文件,定义windows主机服务配置文件 2)、cgi.cfg文件配置
root@nagios#cd /usr/local/nagios/etc
vi cgi.cfg #以下是需要修改的地方 authorized_for_system_information=nagiosadmin,test authorized_for_configuration_information=nagiosadmin,test authorized_for_system_commands=nagiosadmin,test authorized_for_all_services=nagiosadmin,test authorized_for_all_hosts=nagiosadmin,test authorized_for_all_service_commands=nagiosadmin,test authorized_for_all_host_commands=nagiosadmin,test use_authentication=0 #修改为0,不然监控访问的时候会出现以下提示
It appears as though you do not have permission to view information for any of the hosts you requested...
If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file. 3)、配置nagios.cfg文件
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg cfg_file=/usr/local/nagios/etc/objects/templates.cfg # wb config cfg_dir=/usr/local/nagios/etc/linux #配置linux主机加载自定义文件的目录(下面包括linux.cfg、l-services.cfg文件) cfg_dir=/usr/local/nagios/etc/windows #配置win主机加载自定义文件的 目录(包括windows.cfg、w-services.cfg) 4)、配置commands.cfg命令配置文件
define command{
command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } define command{ command_name check_mysql_health #定义mysql监控命令 command_line $USER1$/check_mysql_health --hostname $ARG1$ --port $ARG2$ --username $ARG3$ --password $ARG4$ --mode $ARG5$ } define command{ command_name notify-service-by-sms #定义飞信监控命令 command_line /usr/local/tools/install/fetion --mobile=159230***** --pwd=2255*** --to=$CONTACTPAGER$ --msg-gb="$HOSTNAME$ $SERVICEDESC$ is $SERVICESTATE$ on $TIME$ result is $SERVICEOUTPUT$" $CONTACTPAGER$ } notify-host-by-email、notify-service-by-email这二项是定义mail报警的命令,默认文件有这二项 5)、配置contacts.cfg联系人配置文件
define contact{
contact_name nagiosadmin use generic-contact
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands notify-service-by-email,notify-service-by-sms host_notification_commands notify-host-by-email email http://www.360doc.com/mailto:test@test.com,http://www.360doc.com/mailto:test@163.com pager 1592304****
} #email 定义联系人报警mail地址
#pager 定义联系人报警手机号码
#notify-service-by-email、notify-service-by-sms、notify-host-by-email、要与commands.cfg命令配置文件里的相对应 6)、linux.cfg主机配置文件
#====================linux server=====================
define host{ use generic-host host_name cvs-1.11 alias cvs-server address 192.168.1.11 check_command check-host-alive max_check_attempts 10 check_period 24x7 notification_interval 20 notification_period 24x7 notification_options d,r contact_groups admins name cvs-1.11 #定义名字 } define host{ use generic-host host_name web-1.72 alias web-server address 192.168.1.72 use cvs-1.11 #调用cvs-1.11的配置 } 7)、windows.cfg配置文件
##############windows host################
define host{
use generic-host host_name windows-1.8 alias win-server address 192.168.1.8 check_command check-host-alive max_check_attempts 10 check_period 24x7 notification_interval 20 notification_period 24x7 notification_options d,r contact_groups admins name windows-1.8 #定义名字 } define host{ use generic-host host_name windows-1.71 alias web-server address 192.168.1.71 use windows-1.8 #调用windows-1.8配置文件 } 8)、l-services.cfg定义服务配置文件
define service{ use generic-service host_name cvs-1.11 #与l-linux.cfg主机服务的名字相对应 service_description HTTP status is_volatile 0 #类似声音警告功能关闭 check_period 24x7 #监控期限为24X7 max_check_attempts 3 #最大检测3次 normal_check_interval 1 #每一分钟检测一次 retry_check_interval 1 #间隔1分钟检测 contact_groups admins #监控组 notification_options w,u,c,r # w,u,c,r 发生这四种情况时,进行通告 notification_interval 5 # 通告间隔 notification_period 24x7 #检测时间段 check_command check_http } check_command监控命令有
check-host-alive、check_nrpe!check_disk1、check_nrpe!check_load、check_nrpe!check_total_procs、check_nrpe!check_swap等
9)、w-services.cfg配置文件
define service{
use generic-service host_name windows-1.8 service_description NSClient++ Version is_volatile 0 check_period 24x7 max_check_attempts 3 normal_check_interval 1 retry_check_interval 1 contact_groups admins notification_options w,u,c,r notification_interval 5 notification_period 24x7 check_command check_nt!CLIENTVERSION } define service{
use generic-service host_name windows-1.8 service_description E:\ Drive Space is_volatile 0 check_period 24x7 max_check_attempts 3 normal_check_interval 1 retry_check_interval 1 contact_groups admins notification_options w,u,c,r notification_interval 5 notification_period 24x7 check_command check_nt!USEDDISKSPACE!-l e -w 80 -c 90 } # 如果要监控c 盘,check_nt!USEDDISKSPACE!-l c -w 80 -c 90 这里的c表示是c盘
check_command命令有
check_nt!UPTIME、check_nt!MEMUSE!-w 80 -c 90、(-w 80 -c 90)为当内存使用到80%为warning警告,内存使用到90%为critical紧急,check_nt!USEDDISKSPACE!-l c -w 80 -c 90、check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe等。
10)、linux 客户端的安装配置与启动
tar zxvf nrpe-2.8.1.tar.gz cd nrpe-2.8.1 ./configure –prefix=/usr/local/nrpe make make install 10.1)、添加nagios用户组,并设置权限
root@client#useradd nagios -s /sbin/nologin
chown -R nagios.nagios /usr/local/nrpe 10.2)、需要把nagios监控服务器里的/usr/local/nagios/libexec下面的5个文件cp到 /usr/local/nrpe/libexec目录下
cp /usr/local/nrpe/libexec/check_nrpe /usr/local/nagios/libexec cp /usr/local/nagios/libexec/check_disk /usr/local/nrpe/libexec cp /usr/local/nagios/libexec/check_load /usr/local/nrpe/libexec cp /usr/local/nagios/libexec/check_ping /usr/local/nrpe/libexec cp /usr/local/nagios/libexec/check_procs /usr/local/nrpe/libexec 10.3)、配置nrpe.cfg文件
mkdir /usr/local/nrpe/etc 创建目录
复制nrpe解压目录下的nrpe.cfg文件以 /usr/local/nrpe/etc目录下
cp /root/nrpe/nrpe.cfg /usr/local/nrpe/etc 修改nrpe.cfg文件 server_port=5666 #端口 server_address=192.168.1.56 #服务器IP allowed_hosts=127.0.0.1,192.168.1.56 #充许nagios服务器IP访问 10.4)启动nrpe服务
10.4.1)、以独立守护进程启动nrpe服务
/usr/local/nrpe/bin/nrpe –c /usr/local/nrpe/etc/nrpe.cfg -d 10.4.2)、检测nrpe服务是否正常启动
[root@nagios nrpe]# netstat -nltp | grep nrpe tcp 0 0 192.168.1.56:5666 0.0.0.0:* LISTEN 2233/nrpe 能查看到5666这端口,说明nrpe启动正常
11)、配置windows主机的nrpe服务
修改c:\Program Files\NSClient++\NSC.ini文件
FileLogger.dll
CheckSystem.dll CheckDisk.dll NSClientListener.dll NRPEListener.dll SysTray.dll CheckEventLog.dll CheckHelpers.dll CheckWMI.dll #把前面的;分给去掉
allowed_hosts=127.0.0.1/32,192.168.1.56 #添加nagios监控服务器的IP,充许nagios服务器访问 打开nsclient++ 服务,选择属性---登陆---本地系统账户---(选择)充许服务与桌面交互,重启nsclient++服务
net stop nsclient net start nsclient 五、启动nagios监控服务器
1)、检查配置
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Checking misc settings...
Total Warnings: 0
Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check 2)、启动nagios服务
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg /etc/init.d/nagios restart #重新启动nagios服务
3)、nagios监控页面如下 [url]http://localhost/nagios[/url]
-----------------------------------------------------------------------------------------------------------------------
|
|