接着昨天lamp安装成功后,我们开始安装nagios
详细安装如下:
nagios安装
1、安装nagios
- groupadd nagcmd
- useradd -d /home/nagios -s /sbin/nologin -G nagcmd nagios
- ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagcmd
- make all
- make install
- make install-init
- make install-config
- make install-commandmode
- make install-webconf
编辑apache配置文件
vim /usr/local/apache/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
- Require valid-user
- AddHandler cgi-script cgi pl
- AddDefaultCharset utf-8
- </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
- Require valid-user
- </Directory>
保存退出。
创建apache目录验证文件
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd admin
有了第一个用户后,后面再添加用户,不要加-C,否则会覆盖已存在的用户。
重启apache
/usr/local/apache/bin/apachectl restart
添加nagios开机启动
chkconfig --add nagios
chkconfig nagios on
安装nagios-plugins
- tar xvzf nagios-plugins-1.4.14.tar.gz
- ./configure
- make && make install
安装nrpe
- tar xvzf nrpe-1.8.tar.gz
- ./configure
- make all
修改cgi的配置文件:
vim /usr/local/nagios/etc/cgi.cfg
#是否开启验证,1是开启0是关闭
use_authentication=1
#修改默认用户
- default_user_name=admin
- authorized_for_system_information=nagiosadmin,admin
- authorized_for_configuration_information=nagiosadmin,admin
- authorized_for_system_commands=admin
- authorized_for_all_services=nagiosadmin,admin
- authorized_for_all_hosts=nagiosadmin,admin
- authorized_for_all_service_commands=nagiosadmin,admin
- authorized_for_all_host_commands=nagiosadmin,admin
修改nagios的主配置文件nagios.cfg
#添加或修改下面的配置
- log_file=/usr/local/nagios/var/nagios.log #日志文件
- 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/contactgroups.cfg # 联系组配置文件路径
- cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg # 监视时段配置文件路径
- cfg_file=/usr/local/nagios/etc/objects/templates.cfg # 模板的配置文件路径
- cfg_file=/usr/local/nagios/etc/objects/escalations.cfg
- cfg_file=/usr/local/nagios/etc/objects/hosts.cfg # 主机配置文件路径
- cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg # 主机组配置文件路径
- cfg_file=/usr/local/nagios/etc/objects/services.cfg # 服务配置文件路径
- cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
- cfg_file=/usr/local/nagios/etc/objects/windows.cfg #windows 服务器监控
- #此段自己随便起名
- cfg_dir=/usr/local/nagios/etc/servers/squid
- cfg_dir=/usr/local/nagios/etc/servers/iis
- cfg_dir=/usr/local/nagios/etc/servers/sql
- cfg_dir=/usr/local/nagios/etc/servers/tomcat
- cfg_dir=/usr/local/nagios/etc/servers/guoke
- cfg_dir=/usr/local/nagios/etc/servers/cdn
保存退出
其余的配置项个人因具体情况而定。
至此,重新加载nagios配置文件
service nagios reload
在浏览器中打开:
http://ip地址/nagios
提示输入账户,密码后,看到nagios的页面则表示安装成功。
此处切记nagios版本号,我初次安装时使用nagios-cn.3.2.3版本,但是后来远程管理功能无法使用,多方检查,权限等都是好的,咋试都不行,后来重新编译安装3.2.0,反而一装就好,最后确认为版本问题。