您的位置:首页 > 运维架构

性能监控工具——Cacti安装文档

2015-06-25 17:11 302 查看
一、Cacti安装说明

1.安装说明



一般性的安装说明,详细的操作系统具体的安装说明可用于Linux.

2.服务器安装要求



RRDTool1.2.x或更高版本

MySQL4.1.x或5.x更高版本

PHP4.3.6,5.x或更高版本

Apache2.2或者更高版本

Perl5.10.1或者更高版本

二、安装在Unix/Linux下

1.请确认安装包是根据你的操作系统的需求

验证httpd和mysqld是在系统启动时启动,确保yum源是原始的源。

2.需要包基于yum的操作系统

php
httpd
php-mysql
php-snmp
php-ldap(whenusingLDAPauthentication)
php-xml
mysql
mysql-server
mysql-devel
net-snmp(dependingonthedistro,net-snmp-utilsmayberequired)
Spine(dependingonthenet-snmp-developenssl-develmayberequired)
crond(cron,cronieorthelike)
gcc
gcc-c++
Perl
Perl-libwww-perl
Python
Pythoneasy_install

3。对于安装官方补丁,您将需要一些工具

wget
patch
三、安装环境

1.监控服务器

1.1[/b]php[/b]安装步骤

使用root用户登录服务器
#yummakecache
#yuminstallphp-xmlphp-mysqlphp-snmpphp-ldapphp-pdophp-develphp
安装成功
参考php配置文件修改

1.2[/b]RRDTool[/b]安装步骤

使用root用户登录服务器
#yuminstallrrdtool
安装成功

1.3[/b]httpd[/b]安装步骤

使用root用户登录服务器
#yuminstallhttpdhttpd-tools
安装成功
参考Apache配置文件修改

1.4[/b]net-snmp[/b]安装步骤

使用root用户登录服务器
#yuminstallnet-snmpnet-snmp-libsnet-snmp-utils
安装成功
参考snmp配置文件修改

1.5[/b]Perl[/b]安装步骤

使用root用户登录服务器,安装perl
#yuminstallperlperl-libwww-perl
安装成功

1.6[/b]Mysql[/b]安装步骤

使用root用户登录服务器,安装mysql
#yuminstallmysqlmysql-servermysql-develmysql-libs
安装成功

1.7[/b]Python[/b]安装步骤

使用root用户登录服务器,安装python
#yuminstallpython

安装pythoneasy_install模块
#wget
#tar'target='_blank'>https://pypi.python.org/packages/source/s/setuptools/setuptools-12.0.5.tar.gz#md5=066e16290f8edcbc8b4b67808b2cbdb2
#tar–xvfsetuptools-12.0.5.tar.gz
#cdsetuptools-12.0.5
#pythonsetup.pyinstall
安装boto模块
#easy_installpythonboto

1.8[/b]Cacti[/b]安装步骤

使用root用户登录服务器,安装cacti
#yumwget
#wgethttp://www.cacti.net/downloads/cacti-0.8.8c.tar.gz
#tar–xvfcacti-0.8.8c.tar.gz
#mvcacti-0.8.8ccacti
#mvcacti/var/www/html
#chmod–R755/var/www/html/cacti
安装成功
参考Cacti配置文件修改

1.9[/b]Cacti[/b]基础插件[/b]Spine[/b]安装步骤

使用root用户登录服务器
安装依赖包
#yuminstall-ynet-snmp-developenssl-devel
#wgethttp://www.cacti.net/downloads/spine/cacti-spine-0.8.8c.tar.gz
#tar-xvfcacti-spine-0.8.8c.tar.gz
#cdcacti-spine-0.8.8c
#mkdir/usr/local/spine
#chmod+x/usr/local/spine
#./configure--prefix=/usr/local/spine
#make&&makeinstall
参考Cacti基础插件Spine配置文件修改

1.10[/b]Cacti[/b]基础插件[/b]Monitor[/b]、[/b]settings[/b]、[/b]thold[/b]安装步骤

