分类: LINUX
2012-05-11 18:28:50
一、准备软件包:
LNMP环境:
1.首先安装mysql数据库:
mysql-5.1.62.tar.gz
moxiu_liwei ~ # useradd -s /sbin/nologin mysql
moxiu_liwei ~ # tar vzxf mysql-5.1.62.tar.gz
moxiu_liwei ~ # cd mysql-5.1.62
moxiu_liwei ~ # ./configure --prefix=/usr/local/mysql --datadir=/usr/local/mysql/var
moxiu_liwei ~ # make
moxiu_liwei ~ # make install
moxiu_liwei ~ # cp support-files/my-medium.cnf /etc/my.cnf
moxiu_liwei ~ # /usr/local/mysql/bin/mysql_install_db --user=mysql
moxiu_liwei ~ # chown -R root:mysql /usr/local/mysql
moxiu_liwei ~ # chown -R mysql /usr/local/mysql/var
moxiu_liwei ~ # cp support-files/mysql.server /etc/init.d/mysqld
moxiu_liwei ~ # rc-update add mysqld default
moxiu_liwei ~ # /usr/local/mysql/bin/mysqld_safe --user=mysql &
moxiu_liwei ~ # chmod 755 /etc/init.d/mysqld
moxiu_liwei ~ # /etc/init.d/mysqld restart
moxiu_liwei ~ # netstat -auntp |grep 3306
2.安装php,在安装php之前先把php需要的一些库安装上,如下:
Libconv libxml2 jpeg freetype zlib libpng libmcrypt gd 这些库安装好后安装PHP
php-5.2.10.tar.gz php-5.2.10-fpm-0.5.11.diff
moxiu_liwei ~ # tar vzxf php-5.2.10.tar.gz
moxiu_liwei ~ # gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1
moxiu_liwei~ # cd php-5.2.10
moxiu_liwei~ # ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt-dir --enable-sockets --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-zend-multibyte --disable-ipv6 --enable-fastcgi --enable-fpm
moxiu_liwei~ # make && make install
moxiu_liwei~ # cp php.ini-dish /etc/php.ini
moxiu_liwei~ # vi /usr/local/php/etc/php-fpm.conf
moxiu_liwei~ # useradd -s /sbin/nologin www
修改用户和组的名称为”www”
去掉注释,改成这样:
Unix user of processes
Unix group of processes
moxiu_liwei~ # /usr/local/php/sbin/php-fpm start
moxiu_liwei~ # netstat -auntp |grep 9000
3.安装Nginx:
nginx-1.0.14.tar.gz pcre-8.30.tar.gz
在安装nginx之前先安装pcre
moxiu_liwei~ # tar vzxf pcre-8.30.tar.gz
moxiu_liwei~ # cd pcre-8.30
moxiu_liwei~ # ./configure
moxiu_liwei~ # make && make install
moxiu_liwei~ # tar vzxf nginx-1.0.14.tar.gz
moxiu_liwei~ # cd nginx-1.0.14
moxiu_liwei~ # ./configure --prefix=/usr/local/nginx --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/var/nginx.pid --lock-path=/usr/local/nginx/var/nginx.lock --http-client-body-temp-path=/dev/shm/nginx_temp/client_body --http-proxy-temp-path=/dev/shm/nginx_temp/proxy --http-fastcgi-temp-path=/dev/shm/nginx_temp/fastcgi --user=www --group=www --with-cpu-opt=pentium4F --without-select_module --without-poll_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_geo_module --without-http_memcached_module --without-http_map_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-pcre (可以适当删减)
moxiu_liwei~ # make && make install
4.修改nginx配置,启动nginx(一会添加)
二、安装Cacti
所需软件包:
rrdtool-1.4.5.tar.gz、net-snmp-5.7.1.tar.gz、cacti-0.8.7g.tar.gz、cacti-plugin-0.8.7g-PA-v2.8.tar.gz
1.安装rrdtool工具:
moxiu_liwei~ # tar vzxf rrdtool-1.4.5.tar.gz
moxiu_liwei~ # cd rrdtool-1.4.5
moxiu_liwei~ # ./configure --prefix=/usr/local/rrdtool
moxiu_liwei~ # make && make install
2.安装net-snmp工具:
moxiu_liwei~ # tar vzxf net-snmp-5.7.1.tar.gz
moxiu_liwei~ # cd net-snmp-5.7.1.tar.gz
moxiu_liwei~ # ./configure (根据下面内容填写)
--prefix=/usr/snmp
enable-mfd-rewrites
with-default-snmp-version=2
with-sys-contact=yourname
with-sys-location=China
with-logfile=/var/log/snmpd.log
with-persistent-directory=/var/net-snmp
moxiu_liwei~ # make && make install
PS:以上软件如系统为gentoo可以使用emerg来安装;
3.安装cacti:
Mysql -u root -p
mysql>create database cacti default character set utf8 collate utf8_general_ci;
mysql>grant all on cacti.* to cacti@localhost identified by "cacti";
moxiu_liwei~ # tar vzxf cacti-0.8.7g.tar.gz
moxiu_liwei~ # mv cacti-0.8.7g /usr/local/nginx/html/cacti
moxiu_liwei~ # tar vzxf cacti-plugin-0.8.7g-PA-v2.8.tar.gz -C /usr/local/nginx/html/cacti/
moxiu_liwei~ # cd /usr/local/nginx/html/cacti/
moxiu_liwei cacti # mv cacti-plugin-arch/cacti-plugin-0.8.7g-PA-v2.8.diff ./
moxiu_liwei cacti # patch -p1 -N < cacti-plugin-0.8.7g-PA-v2.8.diff
moxiu_liwei cacti # mysql -u root -p cacti
moxiu_liwei cacti # cd cacti-plugin-arch
moxiu_liwei cacti-plugin-arch # mysql -u root -p cacti
moxiu_liwei cacti-plugin-arch # cd ../
moxiu_liwei cacti # vi include/config.php
修改如下条目:
$database_username = "cactiuser";
$database_password = "cactiuser";
修改成:
$database_username = "cacti";
$database_password = "cacti";
4.在浏览器里输入本机IP地址/cacti来进行安装:
5.因为打完补丁后,登陆cacti图片显示不正常,解决方法如下:
moxiu_liwei cacti # vi include/global.php
在$config['url_path'] = $url_path;下面添加一行:
$config['url_path'] = "/cacti2/cacti/";
然后在浏览器里再次输入:192.168.0.X/cacti来进行登陆,用户名密码全部为admin;
6.上面的补丁cacti-plugin-0.8.7g-PA-v2.8.tar.gz是添加插件管理选项的,默认登陆后不显示,需要为用户开启权限才能看到:
User Management——>用户——>Realm Permissions下面把Plugin Management打上对勾;
然后在Utilities选项下就可以看到Plugin Management选项;
7.添加数据收集计划任务:
Crontab -e
*/5 * * * * /usr/local/php/bin/php /usr/local/nginx/html/cacti/poller.php > /dev/null 2>&1
保存退出
到此cacti已经安装成功;
三、配置SNMP:
1.修改配置文件/etc/snmp/snmp.conf,添加如下条目:
com2sec mynetwork 10.0.0.0/24 moxiu_monitor(要根据自己的实际需求来修改)
2.重启snmp服务
moxiu_liwei cacti # /etc/init.d/snmpd restart
moxiu_liwei cacti # netstat -auntp |grep snmpd 查看snmp服务是否启动
3.进入cacti后需确认更改以下位置:
Console>>General
RRDTool Utility Version 确认版本,要根据自己上面安装的版本来选择
SNMP Version 选择Version2
SNMP Community 根据自己snmp配置文件里COMMUNITY选项来设置,要保持一致;
四、为cacti添加插件:
1.所需软件包:
Monitor.tar.gz 、settings.tar.gz、thold.tar.gz
moxiu_liwei cacti # tar vzxf monitor.tar.gz -C /usr/local/nginx/html/cacti/plugins/
moxiu_liwei cacti # tar vzxf monitor.tar.gz -C /usr/local/nginx/html/cacti/plugins/
moxiu_liwei cacti # tar vzxf monitor.tar.gz -C /usr/local/nginx/html/cacti/plugins/
moxiu_liwei cacti # cd /usr/local/nginx/html/cacti/plugins/monitor/
moxiu_liwei monitor # mysql -u root -p cacti
moxiu_liwei monitor # cd ../thold
moxiu_liwei thold # mysql -u root -p cacti
2.登陆cacti,到Configuration下的Plugin Management里点击插件进行安装;
五、为cacti导入模板:
这一步需要根据自己的需求,假如nginx监控,则需要下载cacti-nginx的模板,把其中的脚本放到/cacti/scripts/目录下,然后把.xml文件从Import/Export下的Import Templates中导入即可;
六、监控主机:
1.首先为被监控端安装net-snmp软件包,让其snmp服务启动起来,然后修改被监控客户端的snmp配置文件:
moxiu_liwei1 # vi /etc/snmp/snmp.conf
添加如下字段:
com2sec mynetwork 10.0.0.48(cacti服务器IP) moxiu_monitor
然后保存退出后重启snmpd服务
moxiu_liwei1 # /etc/init.d/snmpd restart
2.添加监控设备:
在添加监控设备之前,可以先到Templates-->Host Templates里找到ucd/net SNMP Host选项,点进去后为其编辑,添加相应的图像模板;
然后在Devices选项中添加设备,ADD后
Description:为被监控服务器起一个名,比如Web服务器
Hostname:这项可以填Cacti服务器的IP地址,也可以填他的主机名
Host Template:选择ucd/net SNMP Host
SNMP Version:选择Version2
SNMP Community: 填写服务器SNMP配置文件里community下面对应的名称
然后点Create,完成添加设备。
3.添加完成后,成功与否查看方法是看保存后IP地址下面SNMP Information,假如有信息说明添加成功,如SNMP Information信息为SNMP error,则为失败,请查看cacti服务器与被监控服务器的SNMP配置、网络连通性等来排查错误;
4.添加设备成功后,在刚添加的设备信息右侧有一项“Create Graphs for this Host”,点此为被监控主机创建监控图像。
七、监控查看:
创建完图像后,可以到最上面“graphs”选项里查看是否有图像生成,一般会等5分钟左右生成图像;
PS:为cacti目录下的rra与log修改权限,chmod 777 rra log,不然会出现生不成图像的错误;
q30296092015-03-29 13:21:05
你好!~~ 我按照你的做法,在安装cacti后的一步:patch -p1 -N < cacti-plugin-0.8.7g-PA-v2.8.diff报错了,也没有include/global.php这个文件(我装的是apache)
[root@node1 cacti]# patch -p 1 -N < cacti-plugin-0.8.7b-PA-v2.1.diff
patching file auth_changepassword.php
Hunk #1 FAILED at 54.
1 out of 1 hunk FAILED -- saving rejects to file auth_changepassword.php.rej
patching file auth_login.php
Hunk #1 FAILED at 205.
Hunk