xiamn 发表于 2013-6-8 09:22:34

nagio cacti整合配置

所需软件:httpd-2.4.1.tar.gzmysql-5.0.96.tar.gz      php-5.3.25.tar.gznagios-3.2.0.tar.gz   nagios-plugins-1.4.16.tar.gz   nrpe-2.12.tar.gzrrdtool-1.4.8.tar.gzcacti-0.8.8a.tar.gz   cacti-spine-0.8.8a.tar.gzntop-v0.2-1.tgz   monitor-v1.3-1.tgzndoutils-1.5.2.tar.gznpc-2.0.4.tar.gzjson-1.2.1.tgzPDO_MYSQL-1.0.2.tgz一.设置lamp环境编译安装httpdShell>tar zxvf httpd-2.4.1.tar.gzShell>cd httpd-2.4.1Shell>./configure--prefix=/usr/local/apache --enable-soShell>make && make install编译安装msyqlShell>tar zxvf mysql-5.3.25.tar.gzShell>cd mysql-5.3.25Shell>./configure --prefix=/usr/local/mysql--enable-thread-safe-clientShell>make && make installShell>groupadd mysqlShell>useradd mysql -g mysqlShell>chown -r mysql.mysql /var/lib/mysqlShell>/usr/local/mysql/bin/mysql_install_db    ##初始化数据库##Shell>cp support-files/my-medium.cnf /etc/my.cnfShell>/usr/local/mysql/bin/mysqld_safe--defaults-file=/etc/my.cnf--user=root &   ##启动mysql##Shell>/usr/local/msyql/bin/mysqldadmin -uroot -p 123456   #修改mysql登陆密码##Shell>ps -ef |grep mysqld    ##查看mysq进程##编译安装Shell>tar zxvf php-5.3.25.tar.gzShell>cd php-5.3.25Shell>./confiugre --prefix=/usr/local/php--with--mysql=/usr/local/mysql   --with-apxs2=/usr/local/apache/bin/apxs--enable-sockets   --with-config-file-path=/usr/local/php/etc##修改php.ini的存放位置##Shell>make &&make installShell>cpphp.ini-production/etc/php.ini
安装pdo_mysql扩展模块Shell>tar zxvf    PDO_MYSQL-1.0.2.tgzShell>cd   PDO_MYSQL-1.0.2Shell>/usr/local/php/bin/phpizeShell>make && make installShell>vim/usr/local/php/etc/php.ini   extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20090626/"   extension = pdo_mysql.so重启apahce查看是否已加载php-m |grep pdo-mysql二、Apache php整合打开Apache配置文件httpd.conf添加PHPIniDir "/etc/php.ini"跳转到373后添加AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps
跳转到246行添加 index.php保存退出重启apacheShell>/usr/local/apache/bin/apachectl start测试apache,php是否整合Shell>vim /usr/local/apache/htdocs/text.php<?phpPhpinfo;?>打开浏览器输入http://ip/test.php,输出php信息说明配置成功
测试php mysql整合Shell>vim /usr/local/apache/htdocs/test.php<?php$link=mysql_connect("localhost","root","123456");if(!$link) echo "FAILD!";else echo "OK!";?>保存退出打开浏览器http://ip/test.php输出ok说明配置成功
三、安装nagiosShell>useradd -s /sbin/nologin nagiosShell>mkdir -p /usr/local/nagiosShell>chown -R nagios.nagios /usr/local/nagiosShell>usermod-Gnagios-aapache   ##将apache用户加入到nagios组中Shell>tar zxvf nagios-3.2.0.tar.gzShell>cd nagios-3.2.0Shell>./configure --prefix=/usr/local/nagiosShell>make allShell>make installShell>make install-initShell>make install-commandmodeShell>make install-config
安装nagios插件Shell>tar zxvf nagios-plugins-1.4.16.tar.gzShell>cd nagios-plugins-1.4.16Shell>./configure --prefix=/usr/local/nagiosShell>make && make install

