文档章节

Centos6.3搭建cacti&nagios

雁南飞丶
 雁南飞丶
发布于 2014/08/16 20:39
字数 1859
阅读 52
收藏 0

CentOS版本: centos-x64 2.6.32-279.el6.x86_64 

nagios版本:Nagios  Core 3.4.2

Cacti版本: cacti-0.8.8a

Ntop:ntop-5.0.1

pnp:pnp4nagios-0.6.19


一、配置yum, 更换为163的源

 

1. 首先备份/etc/yum.repos.d/CentOS-Base.repo

         #mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

 

2. 下载对应版本repo文件, 放入/etc/yum.repos.d/(操作前请做好相应备份)

         #http://mirrors.163.com/.help/CentOS6-Base-163.repo

 

3. 修改repo文件名称

         #mv /etc/yum.repos.d/CentOS6-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo       

 

4. 运行yum makecache生成缓存

 

5. 安装rpmforge

         #rpm -ivh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm


二、安装包及相关软件

1. 每个人机器的环境不一样,我是用最小安装模式安装的centos,需要安装以上的包,如果还安装过程中提示缺少依赖包,请自行安装吧。

yum install httpd -y

yum install php php-mysql php-snmp php-gd -y

yum install mysql mysql-server mysql-devel -y

yum install net-snmp-utils -y

yum install rrdtool* -y

yum install gcc* -y

yum install gd gd-devel -y

yum install glibc* -y

yum install make.x86_64 automake -y

yum install openssl* -y

yum install perl-devel -y

yum install GeoIP GeoIP-devel -y

yum install ettercap  -y

yum install libpcap libpcap-devel -y

yum install gdbm gdbm-devel -y

yum install python python-libspython-devel -y

yum install wget  -y

yum install automake* -y

yum install libtool -y

yum install subversion -y

yum install libdbi libdbi-devel -y

yum install libdbi-dbd-mysql –y


2. 配置apache

  #vi/etc/httpd/conf/httpd.conf,确保有“LoadModule status_module modules/mod_status.so”这行并没有被注释,标示已经支持检测模块,然后启动apache:

         #servicehttpd start

    #chkconfig --level 35 httpd on  开机启动

 

3. 配置php

         #vi/var/www/html/index.php

         <?php

                   phpinfo();

         ?>

    访问http://localhost,验证php能够正常工作

 

4. 配置mysql

         #servicemysqld start    启动mysql

         #chkconfig--level 35 mysqld on    设置mysql开机启动

         #mysqladmin-u root password 'password'    设置root账号登陆密码

        

    #mysql-u root -p  使用root账号登陆

         mysql>create database cactidb;             创建数据库cactidb,并创建管理账号cactier

         mysql>GRANT all Privileges ON cactidb.* TO cactier@localhost IDENTIFIED BY 'password';        

         mysql>GRANT all Privileges ON cactidb.* TO cactier@127.0.0.1 IDENTIFIED BY 'password';

         mysql>flush privileges;                               更新权限设置

 

         创建mysql.php验证mysql数据库连接

         <?php

                   $link=mysql_connect("localhost","root","password");

                   if(!$link) echo"FAILD!";

                   else echo "OK!";

         ?>

         页面显示OK!表示连接正常。

 

5. 配置SNMP

    #vi/etc/snmp/snmpd.conf   编辑SNMP的配置文件,其中修改一下几行

         # First, map the community name "public"into a "security name"

         #      sec.name  source          community

        41 com2sec notConfigUser  default       public#默认的密码为“public”, 可以改为需要的密码

        62 access  notConfigGroup ""      any       noauth    exact  all none none

       85 view all    included  .1                               80

        #service snmpd start      启动SNMP服务

       #chkconfig--level 35 snmpd on        设置snmp服务开机启动


三、安装nagios

1. 设置nagios用户和组

         #/usr/sbin/useradd-m nagios

         #passwdnagios

         #/usr/sbin/groupaddnagios

         #/usr/sbin/usermod-a -G nagios nagios

 

2. 安装配置nagios

         #tarzxf nagios-3.4.2.tar.gz

         #cd nagios

         #./configure --with-gd-lib=/usr/lib64  --with-gd-inc=/usr/include --with-command-group=nagios--with-httpd-conf=/etc/httpd/conf/

         #makeall

         #makeinstall

         #makeinstall-init

         #makeinstall-config

         #makeinstall-commandmode

         #makeinstall-webconf

         #vi/usr/local/nagios/etc/objects/contacts.cfg

         #htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

        

         vi/etc/httpd/conf/httpd.conf

         添加:

         #nagios default settings

            Include /etc/httpd/conf/nagios.conf

         #service httpd restart

         访问http://IP/nagios

 