使用root用户登录服务器
#wgethttp://docs.cacti.net/_media/plugin:monitor-v1.3-1.tgz
#mvplugin\:monitor-v1.3-1.tgzmonitor-v1.3-1.tgz
#tar-xvfmonitor-v1.3-1.tgz
#cp-Rmonitor/var/www/html/cacti/plugins/
#wgethttp://docs.cacti.net/_media/plugin:settings-v0.71-1.tgz
#mvplugin:settings-v0.71-1.tgzsettings-v0.71-1.tgz
#tar–xvfsettings-v0.71-1.tgz
#cp–Rsettings/var/www/html/cacti/plugins/
#wgethttp://docs.cacti.net/_media/plugin:thold-v0.5.0.tgz
#mvplugin:thold-v0.5.0.tgzthold-v0.5.0.tgz
#tar–xvfthold-v0.5.0.tgz
#cp–Rthold/var/www/html/cacti/plugins/
参考Cacti基础插件monitor、settings、thold配置文件修改

2.受控服务器

2.1[/b]基础监控插件[/b]安装步骤

使用root用户登录监控服务器[/b],安装监控基础模板
#wget
#tar'target='_blank'>http://www.percona.com/downloads/percona-monitoring-plugins/1.1.4/percona-monitoring-plugins-1.1.4.tar.gz
#tar–xvfpercona-monitoring-plugins-1.1.4.tar.gz
#cdpercona-monitoring-plugins-1.1.4\cacti\scripts\
#cp*/var/www/html/cacti/scripts/
#mkdir/var/www/html/cacti/resource/percona
#cdpercona-monitoring-plugins-1.1.4\cacti\
#cp–R*/var/www/html/cacti/resource/percona
#chmod–Rf755/var/www/html/cacti/resource/percona

2.2[/b]net-snmp[/b]安装步骤

使用root用户登录受控服务器[/b]
#yuminstallnet-snmpnet-snmp-libsnet-snmp-utils
安装成功
参考snmp配置文件修改

2.3[/b]编译安装[/b]nginx[/b][/b]

使用root用户登录监控服务器[/b]
#wget
#cp'target='_blank'>http://nginx.org/download/nginx-1.6.2.tar.gz
#cp*.pl/var/www/html/cacti/scripts/
使用root用户登录受控服务器[/b],重新编译安装nginx
#mkdir/usr/local/nginx/
#chmod+x/usr/local/nginx/
#./configure--prefix=/usr/local/nginx--with-http_stub_status_module
#make&&makeinstall
参考监控nginx配置文件修改
四、修改各个配置文件

1.PHP配置文件修改

1.1[/b]配置[/b]php.ini[/b]

使用root用户登陆系统
#vi/etc/php.ini
safe_mode=Off
data.timezone=”Asia/manila”
file_uploads=On
extension_dir="/usr/lib64/php/modules/"或者extension_dir=/etc/php.d
注:如果是php是4.3.6以上版本。请注释掉seesion.save_path=/tmp

2.Apache配置文件修改

2.1[/b]配置[/b]httpd.conf[/b]

使用root用户登录监控服务器
#vi/etc/httpd/conf/httpd.conf
incldueconf.d/*.conf

2.2[/b]配置[/b]cacti.conf[/b]

使用root用户登录监控服务器
#cp/etc/httpd/conf.d/welcome.conf/etc/httpd/conf.d/cacti.conf
按照这个信息配置cacti.conf
#vi/etc/httpd/conf.d/cacti.conf



2.3[/b]配置[/b]php.conf[/b]

使用root用户登录服务器
检查php.conf是否有这些信息
#more/etc/httpd/conf.d/php.conf



3.snmp配置文件修改

3.1[/b]配置[/b]snmpd.conf[/b]

使用root用户登录监控或受控服务器
#vi/etc/snmp/snmpd.conf
原:
viewsystemviewincluded.1.3.6.1.2.1.1
改:
viewsystemviewincluded.1.3.6.1.2.1
原:
com2secnotConfigUserdefaultpublic
改:
com2secnotConfigUser监控端IPpublic
原:
accessnotConfigGroup""anynoauthexactsystemviewnonenone
改:
accessnotConfigGroup""anynoauthexactallnonenone
将#viewallincluded.180前面的#注释去掉
添加监控服务器ip
rocommunityserverIP
保存退出
重启snmpd服务
#servicesnmpdrestart

3.2[/b]设置[/b]snmpd[/b]开机启动[/b]

#chkconfigsnmpdon

4.Cacti配置文件修改

4.1[/b]设置目录权限[/b]

#useraddcactiuser
#chown-Rcactiuserrra/log/

4.2[/b]创建一个[/b]mysqls[/b]数据库[/b]

mysqladmin-user=rootcreatecacti
cd/var/www/html/cacti
导入cacti数据库
mysqlcacti<cacti.sql



mysql>GRANTALLONcacti.*TOcactiuser@localhostIDENTIFIEDBY'somepassword';
mysql>flushprivileges;

4.3[/b]配置计划任务[/b]

使用root用户登录监控服务器
#vi/etc/crontab
*/1****cactiuserphp/var/www/html/cacti/poller.php>/dev/null2>&1
退出保存

