Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。
1.Yum 安装所需的软件包和支持库
Yum install -y httpd httpd-manualhttpd-devel gd gd-devel perl-GDmysql-server mysql-devel php php-mysql php-gd php-pear perl-DBIperl-Digest-SHA1 perl-Digest-HMAC net-snmp-utils perl-socket6 perl-IO-INET6 net-snmp-devel php-snmp dmidecode net-snmp-perl perl-Crypt-DES fping perl-Config-IniFiles graphviz gcc-c++ glib2-devel php-gd php-pdo php-ldap php-mbstring php-xml lib
Yum -y install gcc openssl-devel pcre-devel zlib-devel
2.Sendmail部署
Ø首先要确保sendmail相关组件的完整安装,我们可以使用如下的命令来完成sendmail的安装:
# yum install -y sendmail*
Ø然后重新启动sendmail服务:
# service sendmail restart
Ø然后发送测试邮件,验证sendmail的可用性:
# echo "Hello World" | mail abc@abc.com
mail yanjuxian@126.com test
sdf(内容)
ctrl +D
Nagios 之前的准备,特别需要安装 Gd-devel,另外安装Nagios时需要加 –with-gd-lib=/usr/lib –with-gd-inc=/usr/include;不然不能生成 statusmap.cgi 也就不能看到状态图了
1.创建运行帐户
Groupadd nagios
Useradd –g nagios nagios
Passwd nagios
Mkdir /usr/local/nagios
Chown –R nagios:nagios /usr/local/nagios
Chmod 755 /usr/local/nagios/
Usermod –G nagios apache
Grep ^User /etc/httpd/conf/httpd.conf
User apach
查看运行Apache的帐户
2.Nagios主程序安装:
Tar zxvf nagios-3.4.3.tar.gz
Cd nagios-3.4.3
./configure –prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-inc=/usr/include --enable-event-broker
Make all
Make all install
Make install-init //安装启动脚本到/etc/init.d/
Make install-commandmode
Make install-config //安装初始配置文件到/usr/local/naigos
3.Nagios-plugins的安装
Tar zxvf nagios-plugins-1.4.14.tar.gz
Cd nagios-plugins-1.14
./configure –prefix=/usr/local/nagios-plugins
Make
Make install
安装完成以后在/usr/local/nagios-plugins 会产生一个Libexc的目录,将该目录全部移动至/User/local/nagios目录下即可。
如下:
Mv /usr/local/nagios-plugins/libexec /usr/local/nagios/
4.现在配置Apache:
在apache的httpd.conf文件中加入以下内容:
Vi /etc/httpd/conf/httpd.conf
ScriptAlias /nagios/cgi-bin/usr/local/nagios/sbin
<Directory"/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile/usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios /usr/local/nagios/share
<Directory"/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile/usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
重启Apache
Service httpd restart
#vi/usr/local/nagios/etc/objects/contacts.cfg
修改Nagiosadmin 这行其中的邮件地址为你的Email地址,以将报警邮件发到你的邮箱
5.设置登陆Web 界面时HTTP验证的帐户密码
Htpasswd –c/usr/local/nagios/etc/htpasswd.users nagiosadmin
重启动apache
Service httpd restart
重启动Nagios
Service nagios restart
6.配置和启动Nagios
7.Cd /usr/local/nagios/etc
里面如果有cfg-sample,就把目录里的cgf-sample文件全部拷贝成.cfg例如:
Cp nagios.cfg-sample nagios.cfg
没有的话直接修改:
Vi cgi.cfg
Use_authentication=1 改称 use_authentication=0 即不用验证,不然有些页面不会显示。
8.修改后用如下命令检查配置文件是否正常:
/usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg
如果出现如下显示就是说明配置没问题
Total Warnings:0
Total Errors:0
如果有错误,用以下命令检查那里有错误:
CD /usr/local/nagios/bin/ -d /usr/local/nagios/etc/nagios.cfg
Chown –R nagios.nagios nagios.log
Service nagios restart
Nagios部署完毕
Http://IP/nagios/
1.配置Contacts.cfg
1.vim /etc/nagios/objects/contacts.cfg
2.
3.define contact{ //30行
4. contact_name nagiosadmin
5.use generic-contact
6. alias Nagios Admin
7. email xxxx@163.com //这里改成自己的邮箱
8. }
2.配置Nagios.cfg和Localhost.cfg
查看复制打印?
1.vim /etc/nagios/nagios.cfg
2.
3.enable_notifications=1 //807行,开启报警
4.确认nagios.cfg里面的interval_length,通过那个,算出相应的
5.normal_check_interval比如interval_length=60,那
6.normal_check_interval=10
7.max_check_attempts=3
8.retry_check_interval=1
9.这样就实现在10分钟一次检测,重试3次,重试时间1分钟!
10.
11.上面的总的开启也就是nagios装的所有插件,出现问题都会报警
12.
13.vim /etc/nagios/objects/localhost.cfg
14.
15.define service{ //以processes为例
16.use local-service ; Name of service template to use
17. host_name localhost
18. service_description Total Processes
19. check_command check_local_procs!250!400!RSZDT
20. notifications_enabled 1
21. }
22.
如果总的没有开启,Localhost,cfg里面可以一个一个配置,这样比较麻烦,如果总的开启了,里面的不想启动就可以Notifications_enables设置成0这样,就不会发报警,其他的发送报警。
3.添加发报警用户
1.[root@localhost objects]# cyradm -u cyrus localhost --auth plain
2.verify error:num=18:self signed certificate
3.Password:
4.IMAP Password:
5.localhost> cm nagios
6.localhost> quit
可以看一下nagios发邮件配置文件commands.cfg
4.配置Templates.cfg
Check_interval 5 检测时间;
Retry_interval 1 重试间隔;
Max_check_attempts 10 最大重试次数;
Notification_interval 120 通告间隔,默认2个小时,这个设定的是再次发送通告的周期,
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。