【php精品源码栏目提醒】:网学会员--在 php精品源码编辑为广大网友搜集整理了:cacti+nagios安装全过程 - 其它资料绩等信息,祝愿广大网友取得需要的信息,参考学习。
Cactinagios 监控配置 bycolincolinzhouyjgmail.com操作系统 CentOS5.3 主程序包:cacti‐0.8.7enagios‐3.1.2 其他:SElinux 关闭一.搭建 LAMP 环境 1.为了方便,我这里配置了 yum 来安装 Apache,MySQL,
PHP gtyum install httpd ‐y //注意,这里安装 Apache 的时候也安装了 suexec,对后 面安装 nagios 会有影响,所以后面 nagios 要安装在/var/www/ 目录下。
gtyum install mysql ‐y // ‐y 这里就不用按 y 了,自动跳过去 gtyuminstallphp‐y 2.测试
PHP 是否安装正确,Apache 是否能正常显示。
gtcd/var/www/html gtvitest.
php ltphp Phpinfo gt 保存退出 gtservicehttpdstart //启动 Apache 服务 3.打开浏览器,输入地址 http://服务器 ip/test.
php 或者 http://127.0.0.1/test.
php能看到以下的图片说明
PHP 安装正确了。
//这里如果报错先执行 6. 4.测试 MySQL 是否安装正确。
gtServicemysqldstart //启动 MySQL 服务 gt/usr/bin/mysqladmin ‐urootpassword123456//为 MySQL 的 root 用户添加密码 gtmysql‐uroot‐p123456 //登陆 MySQL,能看到下图,说明正常 mysqlgtquit //退出 MySQL 5.设置 Apache,MySQL 开机启动 gtchkconfighttpdon gtchkconfigmysqldon 6.关闭 SElinux vi/etc/sysconfig/selinux SELINUXenforcing SELINUXdisabled //设置完需要重新启动也可以执行 setenforce0 ,先不重启二.安装 cacti 1.安装前的一些准备 more /var/log/messages //检查有无系统级错误信息,没有系统 error dmesg //检查硬件设备是否有错误信息,没看到 error ifconfig //检查网卡设置是否正确,有 ip 即可 ping www.163.com //检查网络是否正常能通即可,也可以是其他网站 ntsysv //关闭不需要的服务,lt空格gt选择,设置完成后重启系统 crontab –e 加入: 1 /6 ntpdate 210.72.145.44 gt /dev/null 2gtamp1 保存退出。
//定时校正服务器时钟 2.安装 net-snmp yum install net-snmp -y 3.安装
php-snmp //这个在前面 yum 装
php 的时候是装了的,最好检查一下 rpm –q
php-snmp 4.1 centos5 安装 rrdtool //很顺利,只要两个包,跳到 5 4.2 centos4 安装 rrdtool yum 没有 rrdtools 的话要自己去下载 http://dag.wieers.com/rpm/packages/rrdtool/找到适合自己系统的,我这里下载的 是 rrdtool-1.2.23-1.el4.rf.i386.rpm 和 perl-rrdtool-1.2.23-1.el4.rf.i386.rpm gt rpm -ivh rrdtool-1.2.23-1.el4.rf.i386.rpm perl-rrdtool-1.2.23-1.el4.rf.i386.rpm rrdtool-devel-1.2.23-1.el4.rf.i386.rpm //我在安装这几个包的时候搞了一个小时,前面一直报错 一看,貌似是缺了很多包,看看自己又没有,不能一个一个去下吧,网上仔细找找,发现只要下载一个包就 可以了,就是 rrdtool-devel-1.2.23-1.el4.rf.i386.rpm 这个包。
。
。
然后在网上下载到了这个包,又报错,郁闷。
。
看到这个报错,差点崩溃,网上找了好多都有这个情况 ,但是都没说怎 么解决,后来看到一个帖子,貌似是说包有问题,ok,换个地方重新 down 一个,看到这图真高兴…… 执行命令,rrdtool,查看输出,判断是否安装正确、5.开始安装 cacti gttar zvxf cacti-0.8.7e.tar.gz gtmv cacti-0.8.7e /var/www/html/cacti //将目录移动到网站根目录下6.创建数据库,并导入数据文件 gt cd /var/www/html/cacti/ gtmysql -uroot -p123456 //登陆数据库,用户名是 root,密码是 123456、 mysqlgt create database cacti //创建数据库,名字叫 cacti mysqlgt show databases //查看所有数据库,能看到有 cacti mysqlgt grant all on cacti. to cactilocalhost identified by cacti //添加用户命令,第一个 cacti.指哪个数据库,第二个是用户名,后面是登陆密码。
mysqlgt flush privileges //刷新授权表,使添加的用户生效。
mysqlgtquit gtmysql -ucacti -pcacti cacti lt /var/www/html/cacti/cacti.sql //导入数据库,分别是:用户名,密码,数据库名,导入的数据库文件 用以下方法查看是否导入成功。
gtmysql –ucacti –pcacti mysqlgt show databases mysqlgt use cacti mysqlgt show tables //能看到有输出就说明导入成功了。
7。
配置 cacti 编辑文件 include/config.
php 和 include/global.
php gtvi /var/www/html/cacti/include/config.
php //global.
php 修改相同内容 database_t ype quotmysqlquot //数据库类型 database_default quotcactiquot //默认数据库名 database_hostname quotlocalhostquot //主机名 database_username quotcactiquot //登陆数据库用户名 database_password quotcactiquot //登陆数据库密码 database_port quot3306quot //链接数据库端口 保存退出 添加系统用户 cacti gtuseradd –r –M cacti //-M 不创建家目录 –r uid 小于 500 内置用户 设定 log 及 rra 目录权限 gtchown –R cacti /var/www/html/cacti/rra/ gtchown –R cacti /var/www/html/cacti/log/ 增加定时执行脚本,以下脚本执行时不能用 root 用户 //获取数据 gtsu cacti gtcrontab –e /5
php /var/www/html/cacti/poller.
php gt /dev/null 2gtamp18.启动 cacti打开浏览器,输入 http://127.0.0.1/cactiNextgtgt选择 New Install Next gtgt我这里报了一个错,是 snmp 没找到,发现是路径出错了,locate 一下,找到了路径。
网上搜索还发现,有的是 net-snmp-util 包没有装找到之后修改路径就 ok 了,直接刷新 //注意上面 snmp 和 rrdtool 的版本选好自己装的那个。
//这里 net-snmp 是 5.x rrdtool 是 1.2.xFinish gtgtgtgt用户名 admin 密码 admin gtgtgtlogin 第一次登陆会强制要求 修改密码,这里自己修改就好了。
Savegtgtgtcacti 安装完成。
三.Nagios 的安装。
1.Nagios 主程序包的安装 gt tar zxf nagios-3.1.2.tar.gz gtcd nagios-3.1.2 gt./configure --prefix/var/www/html/nagios //我这里是安装在/var/www/html/目录下,前面已经提过了 gtmake all //说明一下下面的图: Make install //安装主程序,CGI 和 HTML 文件 Make install-init //安装 init.d 脚本在/etc/rc.d 目录下 Make install-commandmode //配置目录权限 Make install-config //安装一些控制文件 Make install-webconf //为安装 nagios 配置 Apachegtmake install //非法用户 nagios V Ok,先添加用户: gtuseradd nagios //这里要有家目录,没有的话后面启动会报错 gtmake install gtmake install-init gtmake install-commandmode gtmake install-config // 执行完以上的命令之后可以在/var/www/html/nagios 下看到 6 个目录 gtmake install-webconf //注意上面的命令执行完之后会生成/etc/httpd/conf.d/nagios.conf 文件文件中有 一个认证文件,稍后要创建。
2.增加认证文件 查看 cat /etc/httpd/conf.d/nagios.conf 文件中控制文件的路径。
创建该文件,并添加用户。
这里用户为 test,密码 123456。
gthtpasswd -c /var/www/html/nagios/etc/htpasswd.users test New password:123456 Re-type new password:123456 Adding password for user test gt cat /var/www/html/nagios/etc/htpasswd.users test:8DWKztzZg1ATA //前面是用户名,后面是加密的密码。
3.安装插件 //源代码安装,不截图了。
gttar -xf nagios-plugins-1.4.13.tar gtcd nagios-plugins-1.4.1 gt./configure --prefix/var/www/html/nagios/ gtmake gtmake install gtls /var/www/html/nagios/libexec/ //能看到有很多可执行脚本。
4.将运行 Apache 的用户添加到 nagios 组里,这样 Apache 才有权限读取文件 gtgrep User /etc/httpd/conf/httpd.conf User apache //我这里是 apache 用户 gtusermod –G nagios apache //将 apache 用户加到 nagios 组。
5.阶段测试 到这里 nagios 的安装基本上完成了,先重启 Apache 服务,输入地址访问: gtservice httpd restart 浏览网址 : http://127.0.0.1/nagios/ 用户名:test,密码 123456,确定gtgt Ok,这里只能看到这个页面,其他的都点不开,打开都是报错。
。
whoops! 。
!6.配置 nagios典型配置、//一下内容可以直接粘贴—gt复制。
。
_ 以下有些文件是不存在的,vi 创建。
a定义监控时间段 gtvi /var/www/html/nagios/etc/objects/timeperiods.cfg 在后面加: define timeperiod timeperiod_name all_days alias 24 Hours A Day 7 Days A Week sunday 00:00-24:00 monday 00:00-24:00 tuesday 00:00-24:00 wednesday 00:00-24:00 thursday 00:00-24:00 friday 00:00-24:00 saturday 00:00-24:00 b定义联系人。
gtvi /var/www/html/nagios/etc/objects/contacts.cfg 在后面加上 define contact contact_name zhouyj alias zhouyanjun service_notification_period all_days host_notification_period all_days service_notification_options wucr host_notification_options dur service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email email colinzhouyjgmail.com c定义联系人组 gt vi /var/www/html/nagios/etc/objects/contactgroup.cfg define contactgroup contactgroup_name sagroup alias test group members zhouyj d定义被监控主机 gt vi /var/www/html/nagios/etc/objects/hosts.cfg define host host_name server117 alias server117 address 192.168.1.117 check_command check-host-alive max_check_attempts 5 check_period all_days contact_groups sagroup notification_interval 10 notification_period all_days notification_options dur e定义监控的服务 gt vi /var/www/html/nagios/etc/objects/services.cfg define service host_name server117 service_description check_ssh check_command check_ssh max_check_attempts 5 normal_check_interval 3 retry_check_interval 2 check_period all_days notification_interval 5 notification_period all_days notification_options wucr contact_groups sagroup f编辑主配置文件 gtvi /var/www/html/nagios/etc/nagios.cfg cfg_file/var/www/html/nagios/etc/objects/commands.cfg cfg_file/var/www/html/nagios/etc/objects/contacts.cfg cfg_file/var/www/html/nagios/etc/objects/timeperiods.cfg cfg_file/var/www/html/nagios/etc/objects/templates.cfg cfg_file/var/www/html/nagios/etc/objects/contactgroup.cfg cfg_file/var/www/html/nagios/etc/objects/hosts.cfg cfg_file/var/www/html/nagios/etc/objects/services.cfgg编辑 cgi.cfg 要修改的配置文件是 cgi.cfg它的作用是控制相关 cgi 脚本。
确定 use_authentication1 default_user_nametest 其他的 authorized_for_system_informationtest authorized_for_configuration_information test authorized_for_system_commandstest //多个用户之间用逗号隔开 authorized_for_all_services test authorized_for_all_hosts test authorized_for_all_service_commands test authorized_for_all_host_commands test可以看到基本上所有的成员都是已经定义的,这样整个的配置过程就结束了.虽然功能很简单但是已经为以后扩展打下了良好的基础,以后的工作基本都是复制粘贴啦 7.运行 nagios a)测试配置gt /var/www/html/nagios/bin/nagios -v /var/www/html/nagios/etc/nagios.cfg b以 deamon(后台进程)方式启动 nagiosgt /var/www/html/nagios/bin/nagios -d /var/www/html/nagios/etc/nagios.cfg //以后也可以用 service nagios Start/stop/restart 等命令启动了 8.测试 输入网址 http://192.168.1.117/nagios/ 发现其他的能打开了。
//其中 PENDING 状态是延迟,耐心等就好了。
至此,nagios 和 cacti 的基本配置完成,要实现其他功能需要安装其他插件。
四.整合 nagios 和 cacti (把 Nagios 的数据写到 mysql 里的插件,集成的关键) 1.安装 NDoutils。
gttar zxf ndoutils-1.4b7.tar.gz gtcd ndoutils-1.4b7 gt./configure --prefix/var/www/html/nagios --enable-mysql --disable-pgsql LDFLAGS-L/usr/lib/mysql //声明未定义的库 --with-mysql-inc/usr/include/mysql //mysql 头文件目录.h 结尾 --with-mysql-lib/usr/lib/mysql //mysql 库文件目录.so 结尾 // ./configure –help 查看帮助 gtmake gtll src/ //看是否有 ndo2db‐2xndo2db‐3xndomod‐2x.ondomod‐3x.o 这四个文件 gtcdsrc cpndomod‐3x.ondo2db‐3xlog2ndofile2sock/var/www/html/nagios/bin/ //我的 Nagios 是 3.0.6,所以拷贝的是 ndomod-3x.o、ndo2db-3x,如果你 的是 2.X.x 请拷贝 ndomod-2x.o、ndo2db-2x chown nagios.nagios /var/www/html/nagios/bin/ gtcd ../config gtcp ndo /var/www/html/nagios/etc/ gtchown nagios.nagios /var/www/html/nagios/etc/ 修改配置文件 gtvi /var/www/html/nagios/etc/ndo2db.cfg socket_name/var/www/html/nagios/var/ndo.sock //因为 nagios 装在 html 目录下,所以这里要修改,要不没有权限 db_namecacti //数据库名,跟前面 cacti 公用一个库 db_usercacti db_passcacti gtcd ../db/ gt ./installdb -ucacti -pcacti -hlocalhost -d cacti //导入数据库结构,可以登录数据库查看多了很多 nagios 开头的表 //如果先装了 npc 插件,这一步可以省略 gtvi /var/www/html/nagios/etc/nagios.cfg 确定:event_broker_options-1 添加:broker_module/var/www/html/nagios/bin/ndomod-3x.o config_file/var/www/html/nagios/etc/ndomod.cfg //这两个是一行内容,可以在源代码目录下的 config/nagios.cfg 中找到 gt/var/www/html/nagios/bin/ndo2db-3x -c/var/www/html/nagios/etc/ndo2db.cfg //启动 ndo2db echo “/var/www/html/nagios/bin/ndo2db-3x -c/var/www/html/nagios/etc/ndo2db.cfg” gtgt /etc/rc.local //开机启动 重启 nagios 2.检查安装是否正确 gttail -20 /var/www/html/nagios/var/nagios.log //似乎有问题,跟参考资料上一样的,哎。
A) 检查 ndomod.cfg 文件,发现 output 的 ndo.sock 文件路径不对,前面改过 ndo2db.cfg 文件,把这里也改成和前面一样路径就 ok 了。
gtvi /var/www/html/nagios/etc/ndomod.cfg output/var/www/html/nagios/var/ndo.sock B)到这里能看到数据库里有数据,但是仍然能看到错误。
//图片可放大 // ndo2db-3x: Error: mysql_query failed for INSERT INTOnagios_configfilevariables SET instance_id1 configfile_id1varnamecfg_file varvalue/var/www/html/nagios/etc/objects/contacts.cfg //这里是一个 bug,因为插件设计的时候没有设计好数据库,在 varname 列上建了索引,使得该列拥有了 unique 属性,而 nagios 的 cfg_file 在配置文件里是有多项的。
这里将该索引删除,新建了一个索引。
alter table nagios_configfilevariables drop index instance_id alter table nagios_configfilevariables add index instance_idconfigfile_id varname //重启 nagios 服务,ndo2db 成功完成安装。
3.安装 npc 插件 A)安装 npc 插件之前要安装 Cacti Plugins(插件框架) gtunzip cacti-plugin-0.8.7e-PA-v2.5.zip //.
上一篇:
平顶山学院教案
下一篇:
法律专业开题报告范文