3. 安装nagios-plugins

         #tar zxf nagios-plugins-1.4.16.tar.gz

         #cd nagios-plugins-1.4.16

         #./configure--with-nagios-user=nagios --with-nagios-group=nagios

         #make

         #makeinstall

 

4. 安装 nagios-snmp

         #tar zxf CPAN-1.9800.tar.gz

         #cd CPAN-1.9800

         #perl Makefile.PL

         #make

         #make install

         #yuminstall perl-Time-HiRes -y

         #perl -MCPAN -e shell (ftp://freesoft.cgi.gov.cn/pub/languages/perl/CPAN )

         cpan>installNet::SNMP

        

         #tar zxf nagios-snmp-plugins.1.1.1.tgz

         #cd nagios_plugins

        

         #chkconfig --add nagios

          #chkconfig nagios on

         #/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

         #chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin

         #chcon -R -t httpd_sys_content_t /usr/local/nagios/share

         #servicenagios start


四、安装cacti

1. 安装

         #tar zxvf /root/cacti-0.8.8a.tar.gz

         #mv /root/cacti-0.8.8a /usr/local/cacti

         #mysql -u root -p cactidb < /usr/local/cacti/cacti.sql

         #vi/usr/local/cacti/include/config.php

         $database_type = "mysql";

         $database_default ="cactidb";

         $database_hostname ="localhost";

         $database_username ="cactier";

         $database_password ="password";

         $database_port = "3306";

           $database_ssl = false;

 

         #adduser -s /sbin/nologin cactier

         #cd /usr/local/cacti

         #chown -R cactier rra/ log/

         #vi/etc/crontab

                  */5* * * * cactier php /usr/local/cacti/poller.php > /dev/null &

 

         #vi /etc/httpd/conf/cacti.conf

         Alias /cacti "/usr/local/cacti"

         <Directory"/usr/local/cacti">

               OptionsFollowSymLinks MultiViews

               AllowOverrideNone

               Orderallow,deny

               Allowfrom all

         </Directory>

 

2. 配置

         #/usr/bin/php -q /usr/local/cacti/poller.php --force --debug

验证php是否有错误,如有:PHP Warning:  strtotime()或PHPWarning:  date()的警告信息,则 vi/etc/php.ini,修改“;date.timezone=”为“date.timezone= PRC”,然后重启httpd服务。

 

打开http://IP/cacti/install 进行cacti的安装


五、安装ntop

         #useradd -M -s /sbin/nologin -r ntop

         #tarzxvf ntop-5.0.1.tar.gz

         #cd  ntop-5.0.1

         #./autogen.sh

         #make

         #makeinstall

         #chown-R ntop.ntop /usr/local/share/ntop

         #chown-R ntop:root /usr/local/share/ntop

         #ntop -A

         #ntop -i eth0 -d -L -u ntop

         #echo 'ntop -i eth0 -d -L -u ntop &> /dev/null' >>/etc/rc.d/rc.local

         访问http://IP:3000


六、整合cacti和ntop

         #tar zxvf ntop-v0.2-1.tgz

         #mv ntop /usr/local/cacti/plugins/

         #vi/usr/local/cacti/include/config.php

         添加“$plugins[] = 'ntop';”


七、整合cacti和nagios

1. 安装ndoutils

         #tar zxf ndoutils-1.5.2.tar.gz

         #cd ndoutils-1.5.2

         #./configure --with-mysql-lib=/usr/lib64/mysql

    #make

         #cd /root/ndoutils-1.5.2/db

         #./installdb -ucactier -p 123#abc -h localhost -d cactidb

         #cd /root/ndoutils-1.5.2/src

         cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /var/www/html/nagios/bin

 

         #cp -v ndomod-3x.o /usr/local/nagios/bin/

         #mv/usr/local/nagios/bin/ndomod-3x.o /usr/local/nagios/bin/ndomod.o

 

         #cp -v ndo2db-3x /usr/local/nagios/bin/

         #mv/usr/local/nagios/bin/ndo2db-3x /usr/local/nagios/bin/ndo2db

 

         #cp -v file2sock /usr/local/nagios/bin/

         #cp -v log2ndo /usr/local/nagios/bin/

 

         #cd /root/ndoutils-1.5.2/config

         #cp -v ndo2db.cfg-sample /usr/local/nagios/etc/

         #mv/usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg

 

         #cp -v ndomod.cfg-sample /usr/local/nagios/etc/

         #mv/usr/local/nagios/etc/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg

         #chmod 644 /usr/local/nagios/etc/ndo*

        

         #chown nagios:nagios /usr/local/nagios/etc/*

         #chown nagios:nagios /usr/local/nagios/bin/*

 