4.4[/b]配置[/b]global.php[/b]

使用root用户登录监控服务器
#vi/var/www/html/cacti/include/global.php

$database_type="mysql";

$database_default="cacti";

$database_hostname="127.0.0.1";

$database_username="cacti";

$database_password="cacti";

$database_port="3306";
退出保存

4.5[/b]设置开机启动服务[/b]

使用root用户登录监控服务器
#chkconfigsnmpdon
#chkconfighttpdon
#chkconfigmysqldon
#chkconfigcrondon

4.6[/b]配置[/b]IPTABLES[/b]

使用root用户登录监控服务器

#iptables-AINPUT-ieth0-ptcp--dport80-jACCEPT

4.7[/b]配置[/b]SELINUX[/b]

使用root用户登录监控服务器
#vi/etc/sysconfig/selinux
原:[/b]
#ThisfilecontrolsthestateofSELinuxonthesystem.
#SELINUX=cantakeoneofthesethreevalues:
#enforcing-SELinuxsecuritypolicyisenforced.
#permissive-SELinuxprintswarningsinsteadofenforcing.
#disabled-NoSELinuxpolicyisloaded.
SELINUX=enforcing
#SELINUXTYPE=cantakeoneofthesetwovalues:
#targeted-Targetedprocessesareprotected,
#mls-MultiLevelSecurityprotection.
SELINUXTYPE=targeted
改:[/b]
#ThisfilecontrolsthestateofSELinuxonthesystem.
#SELINUX=cantakeoneofthesethreevalues:
#enforcing-SELinuxsecuritypolicyisenforced.
#permissive-SELinuxprintswarningsinsteadofenforcing.
#disabled-NoSELinuxpolicyisloaded.
SELINUX=disabled
#SELINUXTYPE=cantakeoneofthesetwovalues:
#targeted-Targetedprocessesareprotected,
#mls-MultiLevelSecurityprotection.
#SELINUXTYPE=targeted

4.8[/b]页面配置[/b]

浏览器中输入:http://www.yourdomain.com/cacti/
默认用户名:admin密码:admin

更改密码
安装指南
提示这个直接next
newinstall然后next
直接点完成
登陆界面,登陆之后会提示你重置下密码

5.Cacti基础插件Spine配置文件修改

5.1[/b]配置[/b]spine.conf[/b]

使用root用户登录监控服务器
#cp/usr/local/spine/etc/spine.conf.dist/usr/local/spine/etc/spine.conf
#vi/usr/local/spine/etc/spine.conf
DB_Hostlocalhost
DB_Databasecacti
DB_Usercactiuser
DB_Pass123456
DB_Port3306
DB_PreG0

5.2[/b]修改[/b]Cacti[/b]使用的[/b]PollerType[/b]

以admin用户登录到Cacti
Console->CactiSettings->Poller->PollerType
在”PollerType”下拉框设置中,选择”spine”

5.3[/b]在[/b]cacti[/b]里设置[/b]spine[/b]路径[/b]

以admin用户登录到Cacti
Console->Configuration->Settings->Paths->AlternatePollerPath->SpinePollerFilePath
输入Spine可执行程序的完整路径,我的是/usr/local/spine/bin/spine,保存设置。