打开apache配置文件httpd.conf 在末尾添加以后代码:ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin<Directory "/usr/local/nagios/sbin">   AuthType Basic   Options ExecCGI   AllowOverride None   Order allow,deny   Allow from all   AuthName "Nagios Access"   AuthUserFile /usr/local/nagios/etc/htpasswd   Require valid-user</Directory>
Alias /nagios /usr/local/nagios/share<Directory "/usr/local/nagios/share">   AuthType Basic   Options None   AllowOverride None   Order allow,deny   Allow from all   AuthName "nagios Access"   AuthUserFile /usr/local/nagios/etc/htpasswd   Require valid-user</Directory>
创建nagios登陆用户Shell>/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd admin   ##输入登陆密码修改nagios目录下cgi.cfgShell>vim /usr/local/nagios/etc/cgi.cfgauthorized_for_system_information=admin       #多个用户用逗号分隔authorized_for_configuration_information=adminauthorized_for_system_commands=adminauthorized_for_all_services=adminauthorized_for_all_hosts=adminauthorized_for_all_service_commands=adminauthorized_for_all_host_commands=admin
修改nagios目录下nagios.cfgcommand_check_interval=10s    ##检查时间间隔check_external_commands=1    ##允许web界面下重启、关闭nagios进程等
检查下nagios配置文件是否正确Shell>/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg修改apache 运行的用户Shell>vim /usr/local/apache/conf/httpd.conf    Userapache    Groupapache
启动nagiosShell>/usr/local/nagios/bin/nagios -d/usr/local/nagios/etc/nagios.cfg启动apacheShell>/usr/local/apache/bin/httpd -k start打开浏览器输入http://ip/nagios就可以看到nagios的主界面
四、安装nrpe被监控机上安装Shell>groupadd nagiosShell>useradd -g nagios -d/usr/local/nagios-s/sbin/nologinnagiosShell>tar zxvfnagios-plugins-1.4.16.tar.gzShell>cdnagios-plugins-1.4.16Shell>./configure --prefix=/usr/local/nagiosShell>make && make installShell>tar zxvf nrpe-2.12.tar.gzShell>cd nrpe-2.12Shell>./configureShell>make allShell>make instlal-pluginShell>make install-daemonShell> make install-daemon-configShell>chown-Rnagios.nagios/usr/local/nagios配置nrpeShell>vim /usr/local/nagios/etc/nrpe.cfgallowed_hosts=127.0.0.1,监控机ipShell>echo “nrpe:监控机ip” >>/etc/host.allow启动nrpeShell>/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -dShell>echo “/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d “ >>/etc/rc.local    ## 设置开机启动nrpe检查nrpe是否正常Shell>netstat -atnlp |grep 5666Shell>/usr/local/nagios/libexec/check_nrpe -H localhost    NRPE v2.12                      ##说明nrpe启动成功
监控机上安装Shell>tar zxvfnrpe-2.12.tar.gzShell>cd nrpe-2.12Shell>./configure --prefix=/usr/local/nagiosShell>makeShell>make install-plugin
测试是否可以连接被监控机Shell>/usr/local/nagios/libexec/check_nrpe-H被监控机ip   NRPE v2.12                  ##说明可以和被监控机通信
五.安装cacti安装rrdtoolShell>tar zxvfrrdtool-1.4.8.tar.gzShell>cd rrdtool-1.4.8Shell>./configureShell>make &&make install
安装net-snmpShell>yum install net-snmp* -y
配置mysqlShell>/usr/local/mysql/bin/mysql -uroot -pMysql>create database cactidb;Mysql>grant all privileges on cactidb.* to “cactier”@”locahost” identified by “123456”Mysql>grant all privileges on cactidb.* to “cactier”@”localhost” identified by “123456”
配置snmp.conf(红色字体为修改部分)Shell>vim /etc/snmp/snmp.conf    #       sec.namesource          community    com2sec notConfigUserdefault       public    #       name         incl/excl   subtree         mask(optional)    view    systemview    included   .1.3.6.1.2.1.1    view    systemview    included   .1.3.6.1.2.1.25.1.1    #       group          context sec.model sec.level prefix read   writenotif    accessnotConfigGroup ""      any       noauth    exact allnonenone    ##         incl/excl subtree                        maskview all    included.1                               80Shell>service snmpd start
安装cactiShell>tar zxvfcacti-0.8.8a.tar.gzShell>mvcacti-0.8.8a   cactiShell>mvcacti/usr/local/apache/htdocsShell>cd /usr/local/apache/htdocs/cactiShell>/usr/local/mysql/bin/mysql-uroot -pcactidb <cacti.sqlShell>chown -Rcactier /usr/local/apache/htdocs/cacti/rra   /usr/local/apache/htdocs/cacti/log编辑cacti/include/config.php文件Shell>vim /usr/local/apache/htdocs/cacti/config.php    $database_type = "mysql";    $database_default = "cactidb";    $database_hostname = "localhost";    $database_username = "cactier";    $database_password = "123456";    $database_port = "3306";保存退出Shell>useraddcactierShell>passwdcactierShell>crontab -u cactier -e*/1 * * * * */usr/bin/php /var/www/html/cacti/poller.php >/dev/null 2>&1登陆cacti打开浏览器输入http://ip/cacti   ---->设置注意第一次登陆cacti默认用户名和密码为admin,登陆后要修改密码

