##安装环境ucloud云主机centos6.4_64系统并做好初始化工作
mkdir -p /data/software yum -y install httpd gcc glibc glibc-common *gd* php php-mysql mysql mysql-server mysql-devel openssl openssl-devel cd /data/software wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz wget http://nchc.dl.sourceforge.net/project/nagios-cn/sourcecode/zh_CN%203.2.3/nagios-cn-3.2.3.tar.bz2 wget http://cznic.dl.sourceforge.net/project/nagios/ndoutils-2.x/ndoutils-2.0.0/ndoutils-2.0.0.tar.gz wget http://nchc.dl.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz wget http://iweb.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz wget http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.21.tar.gz
创建nagios并加入nagcmd组
useradd -s /sbin/nologin nagios groupadd nagcmd usermod -G nagcmd nagios usermod -G nagcmd apache
安装nagios中文版
tar jxf nagios-cn-3.2.3.tar.bz2 cd nagios-cn-3.2.3 ./configure --with-command-group=nagcmd --enable-event-broker make all &&make install &&make install-init && make install-config&&make install-commandmode&&make install-webconf htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin ##此处输入nagiosadmin的密码 cd ..
安装nagios-plugin
tar zxvf nagios-plugins-2.0.3.tar.gz cd nagios-plugins-2.0.3 ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd make && make install cd .. echo 'date.timezone = PRC' >> /etc/php.ini ##安装nagiosql时候需要设置时区 service httpd restart && service nagios restart chkconfig httpd on && chkconfig nagios on
安装nrpe
tar zxvf nrpe-2.13.tar.gz cd nrpe-2.13 ./configure && make all && make install
安装ndoutlis
tar zxvf ndoutils-2.0.0.tar.gz cd ndoutils-2.0.0 ./configure --enable-mysql make cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /usr/local/nagios/bin/ mysql -uroot -p ##进入数据库 mysql>create database 库名; mysql>grant all on 库名.* to 用户名@localhost identified by '密码'; mysql>flush privileges; mysql>exit cd db/ ./installdb -u ndouser -p 1234qwer -hlocalhost -d 库名 #导入表结构 cd .. cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg chmod 774 /usr/local/nagios/bin/* chown nagios.apache /usr/local/nagios/bin/* chown nagios.apache /usr/local/nagios/etc/* chmod 644 /usr/local/nagios/etc/* vim /usr/local/nagios/etc/ndo2db.cfg ##修改ndo2db配置文件 socket_type=unix 改成 socket_type=tcp db_port=3306 改成 db_port=8904 ##使用8904 db_name= 改成 db_name=nagios_db db_user=ndouser #连接数据库的用户名 db_pass= #连接数据库的密码 保存退出 vim /usr/local/nagios/etc/ndomod.cfg output_type=unixsocket 改成 output_type=tcpsocket output=/usr/local/nagios/var/ndo.sock 改成 output=127.0.0.1 保存退出 cp /data/software/ndoutils-2.0.0/daemon-init /etc/init.d/ndo2db chmod +x /etc/init.d/ndo2db chkconfig ndo2db on chkconfig nagios on mv /usr/local/nagios/bin/ndo2db-3x /usr/local/nagios/bin/ndo2db vim /usr/local/nagios/etc/nagios.cfg 添加broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg nagios -v /usr/local/nagios/etc/nagios.cfg #有权限报错则chmod 775 /usr/local/nagios -R 给予权限 service nagios restart service ndo2db restart
安装pnp出图
yum install -y pango pango-devel freetype freetype-devel libpng libpng-devel gettext gettext-devel libjpeg yum install -y libjpeg-devel gd gd-devel libxml2 libxml2-devel libiconv libiconv-devel qpixman qpixman-devel glib glib-devel cairo cairo-devel libart* cd /data/software yum install rrdtool rrdtool-perl -y #yum安装rrdtool tar zxvf pnp4nagios-0.6.21.tar.gz cd pnp4nagios-0.6.21/ ./configure --prefix=/usr/local/pnp4nagios/ --with-nagios-user=nagios --with-nagios-group=nagcmd yum install perl-Time-HiRes ./configure --prefix=/usr/local/pnp4nagios/ --with-nagios-user=nagios --with-nagios-group=nagcmd make all && make install && make install-webconf && make install-config && make install-init vim /usr/local/nagios/etc/nagios.cfg cd /usr/local/pnp4nagios/etc/ mv misccommands.cfg-sample misccommands.cfg mv nagios.cfg-sample nagios.cfg mv rra.cfg-sample rra.cfg cd pages/ mv web_traffic.cfg-sample web_traffic.cfg cd ../check_commands/ mv check_all_local_disks.cfg-sample check_all_local_disks.cfg mv check_nrpe.cfg-sample check_nrpe.cfg mv check_nwstat.cfg-sample check_nwstat.cfg service npcd restart chkconfig npcd --add chkconfig npcd on 修改nagios.cfg相关配置文件中参数 process_performance_data=1 #将此变量值设为1 host_perfdata_command=process-host-perfdata service_perfdata_command=process-service-perfdata #取消这两项的注释 cd /usr/local/nagios/etc/objects vim commands.cfg #对nagios命令配置文件进行设置 # 'process-host-perfdata' command definition define command{ command_name process-host-perfdata command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl } # 'process-service-perfdata' command definition define command{ command_name process-service-perfdata command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl } #添加上面两行在文件的末行 ,并删除或注释掉原有对process-host-perfdata和process-service-perfdata进行定义的字段 vim templates.cfg #对nagios的模板配置文件进行修改 define host { name host-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_ register 0 } define service { name srv-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$ register 0 } #在模版中添加pnp4nagios的定义 cp ../pnp4nagios-0.6.14/contrib/ssi/* /usr/local/nagios/share/ssi/ #回到解压目录下,复制鼠标悬停图标显示,预览绘图所需的文件 tar zxvf ndoutils-2.0.0.tar.gz cd ndoutils-2.0.0 ./configure --enable-mysql make cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /usr/local/nagios/bin/ mysql -uroot -p ##进入数据库 mysql>create database nagios; mysql>grant all on nagios.* to ndouser@localhost identified by '1234qwer'; mysql>flush privileges; mysql>exit cd db/ ./installdb -u ndouser -p 1234qwer -hlocalhost -d nagios #导入表结构 cd .. cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg chmod 774 /usr/local/nagios/bin/* chown nagios.apache /usr/local/nagios/bin/* chown nagios.apache /usr/local/nagios/etc/* chmod 644 /usr/local/nagios/etc/* vim /usr/local/nagios/etc/ndo2db.cfg ##修改ndo2db配置文件 socket_type=unix 改成 socket_type=tcp db_port=3306 改成 db_port=8904 ##使用8904 db_name= 改成 db_name=nagios_db db_user=ndouser #连接数据库的用户名 db_pass= #连接数据库的密码 保存退出 vim /usr/local/nagios/etc/ndomod.cfg output_type=unixsocket 改成 output_type=tcpsocket output=/usr/local/nagios/var/ndo.sock 改成 output=127.0.0.1 保存退出 cp /data/software/ndoutils-2.0.0/daemon-init /etc/init.d/ndo2db chmod +x /etc/init.d/ndo2db chkconfig ndo2db on chkconfig nagios on mv /usr/local/nagios/bin/ndo2db-3x /usr/local/nagios/bin/ndo2db vim /usr/local/nagios/etc/nagios.cfg 添加broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg service nagios restart service ndo2db restart cd /data/software tar zxvf nagiosql_320.tar.gz mv nagiosql32/ /usr/local/nagios/nagiosql chown -R nagios.nagios /usr/local/nagios/nagiosql/ chown -R nagios.nagcmd /usr/local/nagios/nagiosql/ chmod 774 /usr/local/nagios/nagiosql/config/ cd /usr/local/nagios/nagiosql/ ll mkdir -p etc/{hosts,services,backup/{hosts,services},import} chown -R nagios.nagcmd . chmod -R 755 . chmod 777 /usr/local/nagios/nagiosql/config/ chown nagios:nagios /usr/local/nagios/bin/nagios chmod 750 /usr/local/nagios/bin/nagios chown -R nagios.nagios /usr/local/nagios/var/spool/ chown nagios:nagios /usr/local/nagios/var/rw/nagios.cmd chmod 660 /usr/local/nagios/var/rw/nagios.cmd touch /usr/local/nagios/nagiosql/install/ENABLE_INSTALLER cat >> /etc/httpd/conf/httpd.conf <<EOF Alias /nagiosql "/usr/local/nagios/nagiosql" <Directory /usr/local/nagios/nagiosql> Options None AllowOverride None Order allow,deny Allow from all </Directory> EOF service httpd restart
在浏览器中打开 http://IP/nagiosql设置nagiosql
选择语言
删除安装目录,这里使用改权限:chmod 000 /usr/local/nagios/nagiosql/install
按照nagios和nagiosql的路径修改对应
如果提示没有权限或者执行报错。
则需检查/usr/local/nagios/ 目录及底下目录的权限
建议使用 chmod 777 -R /usr/local/nagios