安装nagios
#安装所需要的软件包
yum -y install httpd gcc glibc glibc-common gd gd-devel
#创建一个nagios的帐号并给定登录口令
useradd nagios
passwd nagios
#创建一个用户组:nagcmd,用于从web接口执行外部命令。将nagios用户和apache用户都添加到这个组中
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache
#下载Nagios
wget http://ncu.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.1.1/nagios-4.1.1.tar.gz
tar -zxvf nagios-4.1.1.tar.gz
cd nagios-4.1.1.tar.gz
./configure --with-command-group=nagcmd
make all
(安装 二进制运行程序、初始化脚本、配置文件样本、设置运行目录权限)
make install
make install-init
make install-config
make install-commandmode
#修改email地址
vi /usr/local/nagios/etc/objects/contacts.cfg
#配置web接口
(安装nagios的web配置文件到apache的conf.d目录下)
make install-webconf
(创建nagios web接口登录)
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
(重启apache服务使设置生效)
service httpd start
#编译安装nagios插件
wget http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
tar -zxvf nagios-plugins-2.1.1.tar.gz
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
#启动nagios(有报错请查看日志,逐一解决)
(编辑/usr/local/nagios/etc/nagios.cfg可设置查看日志路径log_file)
mkdir -p /usr/local/nagios/var/spool/checkresults
mkdir -p /usr/local/nagios/var/archives
chmod 777 -R /usr/local/nagios/var/
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
chkconfig --add nagios
chkconfig nagios on
service nagios start
#登录nagios(web接口)
http://localhost/nagios/