安装spineShell>tar zxvf   cacti-spine-0.8.8a.tar.gzShell>cd cacti-spine-0.8.8aShell>./configure--prefix=/usr/local/spineShell>make &&make installShell>mv /usr/local/spine/etc/spine.conf.dist   /usr/local/spine/etc/spine.confShell>vim /usr/local/spine/etc/spine.conf   DB_Host         localhost   DB_Database   cactidb   DB_User         cactier   DB_Pass         123456   DB_Port         3306   DB_PreG         0
Shell>ln -s/tmp/mysql.sock   /var/lib/mysql/mysql.sock
设置spine路径,Console——Settings——Paths--->>/usr/local/spine/bin/spine
更改cacti轮询器为spine,Console——Settings——Poller--->>poller type:spine    -->>Poller Interval:every minute   Cron Interval:every minuteShell>/usr/local/spine/bin/spine

整合ntop monitor到cacti中Shell>tar zxvfntop-4.0.tar.gzShell>cdntop-4.0Shell>./autogen.shShell>./configure --prefix=/usr/local/ntopShell>make && make installShell>chown -Rntop.ntop/usr/local/ntop/share/ntopShell>chown -Rntop.ntop/usr/local/ntop/var/ntop配置启动ntopShell>ntop-A    输入密码Shell>n/usr/local/ntop/bin/top -i eth0 -d -L -u ntopShell>echo '/usr/local/ntop/bin/ntop -i eth0 -d -L -u ntop &> /dev/null' >> /etc/rc.local
安装ntop插件Shell>tar zxvfntop-v0.2-1.tgz-C/usr/local/apache/htdocs/cacti/plugins/Shell>vim /usr/local/apache/htdocs/cacti/include/config.php    添加$plugins[] = "ntop";
设置cacti: console---utilities---user managemet---admin---plugin managementview ntop两个选项选上,保存   console---configureation---plugin management---启用ntop
安装monitorShell>tar zxvfmonitor-v1.3-1.tgz-C/usr/local/apache/htdocs/cacti/plugins/Shell>vim /usr/local/apache/htdocs/cacti/include/config.php   添加$plugins[] = "monitor";设置cacti:略(步骤和安装ntop一样)

