Cacti 多用于图形监测系统性能 负载等
Cacti: 是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具.
注意如下几点 4.本文不过多的介绍配置文件和软件使用方法 只标注管简单 多去学习才能更好的掌握各种知识
本文以 Centos 5.4 作为平台来搭建 Lnmp 安装方法: http://www.sa-log.com/195.html 让nginx支持cgi 的方法 http://www.sa-log.com/222.html ############################################################################## 注意,此处只标记. 不要使用该部分命令. 是为了整理看着清爽.具体安装步骤,着重参考安装正文 Cacti版本:cacti-0.8.8a.tar.gz
Nagios版本:nagios-3.4.1.tar.gz
需要安装的软件包
yum install -y gd gd-devel xinetd libart_lgpl
Cacti:
yum -y install libart_lgpl-devel libpng-devel freetype-devel libart_lgpl-devel fonts-chinese cairo-devel pango-devel
先来几张图,把关键位置标注出来. 从正文开始 大篇幅安装步骤 不单独出图 下面的几个图 只是关键点
New Graphs:新建图形
几个设置的时候要注意的地方
cacti 优化参考 所有参数 不可全抄 要根据实际情况修改
##################################################
yum install -y gd gd-devel xinetd libart_lgpl
# 建立nagios用户 用于维护nagios
/usr/sbin/useradd nagios
#passwd nagios # 建立nagioscmd组 用于执行cgi程序 和其他nagios程序
/usr/sbin/groupadd nagcmd
# 将nagios用户加到nagcmd组
/usr/sbin/usermod -a -G nagcmd nagios
# 将web用户加到nagcmd组
/usr/sbin/usermod -a -G nagcmd web
# 将www用户加到nagcmd组
/usr/sbin/usermod -a -G nagcmd www
# 将nagios用户加到www组
/usr/sbin/usermod -a -G www nagios
# 下载需要的软件包
# 官方下载页面 软件 和 插件 # 下载软件和插件包
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz # 解压
tar zxf nagios-3.4.1.tar.gz
tar zxf nagios-plugins-1.4.16.tar.gz # 开始进行便已安装
cd nagios
./configure --prefix=/soft/nagios-3.4.1 --with-command-group=nagcmd make all && make install && make install-init && make install-config && make install-commandmode cd ../ /usr/bin/install -c -m 775 -o nagios -g nagcmd -d /soft/nagios-3.4.1/var/rw chmod g+s /soft/nagios-3.4.1/var/rw cd nagios-plugins-1.4.16 ./configure --prefix=/soft/nagios-3.4.1 --with-nagios-user=nagios --with-nagios-group=nagios make && make install cd ../
###########
yum install -y perl-devel.x86_64
# nagios 是由perl编写的.所以 需要如下perl模块
#perl -MCPAN -e shell
cpan> install Net::SNMP
###########
wget http://search.cpan.org/CPAN/authors/id/D/DP/DPARIS/Crypt-DES-2.05.tar.gz
wget http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/Digest-MD5-2.52.tar.gz wget http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/Digest-SHA1-2.13.tar.gz wget http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/Digest-HMAC-1.03.tar.gz wget http://search.cpan.org/CPAN/authors/id/D/DT/DTOWN/Net-SNMP-v6.0.1.tar.gz tar zxf Crypt-DES-2.05.tar.gz tar zxf Digest-MD5-2.52.tar.gz tar zxf Digest-SHA1-2.13.tar.gz tar zxf Digest-HMAC-1.03.tar.gz tar zxf Net-SNMP-v6.0.1.tar.gz cd Crypt-DES-2.05 perl Makefile.PL make install cd ../ cd Digest-MD5-2.52 perl Makefile.PL make install cd ../ cd Digest-SHA1-2.13 perl Makefile.PL make install cd ../ cd Digest-HMAC-1.03 perl Makefile.PL make install cd ../ cd Net-SNMP-v6.0.1 perl Makefile.PL make install cd ../
# 插件位置 ————————————–
vi /soft/nagios-3.4.1/etc/cgi.cfg
#找到这几行,后面添加 erbin用户,可以自己定义用户,使用“,”隔开
#authorized_for_system_information=nagiosadmin,test
#authorized_for_configuration_information=nagiosadmin,test #authorized_for_system_commands=nagiosadmin,test #authorized_for_all_services=nagiosadmin,test #authorized_for_all_hosts=nagiosadmin,test #authorized_for_all_service_commands=nagiosadmin,test #authorized_for_all_host_commands=nagiosadmin,test use_authentication=0
vi /soft/nagios-3.4.1/etc/objects/contacts.cfg
vi /soft/nagios-3.4.1/etc/cgi.cfg
url_html_path=/nagios
vi /soft/nagios-3.4.1/etc/nagios.cfg
cfg_dir=/soft/nagios-3.4.1/etc/servers cfg_file=/soft/nagios-3.4.1/etc/objects/hostgroups.cfg
mkdir -p /soft/nagios-3.4.1/etc/servers
cd /soft/nagios-3.4.1/etc/servers
vi /soft/nagios-3.4.1/etc/objects/hostgroups.cfg
define hostgroup { hostgroup_name sa-servers aliassa servers members localhost,192.168.2.215 #用逗号间隔多个主机 } 修改nagiosadmin 这行其中的邮件地址为你的email 地址,以将报警邮件发到你的邮箱 设置登陆web 界面时HTTP 验证的账号密码 http://www.4webhelp.net/us/password.php test:44ofpQvlFOgvs
vi /soft/nagios-3.4.1/etc/nagiospasswd
————————————— # 检测配置文件是否有错
/soft/nagios-3.4.1/bin/nagios -v /soft/nagios-3.4.1/etc/nagios.cfg
# 开启 nagios
/soft/nagios-3.4.1/bin/nagios -d /soft/nagios-3.4.1/etc/nagios.cfg
mkdir -p /wwwroot/web/
cp -r /soft/nagios-3.4.1/share/ /wwwroot/web/nagios
########## nginx 配置文件关键部位代码
server_name 192.168.2.215;
index index.html index.htm index.php; root /wwwroot/web; auth_basic "Nagios Access"; auth_basic_user_file /soft/nagios-3.2.1/etc/nagiospasswd; location ~ .*\.(cgi|pl|perl)?$ { gzip off; root /soft/nagios-3.2.1/sbin; rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break; fastcgi_pass 127.0.0.1:8999; fastcgi_param SCRIPT_FILENAME /soft/nagios-3.2.1/sbin$fastcgi_script_name; fastcgi_index index.cgi; fastcgi_read_timeout 60; fastcgi_param REMOTE_USER$remote_user; include fcgi.conf; auth_basic "Nagios Access"; auth_basic_user_file /soft/nagios-3.2.1/etc/nagiospasswd; } ########################### 开始安装cacti
yum -y install libart_lgpl-devel libpng-devel freetype-devel libart_lgpl-devel fonts-chinese cairo-devel pango-devel
wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.3.tar.gz tar zxf rrdtool-1.4.3.tar.gz cd rrdtool-1.4.3 # 让rrdtool 支持中文
sed -i 's/setlocale(LC_NUMERIC, "C")/setlocale(LC_ALL, "zh_CN.UTF-8")/g' src/rrd_graph.c
sed -i 's/setlocale(LC_NUMERIC, old_locale)/setlocale(LC_ALL, old_locale)/g' src/rrd_graph.c
./configure --prefix=/soft/rrdtool-1.4.3
make && make install cd ../ # 将 /soft/rrdtool-1.4.3/lib 加入到 /etc/ld.so.conf
ldconfig
wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz
tar zxf cacti-0.8.8a.tar.gz cp -r cacti-0.8.8a /wwwroot/web/cacti cd /wwwroot/web/cacti mysql -uroot -p mysql>drop database cacti; mysql>create database cacti; mysql>use cacti; mysql>source cacti.sql; mysql>grant all privileges on cacti.* to cacti@localhost identified by "cacti"; mysql>grant all privileges on cacti.* to cactiuser@localhost identified by "cactiuser"; mysql>flush privileges; mysql>exit # 修改数据库信息
vi include/config.php
# 修改php配置文件,修改时区
vi /soft/php-5.4.6/etc/php.ini
safe_mode = Off date.timezone = "PRC" # 保存退出 并重启
wget http://sourceforge.net/projects/net-snmp/files/net-snmp/5.6.1.1/net-snmp-5.6.1.1.tar.gz/download
tar zxf net-snmp-5.6.1.1.tar.gz cd net-snmp-5.6.1.1 # 编译第一步 版本是2 ./configure --prefix=/soft/net-snmp-5.6.1.1 --enable-developer make && make install echo /soft/net-snmp-5.6.1.1/lib > /etc/ld.so.conf ldconfig cd ../
crontab -e
# 没分钟采集一次数据 使用root采集. 一个比较操蛋的问题. 就是东西太多 多环境生成会出问题 权限设置又很麻烦 不如这么来最实惠了. # 使用二进制文件来进行数据采集 效率较高
wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8a.tar.gz
tar zxf cacti-spine-0.8.8a.tar.gz cd cacti-spine-0.8.8a ./configure --prefix=/soft/cacti-spine-0.8.8a --with-mysql=/soft/mysql-5.5.27/ --with-snmp=/soft/net-snmp-5.6.1.1/ make && make install cd /soft/cacti-spine-0.8.8a/etc/ mv spine.conf.dist spine.conf vi /soft/cacti-spine-0.8.8a/etc/spine.conf # 安装完成 之后 http://ip/cacti/install
/soft/rrdtool-1.4.3/bin/rrdtool 用户名 密码 均为admin # 如果绘图出现乱码 上传一个中文字体即可
cp simsun.ttc /usr/share/fonts
fc-cache -f -v # 整合cacit和nagios
wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.5.2/ndoutils-1.5.2.tar.gz/download
tar zxf ndoutils-1.5.2.tar.gz cd ndoutils-1.5.2 ldconfig ./configure --prefix=/soft/ndoutils-1.5.2 --with-mysql=/soft/mysql-5.5.27/ --with-ndo2db-user=nagios --with-ndo2db-group=nagios # include/config.h 修改261 262行 #include </soft/mysql-5.5.27/include/mysql.h> #include </soft/mysql-5.5.27/include/errmsg.h> make make install
需要安装dbi 和 dbd
wget http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/Test-Simple-0.98.tar.gz
wget http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.622.tar.gz wget http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.022.tar.gz tar zxf Test-Simple-0.98.tar.gz tar zxf DBI-1.622.tar.gz tar zxf DBD-mysql-4.022.tar.gz cd Test-Simple-0.98 perl Makefile.PL make make install cd ../ cd DBI-1.622 perl Makefile.PL make make install cd ../ cd DBD-mysql-4.022 perl Makefile.PL make make install cd ../ cd db ./installdb -ucactiuser -pcactiuser -hlocalhost -d cacti [cce_bash] [cce_bash] cp ../config/ndomod.cfg-sample /soft/nagios-3.4.1/etc/ndomod.cfg vi /soft/nagios-3.4.1/etc/nagios.cfg check_external_commands=1 command_check_interval=-1 event_broker_options=-1 broker_module=/soft/nagios-3.4.1/bin/ndomod-3x.o config_file=/soft/nagios-3.4.1/etc/ndomod.cfg process_performance_data=1
cd /root/ndoutils-1.5.2/src
cp ndomod-3x.o ndo2db-3x log2ndo file2sock /soft/nagios-3.4.1/bin/ cd ../config cp ndo2db.cfg-sample /soft/nagios-3.4.1/etc/ndo2db.cfg /soft/ndoutils-1.5.2/bin/ndo2db -c /soft/nagios-3.4.1/etc/ndo2db.cfg mkdir -p /soft/ndoutils-1.5.2/var/
# selinux
chcon -R -t httpd_sys_content_t /soft/nagios-3.4.1/sbin/
chcon -R -t httpd_sys_content_t /soft/nagios-3.4.1/share/ # 安装npc 让nagios在cacti显示
tar zxf npc-2.0.4.tar.gz
cp -r npc /wwwroot/web/cacti/plugins/ chown www:www -R /wwwroot/web/ # 解决npc不出图的问题 进mysql cacti 数据库进行刷库
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; # 进入到软件目录
chown nagios:nagios -R nagios-3.4.1/ ndoutils-1.5.2/
# 进入web进行插件设置 ndo2db 内核错误解释
# cat /proc/sys/kernel/msgmnb
65536 # cat /proc/sys/kernel/msgmax 65536 # cat /proc/sys/kernel/msgmni 1985
# echo 131072 > /proc/sys/kernel/msgmnb
and # vi /etc/sysctl.conf and adjust the appropriate value(s). Why did I do it:
Because of repeating error messages in /var/log/messages: Read the NDO-Utils README file:
************************
NDOUTILS uses a single message queue to communicate between the broker
There are three Linux kernel parameters that determine the resources
To see the current values for any of these parameters, cat
In order for NDOUTILS to work at all, kernel.msgmax must be greater than
If there are insufficient resources for sending messages between the
ndo2db: Warning: Retrying message send. This can occur because
If you see this entry, the message will likely eventually be sent,
If you are close to or have exceeded the number of messages, you may
A conservative approach would be to double the necessary value, stop
To increase a value, echo the value to /proc/sys/kernel/msgmni or
For example, to increase the number of messages allowed in the queue
Once you have determine the correct parameters, you can make them (责任编辑:IT) |