#vi /usr/local/nagios/etc/nagios.cfg  

broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg   # 在文件中添加: 

event_broker_options=-1# 检查  

         

#vi/usr/local/nagios/etc/ndo2db.cfg

socket_type=tcp  

  db_servertype=mysql  

db_host=localhost  

db_port=3306  

db_name=cactidb  

db_prefix=npc_  

db_user=cactier 

db_pass=password 

 

#/usr/local/nagios/etc/ndomod.cfg

output_type=tcpsocket  

  output=127.0.0.1

 

        为ndo2db添加启动进程

#cp ./daemon-init /etc/init.d/ndo2db  

#vi /etc/init.d/ndo2db 

  # 检查里面的路径确保不会出现“//",并将Ndo2dbBin修改成下面的值:  

      Ndo2dbBin=/usr/local/nagios/bin/ndo2db

#chmod +x /etc/init.d/ndo2db

 

         #servicendo2db start

         #tail-20 /var/log/messages    ## 查看其中是否有错误出现。如无报错请继续

         #/usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg    检查nagios配置没有问题

#service nagios restart

 

2. 安装npc

         #tar zxf /root/npc-2.0.4.tar.gz

         #mv /root/npc/ /usr/local/cacti/plugins/

#vi /usr/local/cacti/include/config.php

         添加 $plugins[] = 'npc';

 

3. 为apche添加php支持

         #vi /etc/httpd/conf/httpd.conf

# 添加一行:  

                   AddType application/x-httpd-php .php .phtml  

         # 修改原DirectoryIndex内容为:  

                   DirectoryIndex index.html index.html.var index.php  

  

#usermod -G cactier apache  

#service httpd restart    ## 重启apache以让php生效  

#php -m   ## 查看是否有json被加载

 

 

4. 修改mysql中的表结构:

use cactidb;

alter table npc_eventhandlers addlong_output TEXT NOT NULL default '' after output;

alter table npc_eventhandlers add long_outputTEXT NOT NULL default '' after output;

alter table npc_hostchecks add long_outputTEXT NOT NULL default '' after output; 

alter table npc_hoststatus add long_outputTEXT NOT NULL default '' after output; 

alter table npc_notifications add long_outputTEXT NOT NULL default '' after output; 

alter table npc_servicechecks addlong_output TEXT NOT NULL default '' after output; 

alter table npc_servicestatus addlong_output TEXT NOT NULL default '' after output; 

alter table npc_statehistory add long_outputTEXT NOT NULL default '' after output; 

alter table npc_systemcommands addlong_output TEXT NOT NULL default '' after output;

 

#service ndo2db restart 

#service nagios restart



八、安装pnp4nagios

1. 安装pnp

#tar pnp4nagios-0.6.19.tar.gz

        #cdpnp4nagios-0.6.19

# ./configure --with-nagios-user=nagios--with-nagios-group=nagios

#make all

#make install

#make install-webconf

#make install-config

#make install-init

 

         部署配置文件

#chown –R nagios.nagios /usr/local/pnp4nagios

#su - nagios

$cd /usr/local/pnp4nagios/etc

$mv misccommands.cfg-sample misccommands.cfg

$mv nagios.cfg-sample  nagios.cfg

$mv process_perfdata.cfg-sample process_perfdata.cfg

$mv rra.cfg-sample rra.cfg

 

$cd /usr/local/pnp4nagios/etc/pages

$mv web_traffic.cfg-sample web_traffic.cfg

 

$cd /usr/local/pnp4nagios/etc/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

 

         设置npcd开机启动

         #chkconfig–add /etc/init.d/npcd

         启动npcd

#service npcd start

 

2. 修改nagios配置文件

         配置nagios.cfg,修改:

         #vi/usr/local/nagios/etc/nagios.cfg

process_performance_data=1

                 host_perfdata_command=process-host-perfdata

service_perfdata_command=process-service-perfdata

 

         配置commands.cfg,修改:

#vi /usr/local/nagios/etc/objects/etc/objects/commands.cfg

# '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

        }

 

         配置templates.cfg,添加:

         #vi/usr/local/nagios/etc/objects/etc/objects/templates.cfg

# Pnp4nagios host definition template

                define host {

                                name       host-pnp

                                action_url/pnp4nagios/graph?host=$HOSTNAME$

                                register   0

                  }

 

