nagios+cacti整合的安装文档
安装环境LAMP
1.1 yum安装httpd、mysqld、php及依赖包
-
yum -y install gcc* glibc* gd* php* mysql* http*
-
yum -y install httpd mysql-server perl-DBI perl-DBD-MySQL php php-devel php-mysql php-snmp php-pdophp-gd lm_sensors net-snmp net-snmp-libs net-snmp-utils net-snmp-devel
-
chkconfig mysqld on
-
chkconfig httpd on
-
chkconfig snmpd on
-
service mysqld start
-
service httpd start
-
service snmpd start
1.2测试mysql、php、Apache是否安装成功
编写php的测试页面
-
vim /var/www/html/index.php
-
<?php
-
phpinfo();
-
?>
访问
1.3创建cacti的数据库及cacti用户并赋予cacti用户权限
-
mysqladmin -u root password '123'
-
[root@localhost yum.repos.d]# mysql -u root -p
-
Enter password:
-
Welcome to the MySQL monitor. Commands end with ; or \g.
-
Your MySQL connection id is 4
-
Server version: 5.1.73 Source distribution
-
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
-
Oracle is a registered trademark of Oracle Corporation and/or its
-
affiliates. Other names may be trademarks of their respective
-
owners.
-
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
-
mysql>Create database cacti default character set utf8;
-
Query OK, 1 row affected (0.00 sec)
-
mysql>Grant all on cacti.* to cacti@localhost identified by '123';
-
Query OK, 0 rows affected (0.03 sec)
-
mysql>Flush privileges;
-
Query OK, 0 rows affected (0.00 sec)
-
mysql> quit
-
Bye
安装cacti
2.1安装rrdtool需要的软件包
-
yum -y install cairo-devel libxml2-devel pango pango-devel
2.2安装rrdtool
-
tar zxvf rrdtool-1.4.4.tar.gz
-
cd rrdtool-1.4.4
-
./configure --prefix=/usr/local/rrdtool
-
make
-
make install
-
ln -s /usr/local/rrdtool/bin/* /usr/local/bin/ #此步非常重要
2.3安装cacti-0.8.7.e中文版
-
wget http://blogimg.chinaunix.net/blog/upfile2/090815172648.gz
-
tar xvf090815172648.gz -C /var/www/html
-
cd /var/www/html
-
mv cacti-0.8.7e-cn-utf8/ cacti
-
mysql -u cacti -p cacti < cacti/cacti.sql / 导入数据库
-
Enter password:
2.4创建cacti用户
-
useradd cacti
-
chown -R cacti:cacti /var/www/html/cacti/
-
chmod -R 777 /var/www/html/cacti/
2.5修改cacti配置文件连接数据库
-
vim /var/www/html/cacti/include/config.php
-
$database_username = "cacti";
-
$database_password = "123"
2.6添加crontab每五分钟刷新一次
-
crontab –e
-
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php >/dev/null2>&1
-
service crond restart
浏览器初始化cacti
3.1浏览器输入初始化cacti
如果打开网页页面出现空白那么说明数据库没有导入进去重新导入数据库后重启httpd服务即可
注意:RRDTOOLS版本默认为1.0.x改为1.3.x就行了
3.2如果打开未看到生成图像请手动执行下面命令
-
/usr/bin/php/var/www/cacti/poller.php &>/dev/null手动生成图像
3.3字体在图形中显示不正常的解决方法
下载并安装中文字体这个是微米黑字体
-
wgethttp://sourceforge.net/projects/wqy/files/wqy-microhei/0.2.0-beta/wqy-microhei-0.2.0-beta.tar.gz
-
tar zxvf wqy-microhei-0.2.0-beta.tar.gz
-
cd wqy-microhei
-
cp wqy-microhei.ttc /usr/share/fonts/wqy-microhei.ttc
安装完成后注意在"设置"中更改下面两个必改项.
常规->RRDTool应用程序版本改为1.3.x,默认为1.0.x.不改可能图像不能正常显示出来.
路径->RRDTool默认字体路径改为上面安装的文件路径如/usr/share/fonts/wqy-microhei.ttc
安装cacti的插件
4.1安装插件cacti-plugin
-
gunzip 51CTO下载-cacti-plugin-0.8.7d-PA-v2.4-cn-utf8.diff.gz
-
mv 51CTO下载-cacti-plugin-0.8.7d-PA-v2.4-cn-utf8.diff /var/www/html/cacti/
-
cd /var/www/html/cacti/
-
mv 51CTO下载-cacti-plugin-0.8.7d-PA-v2.4-cn-utf8.diff cacti-plugin-0.8.7d-PA-v2.4-cn-utf8.diff
-
patch -p1 -N < cacti-plugin-0.8.7d-PA-v2.4-cn-utf8.diff
-
mysql -ucacti -p123 cacti <pa.sql
4.2页面设置插件
控制面板—用户管理—admin
插件管理打钩—保存
看到控制面板—配置多个了插件管理
4.3安装Settings插件
-
[root@nagios ~]# cd /usr/local/src/
-
[root@nagios nagios]# wget http://docs.cacti.net/_media/plugin:settings-v0.7-1.tgz
-
[root@nagios nagios]# mv plugin:settings-v0.7-1.tgz settings-v0.7-1.tgz
-
[root@nagios nagios]# tar zxvf settings-v0.7-1.tgz -C /var/www/html/cacti/plugins/
4.4安装Monitor插件
设备在线状态监控插件,在cacti页面host中设置了的主机会在monitor页面显示在线状态,可以和thold插件配置报警.
-
[root@nagios nagios]# wget http://docs.cacti.net/_media/plugin:monitor-v1.3-1.tgz
-
[root@nagios nagios]# mv plugin\:monitor-v1.3-1.tgz monitor-v1.3-1.tgz
-
[root@nagios nagios]# tar zxvf monitor-v1.3-1.tgz -C /var/www/html/cacti/plugins/
在页面上点击插件中安装和启用来启用插件
4.5 cacti插件的设置
直接在页面点击安装和启用后没有出现插件,可以在confi.php配置文件中设置
-
[root@nagios nagios]# vi /var/www/html/cacti/include/config.php
-
$plugins[] = 'npc';
-
$plugins[] = 'monitor'
安装nagios
5.1建nagios用户
-
useradd nagios
-
mkdir -p /usr/local/nagios
-
chown -R nagios.nagios /usr/local/nagios/
-
chmod -R 755 /usr/local/nagios/
5.2编译安装nagios
-
tar xvf nagios-3.2.0.tar.gz
-
cd nagios-3.2.0
-
./configure --prefix=/usr/local/nagios/
-
make all
-
make install
-
make install-init
-
make install-commandmode
-
make install-config
-
make install-webconf
-
chkconfig --add nagios
-
chkconfig nagios on
-
service nagios start
5.3安装nagios插件
-
tar xvf nagios-plugins-1.4.14.tar.gz
-
cd nagios-plugins-1.4.14
-
./configure --prefix=/usr/local/nagios/ && make&& make install
5.4安装nagios的汉化包
-
tar xvf nagios-cn-3.2.0.tar.bz2
-
cd nagios-cn-3.2.0
-
./configure ;
-
make all ;
-
make install
5.5安装sendmail
-
yum install sendmail
-
service sendmail start
5.6建立登陆的用户名密码
-
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin首次创建用-c
5.7修改nagios.cfg文件添加文件路径信息
-
vim /usr/local/nagios/etc/objects/nagios.cfg //nagios主配置文件
-
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg //主机配置文件
-
cfg_file=/usr/local/nagios/etc/objects/services.cfg //服务配置文件
-
cfg_file=/usr/local/nagios/etc/objects/commands.cfg //命令配置文件
-
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg //联系人配置文件
-
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg //时间配置文件
-
cfg_file=/usr/local/nagios/etc/objects/templates.cfg //模板文件
5.8修改contacts.cfg文件,修改邮件地址信息
-
vim /usr/local/nagios/etc/objects/contacts.cfg
-
email root@localhost
5.9检查nagios的配置文件并重新启动
-
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
-
重新启动nagios
-
service nagios restart
整合cacti+nagios
整合cacti和nagios是利用了cacti的一个插件nagiosfor cacti它的原理是将nagios的数据通过ndo2db导入到mysql数据库cacti的库中然后cacti读取数据库信息将nagios
的结果展示出来。
6.1安装php-json扩展
因为NPC使用了ExtJS如过没有json的扩展NPC界面无法出来,如果已安装请略过此步。
查看页面是否有php-json,如果没有按照下面的方法安装即可:
-
tar xf php-json-ext-1.2.1.tar.gz
-
cd php-json-ext-1.2.1
-
phpize
6.2安装ndoutils插件
需要安装mysql-devel的依赖包前面已经装过这里就不用再装了
-
wget http://nchc.dl.sourceforge.net/project/nagios/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz
-
tar xvf ndoutils-1.4b9.tar.gz
-
cd ndoutils-1.4b9
-
./configure --prefix=/usr/local/nagios/ --with-mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios --with-ssl --with-ssl-lib --enable-mysql --enable-ssl --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib64/mysql --disable-pgsql
-
make(不用make install)
6.3复制文件
-
cp src/{ndomod-3x.o,ndo2db-3x,log2ndo,file2sock}/usr/local/nagios/bin/
-
cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
-
cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
-
chmod 644 /usr/local/nagios/etc/ndo*
6.4修改配置文件信息,连接数据库
注意:修改之前先做好备份
-
vim /usr/local/nagios/etc/ndo2db.cfg //红色数字为行号
-
21 ndo2db_user=nagios
-
22 ndo2db_group=nagios
-
34 socket_type=tcp //将此行#号去掉,socket_type=unix前面加上#号
-
102 db_name=cacti //创建的数据库的名字
-
111 db_prefix=npc_
-
120 db_user=cacti //cacti数据库登陆用户名
-
121 db_pass=123 //cacti数据库登陆密码
-
vim /usr/local/nagios/etc/ndomod.cfg
-
25 output_type=tcpsocket //将此行#号去掉,output_type=unixsocket前面加上#号
-
39 output=127.0.0.1 //将此行#去掉,output=/usr/local/nagios//var/ndo.sock前面加上#号
6.4启动ndo2db
-
/usr/local/nagios/bin/ndo2db-3x -c/usr/local/nagios/etc/ndo2db.cfg
-
ps –elf |grep ndo2db
6.5安装npc插件
-
wget http://www.constructaegis.com/downloads/npc-2.0.4.tar.gz
-
tar xvf npc-2.0.4.tar.gz -C /var/www/html/cacti/plugins
-
chown -R apache.apache /var/www/html/cacti/plugins/npc/
6.6修改nagios配置文件添加如下信息:
-
vim /usr/local/nagios/etc/nagios.cfg //在最后添加如下行
-
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
-
注意:broker_module和config_file是一行的
6.7修改数据库的个别字段
-
mysql -ucacti -p123
-
mysql>use cacti;
-
Reading table information for completion of table and column names
-
You can turn off this feature to get a quicker startup with -A
-
-
Database changed
-
mysql>ALTER TABLE npc_eventhandlers ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
-
Query OK, 0 rows affected, 1 warning (0.02 sec)
-
Records: 0 Duplicates: 0 Warnings: 0
-
-
mysql>ALTER TABLE npc_hostchecks ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
-
Query OK, 0 rows affected, 1 warning (0.02 sec)
-
Records: 0 Duplicates: 0 Warnings: 0
-
-
mysql>ALTER TABLE npc_hoststatus ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
-
Query OK, 0 rows affected, 1 warning (0.03 sec)
-
Records: 0 Duplicates: 0 Warnings: 0
-
-
mysql>ALTER TABLE npc_notifications ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
-
Query OK, 0 rows affected, 1 warning (0.03 sec)
-
Records: 0 Duplicates: 0 Warnings: 0
-
-
mysql>ALTER TABLE npc_servicechecks ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
-
Query OK, 0 rows affected, 1 warning (0.02 sec)
-
Records: 0 Duplicates: 0 Warnings: 0
-
-
mysql>ALTER TABLE npc_servicestatus ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
-
Query OK, 0 rows affected, 1 warning (0.02 sec)
-
Records: 0 Duplicates: 0 Warnings: 0
-
-
mysql>ALTER TABLE npc_statehistory ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
-
Query OK, 0 rows affected, 1 warning (0.03 sec)
-
Records: 0 Duplicates: 0 Warnings: 0
-
-
mysql>ALTER TABLE npc_systemcommands ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
-
Query OK, 0 rows affected, 1 warning (0.03 sec)
-
Records: 0 Duplicates: 0 Warnings: 0
-
-
mysql>ALTER TABLE npc_services ADD importance smallint(6) NOT NULL DEFAULT '0';
-
Query OK, 8 rows affected (0.04 sec)
-
Records: 8 Duplicates: 0 Warnings: 0
-
-
mysql>ALTER TABLE npc_hosts ADD importance smallint(6) NOT NULL DEFAULT '0';
-
Query OK, 1 row affected (0.02 sec)
-
Records: 1 Duplicates: 0 Warnings: 0
-
-
mysql>ALTER TABLE npc_contacts ADD minimum_importance smallint(6) NOT NULL DEFAULT '0';
-
Query OK, 1 row affected (0.02 sec)
-
Records: 1 Duplicates: 0 Warnings: 0
-
-
mysql> quit
-
Bye
6.8重启服务
-
service mysqld restart
-
service httpd restart
-
service nagios restart
-
ps -ef |grep ndo2db
-
kill -9 ndo2db的进程号
-
启动ndo2db
-
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
3.4.7 Cacti添加被监控主机
7.1监控端的设置
Cacti中添加监控主机设置方法:
① 添加设备
报错:SNMP错误
解决办法:是因为被监控端没有启动snmp
service snmpd restart
然后到监控端cacti服务器上
snmpwalk -c public -v 2c 192.168.1.222 --> (这个ip为被监控主机的ip)
如果能够接收到被监控机器的数据信息,则表示被监控主机的snmp配置已经完成,没有错误。如果没有接收到被监控主机的数据信息,那么进行第三步操作。
第三,用root登录被监控主机,修改snmp的配置文件:
-
vi /etc/snmp/snmpd.conf
-
最后配置如下:
-
syslocation Server Room
-
syscontact Sysadmin (root@localhost)
-
rocommunity public 127.0.0.1
-
agentaddress 161
-
rocommunity public
-
rwcommunity private
-
trapsink 192.168.124.14 public 162 -->这里的ip=192.168.124.14为被监控主机ip
然后,再执行第二步操作即可。
eq
\o\ac(○,2)2添加图像
Nagios NRPE监控远程主机
8.1监控端的设置
监控机安装NRPE
-
wget http://nchc.dl.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
-
tar zxvf nrpe-2.12.tar.gz
-
cd nrpe-2.12
-
./configure --prefix=/usr/local/nagios
-
make all
-
make install-plugin
-
#监控机只需安装到这步
8.2被监控端的设置
8.2.1被监控端添加用户
-
groupadd nagios
-
useradd -g nagios -d /usr/local/nagios -s /sbin/nologin nagios
8.2.2被监控端安装nagios-
plugins插件
-
wget http://nchc.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
-
tar zxf nagios-plugins-1.4.13.tar.gz
-
cd nagios-plugins-1.4.13
-
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios --with-ping-command="/bin/ping" --with-mysql=/opt/mysql
-
make
-
make install
#查看插件文件是否已安装在这个目录
-
ls /usr/local/nagios/libexec
8.2.3被监控端安装NRPE
-
wget http://nchc.dl.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
-
tar zxvf nrpe-2.12.tar.gz
-
cd nrpe-2.12
-
./configure --prefix=/usr/local/nagios
-
make all
-
make install-plugin
-
make install-daemon
-
make install-daemon-config
-
chown -R nagios:nagios /usr/local/nagios
8.2.4配置被监控端的NRPE:
-
vi /usr/local/nagios/etc/nrpe.cfg
-
allowed_hosts=127.0.0.1,192.168.1.22 #Nagios监控机的地址或域名
修改/etc/hosts.allow增加监控机ip
-
echo 'nrpe:192.168.1.22' >> /etc/hosts.allow
8.2.5启动NRPE守护进程:
-
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
8.2.6将nrpe加入/etc/rc.local,以便开机自动启动。
-
echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local
8.2.7检查NRPE是否正常:
在被监控机上
-
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
查看相应的端口:
防火墙开启5666允许局域网IP或固定IP连接
在监控主机上
-
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.222 $目标主机地址(被监控端地址)
都应该可以输出NRPE的版本:NRPE v2.12
8.2.8检查可监控的服务
在被监控端的nrpe.cfg文件中,可以看到这样的配置:
command[check_load]=/usr/local/nagios/libexec/check_load
-w 15,10,5 -c 30,25,20
这是用来检查CPU负载的。
8.2.9配置被监控端的nrpe.cfg
-
vim /usr/local/nagios/etc/nrpe.cfg
-
添加以下内容:
-
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
-
command[check_load]=/usr/local/nagios/libexec/check_cpu.sh -w 80% -c 90%
-
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
-
command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2
-
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
-
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
-
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
-
command[check_iostat]=/usr/local/nagios/libexec/check_iostat.sh -d sda -w 6 -c 10
-
command[check_mysql]=/usr/local/nagios/libexec/check_mysql -H 192.168.0.22 -u nagios -p 123456 -d nagios
-
command[check_nginx]=/usr/local/nagios/libexec/check_nginx.sh -u 192.168.0.22 -p /status -w 4000 -c 5000
-
command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -f -w 20 -c 10
如果需要自定参数则使用下面命令
command[check_load]=/usr/local/nagios/libexec/check_load
-w $ARG1$ -c $ARG2$
并开启dont_blame_nrpe =1
开启参数将会带来一定的安全风险
8.2.10被监控机重启nrpe
-
ps aux|grep nrpe
-
kill $pid
-
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
8.3监控机NRPE的设置
8.3.1在监控机commands.cfg添加nrpe的定义
-
vim /usr/local/nagios/etc/objects/commands.cfg
-
# 'check_nrpe ' command definition
-
define command{
-
command_name check_nrpe
-
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
-
}
8.3.2在监控机的/usr/local/nagios/etc/objects/下添加被监控机的配置文件app1.cfg,并配置
在/usr/local/nagios/etc/objects/目录下新建文件:app1.cfg
把app1.cfg添加到nagios主机:
-
echo "cfg_file=/usr/local/nagios/etc/objects/app1.cfg" >> /usr/local/nagios/etc/nagios.cfg
如果要再添加B机器如法炮制就可以了
-
Vim app1.cfg
-
define host{
-
use linux-server
-
host_name nagios-client
-
alias nagios-client
-
address 192.168.1.222 //被监控端的IP地址
-
icon_image server.gif
-
statusmap_image server.gd2
-
2d_coords 500,200
-
3d_coords 500,200,100
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name *
-
service_description PING
-
check_command check_ping!100.0,20%!500.0,60%
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description boot分区
-
check_command check_nrpe!check_sda1
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description 根分区
-
check_command check_nrpe!check_sda2
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description 登录用户数
-
check_command check_nrpe!check_users
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description 进总程数
-
check_command check_nrpe!check_total_procs
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description CPU平均负载
-
check_command check_nrpe!check_load
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description 虚拟内存
-
check_command check_nrpe!check_swap
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description SSH
-
check_command check_nrpe!check_ssh
-
notifications_enabled 0
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description 僵死进程数
-
check_command check_nrpe!check_zombie_procs
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description iostat
-
check_command check_nrpe!check_iostat
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description mysql
-
check_command check_nrpe!check_mysql
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description nginx
-
check_command check_nrpe!check_nginx
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description memory
-
check_command check_nrpe!check_mem
-
}
-
define service{
-
use local-service ; Name of service template to use
-
host_name nagios-client
-
service_description IP连接数
-
check_command check_nrpe!check_ip_conn
-
}
8.3.3检查nagios配置文件是否报错
-
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
重启监控机nagios
访问就可以看到新增的机器了
阅读(2699) | 评论(0) | 转发(0) |