cacti監控腳本
❶ 如何使用CactiEZ進行監控Windows主機
如何使用CactiEZ進行監控:
1.要監視一台linux主機,需要在被監控的主機上安裝net-snmp相關軟體包,CentOS安裝可使用「yum -y install net-snmp」命令:
# yum -y install net-snmp
……
Complete!
2.修改配置文件命令:
# vi /etc/snmp/snmpd.conf 確保snmpd.conf文件中包含以下內容:
com2sec notConfigUser default public
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
view systemview included .1
access notConfigGroup "" any noauth exact systemview none none
syslocation www.cactiez.com #系統的物理位置
syscontact Root [email protected] # 聯系人
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
保存並退出
3.開啟snmpd服務:
# service snmpd start
4.設置snmpd每次開機時自動啟動:
# chkconfig snmpd on。該命令執行完成後不會返回任何結果
5.檢查snmpd服務是否已在運行:
# netstat -nlup | grep ":161"
udp 0 0 0.0.0.0:161 0.0.0.0:* 16986/snmpd
該命令檢查本地是否已在監聽UDP埠161,如果返回類似以上結果,表明snmpd服務啟動成功。
6.登錄CactiEZ-Web界面,依次點擊:「控制台」,「主機」,「添加」。添加以下設置:
如何使用CactiEZ進行監控Linux主機
7.如果一切正常,您將會看到類似以下信息:
如何使用CactiEZ進行監控Linux主機
如果不正常,請檢查團體名稱,IP地址,防火牆等。
8.主機添加後,需要添加圖形,點擊右上方的「為這個主機添加圖形」。
8.1在「圖形模板」區域鉤選所有對象:
添加: ucd/net - CPU使用率
添加: ucd/net - 負載平均值
添加: ucd/net - TCP記數器
添加: ucd/net - TCP連接數
添加: ucd/net - 內存使用率
添加: 主機MIB - 進程數量
添加: 主機MIB - 已登錄用戶
8.2在「數據查詢 [SNMP - 獲取磁碟IO]」區域鉤選您需要監控的磁碟名稱:
如sda,sdb,hda等。
注意:磁碟IO有兩個指標需要監控,一個是「磁碟IO 位元組/秒」,另一個是「磁碟IO 傳輸/秒」,但一次只能添加一個,如果要監控兩個指標,需要添加兩次。
8.3在「數據查詢 [SNMP - 獲取處理器信息]」區域鉤選您的邏輯處理器,
如果您只有一個邏輯處理器,那麼這里將不可選擇。
8.4在「數據查詢 [SNMP - 獲取已掛載分區]」區域鉤選您需要監控的磁碟名稱:
如「Real Memory」,「Swap Space」,「/」等,根據您的需求鉤選。
8.5在「數據查詢 [SNMP - 介面統計]」區域鉤選您的網路設備,如「eth0」。
如果該主機為64位主機,請選擇「流入/流出 位(64位)」。
如果該主機為32位主機,請選擇「流入/流出 位」即可。
9.再次點擊「添加」已完成設置。
10.查看主機狀態,點擊上方的「監視器」按鈕,顯示綠色表示正常。
❷ 如何使cacti監控mysql伺服器
cacti監控mysql資料庫的方法
環境:
Cactiez或者cacti主機:192.168.12.5
被監控mysql資料庫主機:192.168.5.231
1. 安裝監控插件
cd /opt
tar -xzvf mysql-cacti-templates-1.1.2.tar.gz
cp /opt/mysql-cacti-templates-1.1.2/ss_get_mysql_stats.php /var/www/html/scripts/
其實裡面我們要監控mysql用到的是:acti_host_template_x_db_server_ht_0.8.6i.xml和mysql_definitions.pl
其他則是監控Apache和Nginx的,接下來我們會介紹到,這里不再詳細的講了。
chown -R apache.apache /var/www/html/scripts
chmod -R 755 /var/www/html/scripts
使用 http 訪問 cacti主機 導入
/opt/mysql-cacti-templates-1.1.2/cacti_host_template_x_db_server_ht_0.8.6i.xml
http://192.168.12.5
默認CactiEZ 和Cacti別是 admin admin
控制台 - 導入導出 - 模板導入 - 瀏覽
選中 cacti_host_template_x_db_server_ht_0.8.6i.xml
保存
2. 配置cacti的mysql插件
修改 ss_get_mysql_stats.php
vi /var/www/html/scripts/ss_get_mysql_stats.php
$mysql_user = 'cacti';
$mysql_pass = 'cacti';
$cache_dir = "/tmp/cacti/cache/";
這個賬戶和密碼是 被監控端主機 給 Cacti主機 授權的 賬戶和密碼
Cacti需要這個賬戶和密碼去連接 被監控機 查詢狀態
mkdir -p /tmp/cacti/cache
chown -R apache.apache /tmp/cacti
chmod -R 755 /tmp/cacti
設置 cacti 緩存目錄在 /tmp/cacti/cache/ 並給予許可權
3. 配置被監控端(192.168.5.231)的mysql 給 cacti 主機授權
mysql -uroot -p
grant process,super on *.* to 'cacti'@'192.168.12.5' identified by 'cacti';
exit
grant process,super on *.* to '賬戶'@'Cacti主機IP地址' identified by '密碼';此命令意義
只允許IP為 192.168.12.5 的主機 以賬戶 cacti 密碼 cacti 去訪問 本機數據
4. 在Cacti主機上(192.168.12.5) 監控Mysql
4.1 為主機添加mysql模塊
控制台 - 管理 - 設備 - 選中之前創建好的主機
然後移到最下面的 添加圖形模版 選中 Mysql相關模塊 然後保存
4.2 為mysql模塊創建圖形
控制台 - 創建 - 創建圖形 - 選中該主機 - 選中mysql模塊 - 創建
4.3 插件mysql性能數據
監視器 - 選中該主機 - 查閱對應的mysql
完畢
-----一些資料庫操作語句
mysqld_safe --user=mysql &
mysql -uroot -p
mysql -uroot -proot
grant ALL PRIVILEGES ON *.* to 『root』@"%" identified by "root" WITH GRANT OPTION;
exit
grant select,insert,update,delete on cacti.* to 『cacti』@」*」identified by "cacti";
exit
grant process,super on *.* to 'cacti'@'%' identified by 'cacti';
grant all privileges on cacti.* to 『cacti』@"%" identified by "cacti";
客戶端開啟Cacti訪問本機mysql的許可權
grant process,super on *.* to 'cacti'@'192.168.12.5' identified by 'cacti';
grant process,super on *.* to 'cacti'@'192.168.5.231' identified by 'cacti';
= = = = =
mysql -ucacti -pcacti -h 192.168.5.231
❸ linux下的監測工具,這幾個哪個最好zabbix、nagios、munin、cacti
報警
繪圖 snmp 專用客戶端
自定義腳本 web前端 優點 缺點
cacti N
Y Y N Y Y 管理方便 監控有限,
若要添加自定
義圖表比較麻煩
munin N Y Y Y Y Y 管理方便 靈活度不高,
監控有限,
若要添加
自定義圖
表比較麻煩
zabbix Y Y Y Y Y Y 功能全面 使用較麻煩
opennms Y Y Y
monit Y N N N Y Y 能自動重啟服務,
web界面啟動或者關閉服務 監控本機比較
方便,不適合
監控遠程主機
nagios Y N Y Y
Y Y 報警功能強大
❹ cacti監控
1.交換機和路由器開啟snmp服務
2.為交換機及路由器指定snmp數據接收伺服器
3.以上兩項配置好就可以監控到數據了
同時推薦一款軟體cacti,是目前我發現的網路監控最好的軟體了
red hat linux 除非你花錢買 紅冒的 更新源...
否這你得....至少編譯安裝這些軟體以解決依賴問題
dejavu-lgc-sans-mono-fonts
mysql
net-snmp
php
php-cli
php-common
php-mysql
php-pdo
php-snmp
rrdtool
dejavu-fonts-common
dejavu-sans-fonts
dejavu-sans-mono-fonts
dejavu-serif-fonts
mysql-libs
net-snmp-libs
伺服器監控的話,建議使用nagios,非常強大
❺ 哪位Cacti高手可以指點下 Cacti如何用腳本來抓數據和如果把數據畫成圖。本人新手。
我現在日常就用著cacti,cacti用腳本抓取數據其實很簡單的,簡單步驟:
1,把腳本放在cacti安裝目錄下的scripts下
2,腳本獲取的數據輸出格式為 xxx:123 ,前面的xxx為變數名稱,後面的數字為腳本抓到的值
3,到cacti里建立一個數據輸入模板,數據類型選擇腳本,填上腳本的路徑比如<path_cacti>/scripts/host_avg_num_cpu.sh <hostname> (後面<>中為自己定義需要傳遞給腳本的變數,可以多個)
3.1,新建Input Fields,就是上面自己定義的變數(有部分內置變數,詳看Special Type Code的說明)
3.2,新建Output Fields,名稱一定要和上面腳本輸出的xxx一樣,記得選上Update RRA
4,新建數據模板,主要是選擇對輸入模板名稱和輸入模板中的Output Fields,數據類型默認的好
5,新建圖形模板,選擇上一步建立好的數據模板中的數據;畫線的話可以選擇LINE1,細項自己看一下就清楚了,很簡單的。需要注意的是畫圖一定需要選擇average,選擇其它會造成不出圖;下面的數據限制默認會是100,需要改成0,要不超100的數據也不會畫。
❻ cacti使用
apache2.2.8+mysql5.0.51+php5.2.5+snmp5.14+rrdtool+cacti 配置
OS fedora7 安裝選包定製
全選開發包
伺服器 一個沒選
本機IP 192.168.1.254
安裝 mysql
所有安裝程序 在 /usr/local下
[root@localhost usr]# groupadd mysql
[root@localhost usr]# useradd -g mysql mysql
[root@localhost usr]# cd /usr/local
[root@localhost local]# tar -zxvf mysql-5.0.51.tar.gz
[root@localhost local]# cd mysql-5.0.51
[root@localhost mysql-5.0.51# ./configure --prefix=/usr/local/mysql
[root@localhost mysql-5.0.51]# make
[root@localhost mysql-5.0.51]# make install
[root@localhost mysql-5.0.51]# cd ../mysql
[root@localhost mysql]# scripts/mysql_install_db --user=mysql
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql var
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# ./bin/mysqld_safe --user=mysql &
[root@localhost mysql]# ./bin/mysqladmin -uroot password mysql
[root@localhost mysql]# cp ../mysql-5.0.51/support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql]# cp ../mysql-5.0.51/support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig --level mysqld 345 on
[root@localhost mysql]# chkconfig --list mysqld
[root@localhost mysql]#
Mysql 安裝結束
安裝apache
[root@localhost usr]# tar -zxvf httpd-2.2.8.tar.gz
[root@localhost usr]# cd httpd-2.2.8
[root@localhost httpd-2.2.8]# ./configure --prefix=/usr/local/apache --enable-mods-shared=all --enable-so
[root@localhost httpd-2.2.8]# make;make install
[root@localhost httpd-2.2.8]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@localhost httpd-2.2.8]# cd /etc/rc3.d
[root@localhost rc3.d]# ln -s /etc/init.d/httpd S85httpd
[root@localhost rc3.d]# ln -s /etc/init.d/httpd K85httpd
[root@localhost rc3.d]# /usr/local/apache/bin/apachectl star
Apache 安裝完畢
安裝PHP
安裝支持圖形處理,自己可以找最新的安裝。
##### zlib#####
cd zlib-1.2.3
./configure --prefix=/usr/local/zlib
make
make install
cd ..
##### FreeType ##### freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure --prefix=/usr/local/freetype
make
make install
cd ..
##### LibPNG #####
cd libpng-1.2.20
cp scripts/makefile.linux makefile
make test
make install
cd ..
##### Jpeg ##### jpegsrc.v6b.tar.gz
cd jpeg-6b
mkdir /usr/local/jpeg
mkdir /usr/local/jpeg/bin
mkdir /usr/local/jpeg/lib
mkdir /usr/local/jpeg/include
mkdir /usr/local/jpeg/man
mkdir /usr/local/jpeg/man/man1
./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
make
make install
cd ..
##### gd ##### gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --prefix=/usr/local/gd \
--with-jpeg=/usr/local/jpeg \
--with-freetype=/usr/local/freetype \
--with-png \
--with-zlib
[root@localhost local# tar -zxvf php-5.2.5.tar.gz
[root@localhost local# cd php-5.2.5
[root@localhost php-5.2.5]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-
mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --with-openssl=/usr/local/ssl --with-gd=/usr/local/gd --
with-gdbm=/usr/lib --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir --with-
zlib=/usr/local/zlib --enable-mbstring --enable-sockets
[root@localhost php-5.2.5]# make;make install
[root@localhost php-5.2.5]# cp php.ini-dist /usr/local/php/etc/php.ini
[root@localhost php-5.2.5]# vi /usr/local/apache/conf/httpd.conf
按 I 鍵 添加 AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddType image/x-icon .ico
DirectoryIndex index.php index.html index.html.var
保存退出 :wq
[root@localhost php-5.2.5]# /usr/local/apache/bin/apachectl restart
Php安裝完畢
設置mysql
[root@localhost httpd-2.2.8]# /usr/local/mysql/bin/mysql -u root -pmysql
mysql> create database cactidb;
mysql> grant all on cactidb.* to root;
mysql> grant all on cactidb.* to root@localhost;
mysql> grant all on cactidb.* to cactiuser;
mysql> grant all on cactidb.* to cactiuser@localhost;
mysql> set password for cactiuser@localhost=password('cactipw');
註:以上語句輸出 Query OK, 0 rows affected (0.01 sec) 表示成功
mysql> exit
Mysql設置完畢
檢測apache + php + mysql
[root @tsai usr]# cd /www/htdocs
[root @tsai htdocs]# touch info.php
[root @tsai htdocs]# vi info.php
<?
phpinfo( );
?>
保存退出 :wq
[root @tsai htdocs]# touch mydqltest.html
[root @tsai htdocs]# vi mysqltest.html
<html>
<body>
<?
$link=mysql_connect('localhost','root');
mysql_select_db('mysql');
$str="select * from user;";
$result=mysql_query($str,$link);
$show=mysql_num_rows($result);
mysql_close($link);
for ($i=0;$i < $show;$i++)
{
$arr[$i]=mysql_fetch_array($result);
};
?>
<table align=center border=1>
<tr align=center>
<td>Host</td>
<td>User</td>
<td>Password</td>
</tr>
<?for ($i=0;$i<$show;$i++){?>
<tr>
<td><?echo $arr[$i][Host]?></td>
<td><?echo $arr[$i][User]?></td>
<td><?echo $arr[$i][Password]?></td>
</tr>
<?};?>
</body>
</html>
保存退出 :wq
重啟mysql + apache 服務
[root @localhost htdocs]# service mydql restart
[root @localhost htdocs]# service httpd restart
進入瀏覽器檢查
http://192.168.1.254/info.php 和 http://192.168.1.254/mysqltest.html
安裝rrdtool
[root@localhost usr]# tar zxvf rrdtool-1.0.50.tar.gz
[root@localhost usr]# cd rrdtool-1.0.50
[root@localhost rrdtool-1.0.50]# ./configure
[root@localhost rrdtool-1.0.50]# make && make install
我的是fedora 7,用下面的方法。
[root@localhost usr] yum install rrdtool
Rrdtool安裝完畢
安裝net-snmp、snmpwalk和snmpget命令
[root@localhost usr]# rpm -qa | grep net-snmp
net-snmp-5.0.9-2.30E.15
net-snmp-devel-5.0.9-2.30E.15
net-snmp-libs-5.0.9-2.30E.15
net-snmp-utils-5.0.9-2.30E.15
[root@localhost usr]# vi /etc/snmp/snmpd.conf
更改 1、com2sec notConfigUser default public
改為:com2sec notConfigUser 127.0.0.1 public
2、access notConfigGroup "" any noauth exact systemview none none
改為:access notConfigGroup "" any noauth exact all none none
3、#view all included .1 80
將前面的 # 注釋 去掉。
保存退出 :wq
[root@localhost usr]# service snmpd restart
使用yum安裝更方便:
[root@localhost usr]# yum install net-snmp
[root@localhost usr]# yum update net-snmp
配置還是使用上面的方法修改。
或者使用:net-snmp-5.1.4.tar.gz安裝
[root@localhost local]# tar -zxvf net-snmp-5.1.4.tar.gz
[root@localhost local]# cd net-snmp-5.1.4
[root@localhost local]# ./configure
[root@localhost local]# make
[root@localhost local]# make install
運行snmpconf -g basic_setup,會在當前目錄下生成一個snmpd.conf配置文件:
[root@localhost local]# snmpconf -g basic_setup
運行後會出現一個詢問菜單,按如下步驟進行回答:CODE:[Copy to clipboard]Do you want to configure the information returned in
the system MIB group (contact info, etc)? (default = y): y
The location of the system: Shenzhen, China
The contact information: [email protected]
Do you want to properly set the value of the sysServices.0 OID (if you don't know, just say no)? (default = y): y
does this host offer physical services (eg, like a repeater) [answer 0 or 1]: 1
does this host offer datalink/subnetwork services (eg, like a bridge): 0
does this host offer internet services (eg, supports IP): 1
does this host offer end-to-end services (eg, supports TCP): 1
does this host offer application services (eg, supports SMTP): 1
Do you want to configure the agent's access control? (default = y): y
Do you want to allow SNMPv3 read-write user based access (default = y): n
Do you want to allow SNMPv3 read-only user based access (default = y): n
Do you want to allow SNMPv1/v2c read-write community access (default = y): n
Do you want to allow SNMPv1/v2c read-only community access (default = y): y
The community name to add read-only access for: public
The hostname or network address to accept this community name from [RETURN for all]: (RETURN)
The OID that this community should be restricted to [RETURN for no-restriction]: (RETURN)
Do you want to configure where and if the agent will send traps? (default = y): n
Do you want to configure the agent's ability to monitor various aspects of your system? (default = y): y
Do you want to configure the agents ability to monitor processes? (default = y): y
Name of the process you want to check on: sshd(需要監控的進程)
Maximum number of processes named ' sshd' that should be running [default = 0]: 1
Minimum number of processes named ' sshd' that should be running [default = 0]: 0
Do another proc line? (default = y): n
Do you want to configure the agents ability to monitor disk space? (default = y): y
Enter the mount point for the disk partion to be checked on: /
Enter the minimum amount of space that should be available on /var: %100
Do another disk line? (default = y): y
Enter the mount point for the disk partion to be checked on: /var
Enter the minimum amount of space that should be available on /var: %100
Do another disk line? (default = y): y
Enter the mount point for the disk partion to be checked on: /usr
Enter the minimum amount of space that should be available on /usr: %100
Do another disk line? (default = y): y
Enter the mount point for the disk partion to be checked on: /home
Enter the minimum amount of space that should be available on /home: %100
Do another disk line? (default = y): n
Do you want to configure the agents ability to monitor load average? (default = y): y
Enter the maximum allowable value for the 1 minute load average: 12
Enter the maximum allowable value for the 5 minute load average: 12
Enter the maximum allowable value for the 15 minute load average: 12
Do another load line? (default = y): n
Do you want to configure the agents ability to monitor file sizes? (default = y): n(如果想監控文件的大小,可以選y)
4.運行net-snmp:
# snmpd -c /path/snmpd.conf (要上面生成的絕對路徑)
測試一下看看net-snmp是否配置成功:
#snmpwalk -v 1 -c public localhost .1 (是否可以從.1開始採集伺服器數據)
#snmpwalk -v 1 -c public localhost dskPercent.1 (看看剛配置過的硬碟監測是否成功)
如果有數據了,恭喜你snmp安裝成功了。
註:如果你機器內沒有snmpwalk和snmpge命令,請到安裝盤里查找 net-snmp-utils 包,rpm -ivh net-snmp-utils-*.rpm 只後這兩個命令就
在系統里了。其他包也都在安裝盤里 確保安裝這四個包就OK
安裝/ 配置cacti
[root@localhost usr]# useradd cactiuser -g users
[root@localhost usr]# passwd cactiuser (pwd:cactipw)
[root@localhost usr]# cp cacti-0.8.7.tar.gz /var/www/html
[root@localhost usr]# cd /var/www/html
[root@localhost html]# tar -zxvf cacti-0.8.7.tar.gz
[root@localhost html]# mv cacti-0.8.6g cacti
[root@localhost html]# cd cacti
[root@localhost cacti]# /usr/local/mysql/bin/mysql -u root -p cactidb < cacti.sql
passwork:
[root@localhost cacti]# chown -R cactiuser rra/ log/
[root@localhost cacti]# cd scripts
[root@localhost scripts]# chown cactiuser:users *
[root@localhost scripts]# vi /www/htdocs/cacti/include/config.php
$database_type = 「mysql」;
$database_default = 「cactidb」;
$database_hostname = 「localhost」;
$database_username = 「cactiuser」;
$database_password = 「cactipw」;
更改用戶、密碼 等項 與上面給出的對應 保存退出
[root@localhost scripts]# crontab -u cactiuser -e
加入
*/5 * * * * /usr/local/php/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1
保存退出:wq
全部設置完畢。
打開瀏覽器 http://192.168.1.254/cacti 進入cacti的初始設置頁面
第一次默認登陸賬號:admin 密碼 admin
登陸後在新改個密碼就OK
需要說明的還有路徑
snmpwalk Binary Path : /usr/bin/snmpwalk
snmpget Binary Path: /usr/bin/snmpget
RRDTool Binary Path: /usr/bin/rrdtool
PHP Binary Path: /usr/local/php/bin/php
Cacti Log File Path: /var/www/html/cacti/log/cacti.log
Cactid Poller File Path:/var/www/html/cacti/poller.php
如果你是按我的步驟做的 那上面的路徑一定不會錯。
註:此時graphs還不能顯示圖形,需要將服務重新啟動一下
[root@localhost scripts]# service snmpd restart
[root@localhost scripts]# service mysql restart
[root@localhost scripts]# service httpd restart
❼ 用cacti怎樣對網路進行監控
cacti監控網路的流量,使用SNMP協議,只要設備支持SNMP協議,都可以進行監控
❽ Linux系統下cacti監控腳本是存放在哪個位置
監控腳本?有這個東西嗎?他是通過rrtool進行圖形監控的,在rra文件下是你監控伺服器的項目文件