我这里安装的均为当前最新的稳定版本:
nagios-4.0.8
nagios-plugins-2.0.3
安装如下:
安装前准备工作
使用root用户操作服务器,需要以下软件环境:
Apache
PHP
DCC编译器
GD开发库
可通过yum进行安装:
yum install httpd php
yum install gcc glibc glibc-common
yum install gd gd-devel
- 创建用户和用户组
useradd -m nagios
passwd nagios
Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.
/usr/sbin/groupadd nagcmd /usr/sbin/usermod -a -G nagcmd nagios /usr/sbin/usermod -a -G nagcmd apache
2. 下载Nagios和Nagios插件
创建文件夹/software 将下载的文件放到/software目录下
官网下载:http://www.nagios.org/download
3. 编译安装nagios
# cd /software
# tar -zxvf nagios-4.0.8.tar.gz
# cd nagios-4.0.8
Run the Nagios configure script, passing the name of the group you created earlier like so:
./configure --with-command-group=nagcmd
Compile the Nagios source code.
make all
Install binaries, init script, sample config files and set permissions on the external command directory.
make install make install-init make install-config make install-commandmode
Don't start Nagios yet - there's still more that needs to be done...
4. Customize Configuration
Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You'll need to make just one change before you proceed...
Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you'd like to use for receiving alerts.
vi /usr/local/nagios/etc/objects/contacts.cfg
5. Configure the Web Interface
Install the Nagios web config file in the Apache conf.d directory.
make install-webconf
Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account - you'll need it later.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin //这里我将密码设为123456
Restart Apache to make the new settings take effect.
service httpd restart
Note: Consider implementing the ehanced CGI security measures described here to ensure that your web authentication credentials are not compromised.
6. 安装nagios插件
cd /software
tar -zxvf nagios-plugins-2.0.3.tar.gz
cd nagios-plugins-2.0.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
7. 启动nagios
将nagios加入开机启动
chkconfig --add nagios
chkconfig nagios on
验证nagios配置文件是否有错:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果没有错误,则启动nagios:
service nagios start
8. 关闭selinux
vim /etc/selinux/config
将SELINUX=enforcing 改为 SELINUX=disabled
修改后需重启系统生效。
临时生效:
# setenforce 0
9. 在浏览器中登录
用户名为nagiosadmin 密码为刚才配置的123456
http://localhost/nagios/
我这里吧默认80端口改成了800了,如下图:
当前系统默认监控的本机的项目:
10. nagios配置文件说明
nagios安装完成后主目录为/usr/local/nagios 所有的配置文件在/usr/local/nagios/etc目录下:
cgi.cfg
htpasswd.users //用于web端登录时的验证,上文中添加的
nagios.cfg //nagios主配置文件,如果监控其他主机,需要在里面添加其他主机的配置文件
resource.cfg //定义了nagios插件的位置
其中objects目录也是非常重要的目录,绝大部分操作都会在这里进行,他的默认文件有:
commands.cfg //命令定义文件,其中的命令可被其他配置文件引用
contacts.cfg //定义联系人和联系人组的文件
localhost.cfg //监控本机的文件
printer.cfg //监控打印机的模板文件,默认没有启用
switch.cfg //监控路由器的模板文件,默认没有启用
templates.cfg //定义主机和服务的模板配置文件,可在其他配置文件中引用
timeperiods.cfg //定义nagios监控时间段的配置文件
windows.cfg //监控windows主机的配置文件,默认没有启用
监控本机:
在/usr/local/nagios/etc/nagios.cfg中加入本机的监控,默认已经添加:
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
本机配置文件默认监控了8项服务Current load,Current Users,HTTP,PING,Root Partition,SSH,Swap Usage,Total Processes
添加一个对本机/data分区的监控:
vim localhost.cfg
在后面添加
define service{
use local-service
host_name localhost
service_description Data Partition
check_command check_local_disk!20%!10%!/data
notifications_enabled 1
}
保存重启nagios服务,登录web即可看到。
Nagios发送邮件的设置:
下载sendmail http://caspian.dotconf.net/menu/Software/SendEmail/
cd /usr/local/
tar -zxvf sendEmail-v1.56.tar.gz
复制执行程序 cp sendEmail-v1.56/sendEmail /usr/local/bin/
发件测试:
# sendEmail -f nagios@domain.com -t 7344506@qq.com -s mail.domain.com -u "This is subject" -xu nagios -xp passpwd -m This is content.
解释:
-f 表示发送者的邮箱
-t 表示接收者的邮箱
-s 表示SMTP服务器的域名或者ip
-u 表示邮件的主题
-xu 表示SMTP验证的用户名
-xp 表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
-m 表示邮件的内容
修改commands.cfg
vim /usr/local/nagios/etc/objects/commands.cfg
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$
\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | sendEmail -f nagios@domain.com -t $CONTACTEMAIL$ -s mail.domain.com -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAM
E$ is $HOSTSTATE$ **" $CONTACTEMAIL$ -xu nagios -xp password
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTA
DDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | sendEmail -f nagios@domain.com -t $CONTACTEMAIL$ -s mail.domain.com -u "** $NOTIFIC
ATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ -xu nagios -xp password
}
保存并重启nagios服务。
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索密码
, 文件
, 监控
, 配置
, make
objects
centos6.5安装nagios、centos nagios 安装、centos7安装nagios、centos7下安装nagios、centos nagios,以便于您获取更多的相关知识。