Nagios是一个常用的“状态监控”系统,能及时、准确的发现系统状态的变化,在系统运维中发挥着重要的作用。
系统环境:CentOS Linux
1. 安装前的准备
安装Nagios之前需要系统安装下面几个软件包:
Apache
PHP
GCC compiler
GD development libraries
使用下面的命令安装
yum install httpd php
yum install gcc glibc glibc-common
yum install gd gd-devel
yum install mysql mysql-devel (使用系统的mysql库,或者自定义,可以编译出check_mysql等与mysql相关的检查工具)
2. 建立Nagios运行账号
/usr/sbin/useradd -m nagios
passwd nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
3. 下载
cd /usr/local/src
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.2.0.tar.gz
wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz
4. 编译安装Nagios
cd /usr/local/src
tar xzf nagios-3.2.0.tar.gz
cd nagios-3.2.0
./configure –with-command-group=nagcmd –prefix=/opt/nagios-3.2.0
make all
make install #安装二进制程序
make install-init #安装init脚本
make install-config #安装样例配置文件
make install-commandmode # 设置扩展命令目录权限
5. 修改配置
首先要修改的配置是管理员的邮箱地址,编辑配置文件/opt/nagios-3.2.0/etc/objects/contacts.cfg。
6. 配置web界面
cd /usr/local/src/nagios-3.2.0
make install-webconf
设置访问帐户
htpasswd -c /opt/nagios-3.2.0/etc/htpasswd.users nagiosadmin
7. 编译安装nagios-plugins
cd /usr/local/src
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure –with-nagios-user=nagios –with-nagios-group=nagios –prefix=/opt/nagios-3.2.0
make
make install
8. 启动Nagios
chkconfig –add nagios
chkconfig nagios on
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #校验配置文件
如果没有配置错误
service nagios start
9. 修改SELinux
假如系统没有关闭SELinux子系统:
查看 SELinux 是否运行在 Enforcing 模式.
getenforce
设置 SELinux 运行至 Permissive 模式.
setenforce 0
要永久的使之生效需要修改配置文件 /etc/selinux/config 然后重启系统。
为了安全起见,在不关闭SELinux或者将SELinux模式设置成 Permissive 模式的情况下,可以通过下面的设置允许在SELinux的enforcing/targeted模式下运行CGIs:
chcon -R -t httpd_sys_content_t /opt/nagios-3.2.0/sbin/
chcon -R -t httpd_sys_content_t /opt/nagios-3.2.0/share/