6.Cacti基础插件monitor、settings、thold配置文件修改

6.1[/b]导入基础数据[/b]

#mysql-uroot-pcacti</home/www/cacti/plugins/monitor/monitor.sql

6.2[/b]配置[/b]config.php[/b]

使用root用户登录监控服务器
#vi/var/www/html/cacti/include/config.php
$database_type="mysql";
$database_default="cacti";
$database_hostname="localhost";
$database_username="cactiuser";
$database_password="somepassword";
/*loadupoldstylepluginshere*/
$plugins=array();
$plugins[]='thold';
$plugins[]='monitor';
$plugins[]='settings';
$plugins[]='discovery';
/*
EditthistopointtothedefaultURLofyourCactiinstall
ex:ifyourcactiinstallasathttp://serverip/cacti/this
wouldbesetto/cacti/
*/
$url_path="/cacti/";
/*Defaultsessionname-Sessionnamemustcontainalphacharacters*/
#$cacti_session_name="Cacti";
退出保存

6.3[/b]页面配置[/b]

以admin用户登录到Cacti
Console->Configuration->PluginManagement
配置如下图所示:





7.监控nginx配置文件修改

7.1[/b]配置[/b]nginx.conf[/b]

使用root用户登录受控服务器[/b]
在nginx.conf中添加如下(粗体字部分)
#vi/usr/local/nginx/conf/nginx.conf
server{
listen80;
server_namelocalhost;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location/{
root/data/web_server/index;
indexindex.htmlindex.htm;
}
location/nginx_status{[/b]
#Turnonnginxstats[/b]
stub_statuson;[/b]
#Idonotneedlogsforstats[/b]
access_logoff;[/b]
#Security:Onlyallowaccessfrom192.168.1.100IP#[/b]
#allow192.168.1.100;[/b]
#Sendrestoftheworldto/dev/null#[/b]
#denyall;[/b]
}[/b]
}

7.2[/b]页面确认[/b]

通过http://127.0.0.1/nginx_status访问
返回结果类似于:

Activeconnections:1
serveracceptshandledrequests
6556551985
Reading:0Writing:1Waiting:0

8.监控redis配置文件修改

8.1[/b]配置[/b]ss_get_by_ssh.php[/b]

注:此文件在检出监控插件中安装

使用root用户登录受控服务器[/b]
#vim/var/www/html/cacti/scripts/
$ssh_user='root';#SSHusername
$ssh_port=22;#SSHport
$ssh_iden='-i/root/.ssh/id_rsa[/b]';#SSHidentity
##修改根据你的配置,你的ssh连接用户,还有认证私钥的位置
$redis_port=6379;#Whichportredislistenson

8.2[/b]配置[/b]ssh[/b]公私钥无需密码登录[/b]

注:因为cacti监控redis是需要登录到redis的服务端运行redis的状态获取命令,所以需要ssh连接登录。需要配置非交互式帐号密码登录。这里采用公私钥模式。

使用root用户登录监控服务器[/b]
在监控服务器生成一对公私钥
ssh-keygen##如果是root用户,生成的默认目录为/root/.ssh[/b]下2个文件id_rsa(公钥)id_rsa.pub(私钥)
cd/root/.ssh/&&chmod600id_rsa*##把这2个文件修改权限,为600
ssh-copy-id-i/root/.ssh/id_rsaroot@192.168.200.1#加被监控节点公私钥认证

8.3[/b]上传[/b]redis[/b]监控模板[/b]

在本机下载监控模板
http://www.percona.com/downloads/percona-monitoring-plugins/1.1.4/percona-monitoring-plugins-1.1.4.tar.gz
解压percona-monitoring-plugins-1.1.4.tar.gz
上传监控模板Console->ImportTemplates
cacti_host_template_percona_redis_server_ht_0.8.6i-sver1.1.4.xml

9.监控mysql配置文件修改

9.1[/b]创建受控[/b]Mysql[/b]需要的账户以及权限[/b]

