生产环境:
操作系统:CentOS6.6
任务:监控服务器上安装cacti,配置被监控服务器。
我们要理解监控端(监控服务器),被监控端(客户端)。监控服务器需要安装的软件(包括:net-snmp、libart_lgpl、rrdtool、apache、mysql、php、cacti),被监控端(snmp)。
一、Linux监控服务器上安装Cacti
生产环境:CentOS 6.6
说明:因生产环境操作系统会最小化安装,在安装软件的时候,请把相关基础软件包安装,否则在安装的过程会报错。
例如:yum install gcc glibc glibc-common cairo pango zlib zlib-devel freetypefreetype-devel gd gd-devel -y
1. 安装net-snmp及配置:
(1)安装net-snmp
[root@sky9896 sky]#yum install net-snmp* -y
[root@sky9896sky]# cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.ori
[root@sky9896sky]#cat>/etc/snmp/snmpd.conf<
com2sec local localhost public
com2sec mynetwork 117.40.239.9 public #定义共同体名
group MyRWGroupv1 local #定义组名
group MyRWGroupv2c local
group MyRWGroupusm local
group MyROGroupv1 mynetwork
group MyROGroupv2c mynetwork
group MyROGroupusm mynetwork
view all included .1 80
access MyROGroup"" any noauth exact all none none
access MyRWGroup"" any noauth exact all all none
syslocation bbs.jxatei.net
syscontact Me <[email protected]> #邮箱
proc mountd
proc ntalkd 4
proc sendmail 10 1
proc httpd 10 1
exec echotest/bin/echo hello world
exec disk_used_shell /bin/sh /root/current_disk_used.sh
exec httpd_proc /bin/sh /root/current_httpd_proc.sh
disk / 10000
disk /boot 10000
load 12 14 14
EOF #不要忘记了结束符
注意:
(1) 定义好共同体名,在配置windows客户端时,共体同名要一致。
(2) com2sec mynetwork 117.40.239.9 public #根据实际情况设置IP地址,做为监控访问通信的地址。
(2)启动snmpd服务:
[root@sky9896 sky]#/etc/init.d/snmpd start #方法一
正在启动 snmpd:
[root@sky9896 sky]#service snmpd start #方法二
正在启动 snmpd:
(3)检查端口及进程是否启动:
[root@sky9896 sky]# lsof-i:161
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
snmpd 29939 root 7u IPv4 4091635 0t0 UDP *:snmp
[root@sky9896 sky]#netstat -lntup|grep 161 #检查端口号
udp 0 0 0.0.0.0:161 0.0.0.0:* 29939/snmpd
[root@sky9896 sky]# ps-ef|grep snmpd|grep -v grep #检查进程
root 29939 1 0 09:58 ? 00:00:00 /usr/sbin/snmpd -LS0-6d -Lf/dev/null -p /var/run/snmpd.pid
2. 安装:libart_lgpl-2.3.17
[root@sky9896tools]#wget
http://ftp.gnome.org/pub/gnome/sources/libart_lgpl/2.3/libart_lgpl-2.3.17.tar.bz2
[root@sky9896tools]# wget
http://oss.oetiker.ch/rrdtool/pub/libs/libart_lgpl-2.3.17.tar.gz
[root@sky9896libart_lgpl-2.3.17]#./configure
[root@sky9896libart_lgpl-2.3.17]#make && make install
3. 安装rrrdtool-1.2.30
[root@sky9896tools]#wget
http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.2.30.tar.gz
[root@sky9896tools]#tar xf rrdtool-1.2.30.tar.gz
[root@sky9896tools]#cd rrdtool-1.2.30
[root@sky9896tools]#./configure
[root@sky9896tools]#make && make install
[root@sky9896tools]#
ls-l /usr/local/rrdtool-1.2.30/bin/rrdtool && ln -s/usr/local/rrdtool-1.2.30/bin/rrdtool
[root@sky9896tools]#
ls -l /usr/local/rrdtool-1.2.30/bin/rrdtool &&ln -s /usr/local/rrdtool-1.2.30/bin/rrdtool /usr/local/bin/rrdtool
注意事项:
报错1:
make[3]: *** [perl-piped/Makefile] 错误 2
make[3]: Leaving directory`/home/skyboy/tools/cacti_tools/rrdtool-1.2.30/bindings'
make[2]: *** [all-recursive] 错误 1
make[2]: Leaving directory`/home/skyboy/tools/cacti_tools/rrdtool-1.2.30/bindings'
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory`/home/skyboy/tools/cacti_tools/rrdtool-1.2.30
[root@sky9896 tools]#yum -y install perl-ExtUtils-MakeMaker
#解决问题
报错2:
configure: error: Please fix the library issues listedabove and try again.
[root@sky9896 tools]#yum-y install pango*
报错3:
configure: error: Please fix thelibrary issues listed above and try again.
[root@sky9896 tools]#yum –y install pango-devel*cairo-devel*
4. 安装apache、Mysql、PHP
(1) 安装mysql php httpd
[root@sky9896tools]#yum install mysql* httpd*php* --skip-broken -y
[root@sky9896 tools]#cd /etc/httpd/conf
[root@sky9896 tools]#cp httpd.conf httpd.conf.oldboy.ori
[root@sky9896 tools]#sed -i 's#\#ServerName www.example.com:80#ServerName127.0.0.1:80#' /etc/httpd/conf/httpd.conf #做本地解析就不会提示没有解析
[root@sky9896 tools]#sed-i 's#DirectoryIndex index.html index.html.var#DirectoryIndex index.phpindex.html #' /etc/httpd/conf/httpd.conf #修改成'index.php”为默认主页。
(2) 启动httpd服务
[root@sky9896 sky]# /etc/init.d/httpd start
正在启动 httpd:
(3) 检查端口
[root@sky9896 sky]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 17871 root 4u IPv6 3224763 0t0 TCP *:http (LISTEN)
httpd 17873 apache 4u IPv6 3224763 0t0 TCP *:http (LISTEN)
httpd 17874 apache 4u IPv63224763 0t0 TCP *:http (LISTEN)
httpd 17875 apache 4u IPv6 3224763 0t0 TCP *:http (LISTEN)
httpd 17876 apache 4u IPv6 3224763 0t0 TCP *:http (LISTEN)
httpd 17877 apache 4u IPv6 3224763 0t0 TCP *:http (LISTEN)
httpd 17878 apache 4u IPv6 3224763 0t0 TCP *:http (LISTEN)
httpd 17879 apache 4u IPv6 3224763 0t0 TCP *:http (LISTEN)
[root@sky9896sky]# netstat -lntup|grep 80
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2804/mysqld
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 1811/java
tcp 0 0 :::8009 :::* LISTEN 1811/java
tcp 0 0 :::80 :::* LISTEN 17871/httpd
tcp 0 0 :::8080 :::* LISTEN 1811/java
[root@sky9896 sky]# ps -ef|grep httpd|grep -v grep
测试主页:
[root@sky9896 sky]# echo -e"" >/var/www/html/index.php
http://ip地址
(4) 启动Mysql服务
[root@sky9896 sky]#/etc/init.d/mysqld start
正在启动 mysqld: [确定]
[root@sky9896 sky]# lsof -i:3306 #检查端口
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 2804 mysql 10u IPv4 3272205 0t0 TCP *:mysql (LISTEN)
[root@sky9896 sky]# ps -ef|grep mysqld|grep -v grep #检查进程
root 2597 1 0Nov09 ? 00:00:00 /bin/sh/usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock--pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 2804 2597 1Nov09 ? 00:12:13/usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql--plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log--pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
5. 安装cacti
#对cacti用户授权,然后建立数据库
mysql>GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser';
QueryOK, 0 rows affected (0.00 sec)
mysql>flush privileges;
QueryOK, 0 rows affected (0.00 sec)
mysql>create database cacti;
QueryOK, 1 row affected (0.00 sec)
[root@sky9896 tools]# wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz
[root@sky9896 tools]#tar zxf cacti-0.8.8a.tar.gz
[root@sky9896 cacti-0.8.8a]# mysql –uroot –p cacti
[root@sky9896 cacti-0.8.8a]# chown -Rapache rra/ log/
[root@sky9896 cacti-0.8.8a]# mv../cacti-0.8.8a /var/www/html/cacti
[root@sky9896 html]# chown -Rapache.apache cacti
[root@sky9896 html]# chmod 755/var/www/html/cacti/poller.php
[root@sky9896 html]# echo '*/5 * * ** /usr/bin/php/var/www/html/cacti/poller.php >/dev/null 2>&1' >>/var/spool/cron/root
注意事项:
[root@sky9896 html]# vi /etc/sysconfig/iptables
-A INPUT -p udp -m state --state NEW -m udp --dport 161 -j ACCEPT #设置161端口通过防火墙
浏览器端(客户端):
http://117.40.239.9/cacti/index.php
二、 Linux被监控服务器(客户端配置)
Linux客户端配置,只要安装net-SNMP软件包。
[root@A ~]# yum install net-snmp* -y
[root@A ~]# cat>/etc/snmp/snmpd.conf<
com2sec local localhost public
com2sec mynetwork 117.40.239.9 public #监控服务器IP地址
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view all included .1 80
access MyROGroup "" any noauth exact all none none
access MyRWGroup"" any noauth exact all all none
syslocation 117.40.239.9
syscontact Me <[email protected]>
proc mountd
proc ntalkd 4
proc sendmail 10 1
proc httpd 10 1
exec echotest /bin/echo hello world
exec disk_used_shell /bin/sh /root/current_disk_used.sh
exec httpd_proc /bin/sh /root/current_httpd_proc.sh
disk / 10000
disk /boot 10000
load 12 14 14
EOF
[root@A~]# vi/etc/sysconfig/iptables
-A INPUT -p udp -m state --state NEW -m udp --dport 161 -j ACCEPT #在iptables里添加上一条,用来对161端口通过防火墙
三、Windows被监控服务器(客户端配置)
1)、打开“控制面板”-“添加删除程序”-“添加删除组建”在“管理和监视工具”中选中“简单网络管理协议(snmp)”点击“下一步”,开始安装,在安装过程中需要i386文件。
(2)、打开“开始”-“程序”-“管理工具”-“服务”,找到“snmpservice”,右键打开“属性”,选择“安全”,在“接受团体名称”处,点“添加”,在“团体名称”处写入你的cacti使用的community,选中“接受来自这些主机的snmp数据包”,默认值为“localhost”,点击“编辑”,将“localhost”改为cacti监控服务器的实际 ip地址。请看下面示意图。
小结cacti安装配置文档,但是还有好多细节没有小结出来,在后续期间还会整理相关文档。在这里想讲一个学习思路,或者是说学习体会吧。首先,对理论进行大概的了解,特别是cacti的工作原理和流程先了解一下,理解最好,不过没有理解也没有关系,我们在虚拟机上做实验过程当中来消化理论。虚拟机上研究的差不多,然后直接在生产服务器上上线。