---修改yum升级服务器[iyunv@localhost ~]# cd /etc/yum.repos.d[iyunv@localhost yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.bak[iyunv@localhost yum.repos.d]# wget http://centos.ustc.edu.cn/CentOS-Base.repo
---更新软件[iyunv@localhost yum.repos.d]# yum update
---安装以下必备软件[iyunv@localhost yum.repos.d]# yum install httpd[iyunv@localhost yum.repos.d]# yum install gcc[iyunv@localhost yum.repos.d]# yum install glibc glibc-common[iyunv@localhost yum.repos.d]# yum install gd gd-devel
---添加nagios用户、nagcmd组等
[iyunv@localhost yum.repos.d]# cd [iyunv@localhost ~]# useradd -m nagios[iyunv@localhost ~]# passwd nagios---nagios[iyunv@localhost ~]# groupadd nagcmd[iyunv@localhost ~]# usermod -a -G nagcmd nagios[iyunv@localhost ~]# usermod -a -G nagcmd apache
---安装nagios
[iyunv@localhost ~]# mkdir -p ~/downloads[iyunv@localhost ~]# cd ~/downloads[iyunv@localhost downloads]# wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.3/nagios-3.2.3.tar.gz[iyunv@localhost downloads]# wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz[iyunv@localhost downloads]# tar xzf nagios-3.2.3.tar.gz[iyunv@localhost downloads]# cd nagios-3.2.3[iyunv@localhost nagios-3.2.3]# ./configure --with-command-group=nagcmd --with-gd-lib=/usr/lib --with-gd-inc=/usr/include [iyunv@localhost nagios-3.2.3]# make all[iyunv@localhost nagios-3.2.3]# make install[iyunv@localhost nagios-3.2.3]# make install-init[iyunv@localhost nagios-3.2.3]# make install-config[iyunv@localhost nagios-3.2.3]# make install-commandmode
[iyunv@localhost nagios-3.2.3]# cp /usr/local/nagios/etc/objects/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg.bak[iyunv@localhost nagios-3.2.3]# vi /usr/local/nagios/etc/objects/contacts.cfg---修改nagiosadmin:email
[iyunv@localhost nagios-3.2.3]# make install-webconf[iyunv@localhost nagios-3.2.3]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin---nagios
[iyunv@localhost nagios-3.2.3]# service httpd restart
---安装nagios-plugins
[iyunv@localhost nagios-3.2.3]# cd ~/downloads[iyunv@localhost downloads]# tar xzf nagios-plugins-1.4.15.tar.gz[iyunv@localhost downloads]# cd nagios-plugins-1.4.15[iyunv@localhost nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios[iyunv@localhost nagios-plugins-1.4.15]# make[iyunv@localhost nagios-plugins-1.4.15]# make install
---安装nagios-snmp-plugins
[iyunv@localhost nagios-plugins-1.4.15]# cd ~/downloads[iyunv@localhost downloads]# wget http://nagios.manubulon.com/nagios-snmp-plugins.1.1.1.tgz[iyunv@localhost downloads]# tar xzf nagios-snmp-plugins.1.1.1.tgz[iyunv@localhost downloads]# cd nagios_plugins[iyunv@localhost nagios_plugins]# perl -MCPAN -e shell
cpan> install Net::SNMP
[iyunv@localhost nagios_plugins]# ./install.sh
---其它设置
[iyunv@localhost nagios_plugins]# cd [iyunv@localhost ~]# chkconfig --add nagios[iyunv@localhost ~]# chkconfig nagios on[iyunv@localhost ~]# chkconfig httpd on[iyunv@localhost ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg---检测配置[iyunv@localhost ~]# service nagios start
[iyunv@localhost ~]# cp /etc/sysconfig/selinux /etc/sysconfig/selinux.bak[iyunv@localhost ~]# vi /etc/sysconfig/selinux---SELINUX=permissive
---安装mysql
[iyunv@localhost ~]# yum -y install mysql[iyunv@localhost ~]# yum -y install mysql-server[iyunv@localhost ~]# yum -y install mysql-devel[iyunv@localhost ~]# yum -y install php-mysql
[iyunv@localhost ~]# chkconfig --levels 345 mysqld on[iyunv@localhost ~]# service mysqld start
[iyunv@localhost ~]# mysqlSET PASSWORD FOR 'root'@'localhost' = PASSWORD('mysql');
[iyunv@localhost yum.repos.d]# yum install php
---安装cacti
[iyunv@localhost ~]# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm[iyunv@localhost ~]# rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm[iyunv@localhost ~]# yum install rrdtool[iyunv@localhost ~]# yum install net-snmp net-snmp-utils net-snmp-devel
[iyunv@localhost ~]# yum install cacti---php-mysql,php-pdo,php-snmp
[iyunv@localhost conf.d]# vi cacti.conf
Alias /cacti/ /usr/local/wwwroot/cacti/<Directory /usr/local/wwwroot/cacti/> DirectoryIndex index.php Options -Indexes AllowOverride all order deny,allow allow from all AddType application/x-httpd-php .php php_flag magic_quotes_gpc on php_flag track_vars on</Directory>
[iyunv@localhost ~]# mysql -u root -pMysql>create database cacti;Mysql>use cacti;Mysql>source /usr/local/wwwroot/cacti/cacti.sqlMysql>grant all privileges on cacti.* to cacti@localhost identified by 'cacti';Mysql>flush privileges;
---apache设置
[iyunv@localhost ~]# vi /var/www/cacti/include/config.php
$database_type = "mysql";$database_default = "cacti";$database_hostname = "localhost";$database_username = "cacti";$database_password = "cacti";$database_port = "3306";
---安装ndoutils,实现nagios采集数据写入mysql
[iyunv@localhost ~]# wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz[iyunv@localhost ~]# tar zxf ndoutils-1.4b9.tar.gz[iyunv@localhost ~]# cd ndoutils-1.4b9[iyunv@localhost ndoutils-1.4b9]# ./configure --enable-mysql --disable-pgsql --with-mysql-lib=/usr/lib/mysql[iyunv@localhost ndoutils-1.4b9]# make[iyunv@localhost ndoutils-1.4b9]# cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
[iyunv@localhost ndoutils-1.4b9]# vi /usr/local/nagios/etc/nagios.cfg
check_external_commands=1command_check_interval=-1event_broker_options=-1broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfgprocess_performance_data=1
[iyunv@localhost ndoutils-1.4b9]# cd src/[iyunv@localhost src]# cp file2sock log2ndo ndo2db-3x ndomod-3x.o /usr/local/nagios/bin/[iyunv@localhost src]# cp ndo2db-3x /usr/local/nagios/bin/ndo2db[iyunv@localhost src]# cd ..[iyunv@localhost ndoutils-1.4b9]# cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
[iyunv@localhost ndoutils-1.4b9]# cd /usr/local/nagios/etc/[iyunv@localhost etc]# cp ndomod.cfg ndomod.cfg.bak[iyunv@localhost etc]# cp ndo2db.cfg ndo2db.cfg.bak[iyunv@localhost etc]# cat ndomod.cfg|grep -v '^#'|sed /^$/dinstance_name=defaultoutput_type=tcpsocketoutput=127.0.0.1tcp_port=5668output_buffer_items=5000buffer_file=/usr/local/nagios/var/ndomod.tmpfile_rotation_interval=14400file_rotation_timeout=60reconnect_interval=15reconnect_warning_interval=15data_processing_options=-1config_output_options=2[iyunv@localhost etc]# cat ndo2db.cfg|grep -v '^#'|sed /^$/dlock_file=/usr/local/nagios/var/ndo2db.lockndo2db_user=nagiosndo2db_group=nagiossocket_type=tcpsocket_name=/usr/local/nagios/var/ndo.socktcp_port=5668db_servertype=mysqldb_host=localhostdb_port=3306db_name=cactidb_prefix=npc_db_user=cactidb_pass=cactimax_timedevents_age=1440max_systemcommands_age=10080max_servicechecks_age=10080max_hostchecks_age=10080max_eventhandlers_age=44640max_externalcommands_age=44640debug_level=1debug_verbosity=1debug_file=/usr/local/nagios/var/ndo2db.debugmax_debug_file_size=1000000
[iyunv@localhost etc]# chown nagios /usr/local/nagios/etc/*[iyunv@localhost etc]# chgrp nagios /usr/local/nagios/etc/*
alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output; alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output; alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output; alter table npc_notifications add long_output TEXT NOT NULL default '' after output; alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output; alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output; alter table npc_statehistory add long_output TEXT NOT NULL default '' after output; alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output;