Nagios、cacti整合安装ndoutilsShell>tar zxvf    ndoutils-1.5.2.tar.gzShell>cd ndoutils-1.5.2Shell>./configure --prefix=/usr/local/nagios --enable-mysql --disable-pgsql   --with-mysql-inc=/usr/local/mysql/include   --with-mysql-lib=/usr/local/mysql/lib/mysqlShell>make&& make installShell>cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /usr/local/nagios/bin/Shell>./installdb -ucactier -p123456 -hlocalhost -d cactidbShell>cp -v config/{ndo2db.cfg-sample,ndomod.cfg-sample} /usr/local/nagios/etc/Shell>mv /usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfgShell>mv /usr/local/nagios/etc/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfgShell>chown -R nagios.nagios /usr/local/nagios/etc/ndo*Shell>chown -R nagios.nagios /usr/local/nagios/bin/*Shell>vim /usr/local/nagios/etc/nagios.cfg添加      broker_module=/usr/local/nagios/bin/ndomod-3x.o      config_file=/usr/local/nagios/etc/ndomod.cfg      event_broker_options=-1Shell>vim /usr/local/nagios/etc/ndo2db.cfg    socket_type=tcp    db_servertype=mysql    db_host=localhost    db_port=3306    db_name=cactidb    db_prefix=nagios_    db_user=cactier    db_pass=123456Shell>vim /usr/local/nagios/etc/ndomod.cfg      output_type=tcpsocket      output=127.0.0.1Shell>cp ./daemon-init /etc/init.d/ndo2dbShell> vi /etc/init.d/ndo2db# 检查里面的路径确保不会出现“//”,并将Ndo2dbBin修改成下面的值:Ndo2dbBin=/var/www/html/nagios/bin/ndo2db-3xShell>chmod +x /etc/init.d/ndo2dbShell>service ndo2db start查看是否有错误Shell>tail -f /var/logl/messages   或者    tail -f/usr/local/nagios/var/nagios.log
安装npcShell> tar zxvfnpc-2.0.4.tar.gz-C /usr/local/apache/htdocs/cacti/pluginsShell>vim /usr/local/apache/htdocs/cacti/include/config.php    添加$plugins[] = 'npc';
安装npc支持jsonShell>tar zxvfjson-1.2.1.tgzShell>cd json-1.2.1Shell>/usr/local/php/bin/phpizeShell>./configureShell>make && make install安装完后会有类似这样的提示:Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/查看是否有导入信息Shell>/usr/local/php/bin/php -i |grep php.ini##Configuration FileLoaded Configuration Filephp.ini路径Shell>vim/etc/php.ini    添加extension = json.so查看json 是否加载Shell>/usr/local/php/bin/php -m |grep json

修改ndo2db.cfg文件Shell>vim /usr/local/nagios/etc/ndo2db.cfg   db_prefix=nagios_   修改为db_prefix=npc_
修改cacti npc插件Console-->settings-->npc -->Remote Commands选项打勾--->输入nagios command file pathc -->输入nagios URL -->host icons   service icons选项打勾-->logging level选择DEBUG   保存

修改数据库表结构:Shell>/usr/local/mysql/bin/mysql-uroot -pMsyql>use cactidb;Msyql>ALTER TABLE `npc_hostchecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;ALTER TABLE `npc_hoststatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;ALTER TABLE `npc_servicechecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;ALTER TABLE `npc_servicestatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;ALTER TABLE `npc_statehistory` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;ALTER TABLE `npc_eventhandlers` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;ALTER TABLE `npc_systemcommands` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;ALTER TABLE `npc_notifications` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;Mysql>exit
重启ndo2db nagios 服务Shell>servicendo2dbrestartShell>/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

缘来路过 发表于 2013-6-8 09:27:28

俺从不写措字,但俺写通假字!

zhaolu 发表于 2013-6-8 09:43:56

路边的野花不要,踩。

hx0011yy 发表于 2013-6-8 10:33:26

做爱做的事,交配交的人。

hao1nan 发表于 2013-6-8 11:11:35

比我有才的都没我帅,比我帅的都没我有才!

fairyguo 发表于 2013-6-8 12:39:41

这是什么东东啊

jmton 发表于 2013-6-8 13:15:02

死亡教会人一切,如同考试之后公布的结果——虽然恍然大悟,但为时晚矣~!
页: [1]
查看完整版本: nagio cacti整合配置