# Pnp4nagioshost definition template

define service {

                  name       srv-pnp

                  action_url/pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$

                  register   0

         }

 

         配置主机监控文件:

         #vi/usr/local/nagios/etc/objects/etc/objects/192.168.8.80-NSClient.cfg

                define service{

                                use                                          generic-service,srv-pnp

                                host_name                            192.168.8.80-NSClient

                                service_description            check_ping

                                check_command                 check_ping!100.0,20%!500.0,60%

                  }

 

3. 重启服务

#/usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg    检查nagios配置

#service nagios restart   没有错误重启nagios服务

        #service npcd restart      重启npcd服务




先简单记录一下,以后有时间再完善吧。

本文转载自:http://blog.csdn.net/deepnight2005/article/details/8364409

雁南飞丶
粉丝 37
博文 185
码字总数 246256
作品 0
西安
运维
私信 提问
Win7 安装Centos6.3

http://www.linuxidc.com/Linux/2012-10/71888.htm 一直按照上文进行win7硬盘安装centos6.3 不过我遇到了一个问题就是,在grub引导了centos6.3后,却启动不了centos的画面。是在不知道是什么...

huiyong-cheng
2012/12/12
975
8
Linux学习笔记:Xshell连接VMware网络连接问题

这几天学习linux,视频里老师推荐使用Centos6.3和Xshell,但是遇到了几个问题。 1、Centos6.3安装完后默认自动获取IP地址,每次虚拟机重启IP就变动。 2、修改完eth0的IP后,重启后依旧是一切...

countryman
2016/03/06
201
0
搭建Web服务器之Step4:安装VMWare-Tool实现共享文件夹

VMWare版本:7.1.4 主机系统:Win7旗舰 虚拟系统:CentOS6.3 1.启动CentOS,在VMWare下方提示安装VMWare-Tool,点击安装,稍待片刻,centos桌面弹出一个DVD的光盘,里面有 VMwareTools-8.8....

派卡琪安
2012/08/13
838
0
NFS服务的配置过程。

NFS(Network File System)即网络文件系统,是由Sun公司开发的一种通过网络方式共享系统的通用共享解决方案。目前NFS有3个版本,分别为NFSv2、NFSv3、NFSv4。NFSv2是一个古老的版本,但却被...

hu小贱
2014/11/06
0
0
搭建Web服务器之Step10:Win7开发CentOS6.3部署

测试说明:个人开发的一个网站,win7开发,开发完毕后,迁移部署至虚拟机上的CentOS6.3上进行测试 迁移步骤: 1.搭建好Web服务器 2.在CentOS下的MySQL执行Step9导出的.sql文件 3.在Win下将项...

派卡琪安
2012/10/05
588
0

没有更多内容

加载失败,请刷新页面

加载更多

rime设置为默认简体

转载 https://github.com/ModerRAS/ModerRAS.github.io/blob/master/_posts/2018-11-07-rime%E8%AE%BE%E7%BD%AE%E4%B8%BA%E9%BB%98%E8%AE%A4%E7%AE%80%E4%BD%93.md 写在开始 我的Arch Linux上......

zhenruyan
今天
5
0
简述TCP的流量控制与拥塞控制

1. TCP流量控制 流量控制就是让发送方的发送速率不要太快,要让接收方来的及接收。 原理是通过确认报文中窗口字段来控制发送方的发送速率,发送方的发送窗口大小不能超过接收方给出窗口大小。...

鏡花水月
今天
10
0
OSChina 周日乱弹 —— 别问,问就是没空

Osc乱弹歌单(2019)请戳(这里) 【今日歌曲】 @tom_tdhzz :#今日歌曲推荐# 分享容祖儿/彭羚的单曲《心淡》: 《心淡》- 容祖儿/彭羚 手机党少年们想听歌,请使劲儿戳(这里) @wqp0010 :周...

小小编辑
今天
1K
11
golang微服务框架go-micro 入门笔记2.1 micro工具之micro api

micro api micro 功能非常强大,本文将详细阐述micro api 命令行的功能 重要的事情说3次 本文全部代码https://idea.techidea8.com/open/idea.shtml?id=6 本文全部代码https://idea.techidea8....

非正式解决方案
今天
5
0
Spring Context 你真的懂了吗

今天介绍一下大家常见的一个单词 context 应该怎么去理解,正确的理解它有助于我们学习 spring 以及计算机系统中的其他知识。 1. context 是什么 我们经常在编程中见到 context 这个单词,当...

Java知其所以然
昨天
9
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部