使用root用户登录受控服务器[/b]
配置MySQL服务器
让cacti所在机器能够访问MySQL服务器的状态信息,必须拥有”process”权限。如果要监控InnoDB状态,还必须有”SUPER”权限。

mysql>grantprocess,superon*.*to'cacti'@'%'identifiedby'cacti';
mysql>grantallprivilegesoncacti.*tocacti@"%"identifiedby"cacti";


9.2[/b]配置[/b]ss_get_mysql_stats.php[/b]

使用root用户登录监控服务器[/b]
vim/var/www/html/cacti/scripts/scriptsss_get_mysql_stats.php



9.3[/b]上传[/b]mysql[/b]监控模板[/b]

在本机下载监控模板
http://www.percona.com/downloads/percona-monitoring-plugins/1.1.4/percona-monitoring-plugins-1.1.4.tar.gz
解压percona-monitoring-plugins-1.1.4.tar.gz
上传监控模板Console->ImportTemplates
cacti_host_template_percona_mysql_server_ht_0.8.6i-sver1.1.4.xml

10.监控php配置文件修改

10.1[/b]创建[/b]php[/b]监控脚本[/b]

使用root用户登录监控服务器[/b]
vim/var/www/html/cacti/scripts/get_php_fpm_status.php
<?php
#!/usr/bin/php-q
/*doNOTrunthisscriptthroughawebbrowser*/
if(!isset($_SERVER["argv"][0])||isset($_SERVER['REQUEST_METHOD'])||isset($_SERVER['REMOTE_ADDR'])){
die("<br><strong>Thisscriptisonlymeanttorunatthecommandline.</strong>");
}
$default['host']='';#serverhost
$default['script']='/status';#testscript(absolutepathstartingat/-rootdirectory-)
$default['port']=80;#tcpport
$default['timeout']=3;#timeoutinseconds
$args=array();
@list(,$args['host'],$args['script'],$args['port'],$args['timeout'])=$_SERVER["argv"];
foreach($argsas$key=>$value)
$args[$key]=($value)?$value:$default[$key];
if(($args['host']=='')||($args['port']=='')){
print"Usage:get_php_fpm_status.php<host>[<testscript>][<port>][<timeoutseconds>]\n";
exit(-1);
}
#getresouce
$con=curl_init();
curl_setopt($con,CURLOPT_URL,'http://'.$args['host'].':'.$args['port'].$args['script']);
curl_setopt($con,CURLOPT_RETURNTRANSFER,1);
curl_setopt($con,CURLOPT_CONNECTTIMEOUT,10);
$content=curl_exec($con);
curl_close($con);
$result=preg_match("/acceptedconn:\s+(\d+)\s*\n/i",$content,$matches);
$conn['accepted']=($result)?$matches[1]:'n/a';
$result=preg_match("/idleprocesses:\s+(\d+)\s*\n/i",$content,$matches);
$conn['idle']=($result)?$matches[1]:'n/a';
$result=preg_match("/activeprocesses:\s+(\d+)\s*\n/i",$content,$matches);
$conn['active']=($result)?$matches[1]:'n/a';
$result=preg_match("/totalprocesses:\s+(\d+)\s*\n/i",$content,$matches);
$conn['total']=($result)?$matches[1]:'n/a';
echo'accepted:'.$conn['accepted'].'idle:'.$conn['idle'].'active:'.$conn['active'].'total:'.$conn['total'];
保存退出,赋予权限
chmod755/var/www/html/cacti/scripts/get_php_fpm_status.php

10.2[/b]配置[/b]php.ini[/b]

使用root用户登录监控服务器[/b]
cp/etc/php-fpm.d/www.conf/etc/php-fpm.d/www.conf.bak
vim/etc/php-fpm.d/www.conf
原:
allow_url_fopen=Off
改:
allow_url_fopen=On
原:
#user_agent="PHP"
改:
user_agent="PHP"

10.3[/b]上传[/b]mysql[/b]监控模板[/b]

在本机下载监控模板
http://forums.cacti.net/download/file.php?id=23101
解压PHP-FPM-Template.tar
上传监控模板Console->ImportTemplates
Custom_PHP-FPM.xml


来自为知笔记(Wiz)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: