日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

cacti及其相关插件的安装

發布時間:2023/12/9 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cacti及其相关插件的安装 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

cacti是什么?

1. cacti是用php語言實現的一個軟件,它的主要功能是用snmp服務獲取數據,然后用rrdtool儲存和更新數據,當用戶需要查看數據的時候用rrdtool生成圖表呈現給用戶。因此,snmprrdtoolcacti的關鍵。Snmp關系著數據的收集,rrdtool關系著數據存儲和圖表的生成。


2. Mysql配合PHP程序存儲一些變量數據并對變量數據進行調用,如:主機名、主機ipsnmp團體名、端口號、模板信息等變量。


3. snmp抓到數據不是存儲在mysql中,而是存在rrdtool生成的rrd文件中(在cacti根目錄的rra文件夾下)。rrdtool對數據的更新和存儲就是對rrd文件的處理,rrd文件是大小固定的檔案文件(Round Robin Archive),它能夠存儲的數據筆數在創建時就已經定義。


cacti的工作流程可以用下圖表示:


cacti的安裝:

配置本地yum

[root@cacti ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo

[rhel-Server]

name=Red Hat Enterprise Linux Server

baseurl=file:///mnt/cdrom/Server

enabled=1

gpgcheck=1

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release



[root@cacti ~]# mkdir /mnt/cdrom

[root@cacti ~]# mount /dev/cdrom/mnt/cdrom/

mount: block device /dev/cdrom iswrite-protected, mounting read-only


[root@cacti ~]# yum install httpd php php-mysql php-snmp mysql-serverperl-DBD-MySQL php-pdo net-snmp net-snmp-libs net-snmp-utils net-snmp-develruby –y


[root@cacti ~]# service httpd start

[root@cacti ~]# chkconfig httpd on


[root@cacti ~]# service mysqld start

[root@cacti ~]# chkconfig mysqld on


[root@cacti ~]# mysqladmin -u root -ppassword '123'


[root@cacti ~]# mysql -u root –p

mysql> CREATE DATABASE cacti;

mysql> grant all privileges on cacti.* to cacti@localhostidentified by 'cacti';

mysql> grant all privileges on cacti.* to cacti@127.0.0.1identified by 'cacti';

mysql> grant all privileges on cacti.* tocacti@192.168.2.0 identified by 'cacti';

mysql> flush privileges;

mysql> quit


上傳需要用的軟件

軟件資料下載地址http://down.51cto.com/data/994246

cacti-0.8.7g.tar.gz cacti的主程序

cacti-plugin-0.8.7g-PA-v2.8.tar.gz 插件管理器

feition.tar.bz2 用于飛信報警的程序

monitor-latest.tgz 實現只管監測的插件

sendMsg.zip 發送MSN消息的應用

settings-latest.tgz 增強功能的插件,例如發送電子郵件

thold-latest.tgz 實現達到預值告警的插件



[root@cacti software]# yum localinstallrrdtool* --nogpgcheck –y


安裝cacti的主程序

[root@cacti software]# tar -zxvf cacti-0.8.7g.tar.gz -C /var/www/html/

[root@cacti software]# cd /var/www/html/

[root@cacti html]# mv cacti-0.8.7g/ cacti


[root@cacti html]# service snmpd start

[root@cacti html]# chkconfig snmpd on

[root@cacti html]# vim /etc/snmp/snmpd.conf

添加一行view systemview included .1.3.6.1.2.1.25.1.6 /使能監控tcp流量



編輯計劃任務

[root@cacti html]# crontab -e

*/5 * * * * php/var/www/html/cacti/poller.php >/dev/null 2>&1


導入數據庫

[root@cacti html]# mysql -u root -p cacti</var/www/html/cacti/cacti.sql

輸入mysql管理員口令


編輯cacti連接數據庫的文件

[root@cacti html]# vim cacti/include/config.php

29 $database_username = "cacti";

30 $database_password = "cacti";


新建一個用戶cacti,口令也為cacti

[root@cacti html]# useradd cacti

[root@cacti html]# passwd cacti


[root@cacti html]# cd cacti/

[root@cacti cacti]# chown -R cacti rra log


此時就可以通過頁面登錄cacti了,用戶和口令都為admin



實現對apache的監控

[root@cacti software]# cd ApacheStats_0.8.2/

[root@cacti ApacheStats_0.8.2]#ll

total 116

-rw-r--r-- 1 root root 102879 Oct 27 18:51 cacti_host_template_webserver_-_apache.xml

-rw-r--r-- 1 root root 4108 Oct 27 18:51 ss_apache_stats.php

[root@cacti ApacheStats_0.8.2]#cp ss_apache_stats.php /var/www/html/cacti/scripts/

[root@cacti ApacheStats_0.8.2]#chown 1000:users /var/www/html/cacti/scripts/ss_apache_stats.php


cacti_host_template_webserver_-_apache.xml 為下面要導入的模版文件



通過控制臺導入模版

修改apache的配置文件

[root@cacti ApacheStats_0.8.2]#cd

[root@cacti ~]# vim/etc/httpd/conf/httpd.conf


217 ExtendedStatus On /打開這一行


903 #<Location /server-status>

904 # SetHandler server-status

905 # Order deny,allow

906 # Deny from all

907 # Allow from .example.com

908 #</Location>

909 <Location /server-status>

910 SetHandler server-status

911 Order deny,allow

912 Deny from all

913 Allow from all

914 </Location>

apache重啟

[root@cacti ~]# service httpd restart


在安裝插件之前要先安裝插件管理器

[root@cacti cacti]# cd /root/software/

[root@cacti software]# tar -zxvf cacti-plugin-0.8.7g-PA-v2.8.tar.gz

[root@cacti software]# cp -R cacti-plugin-arch/* /var/www/html/cacti/

[root@cacti software]# cd /var/www/html/cacti/

[root@cacti cacti]# mysql -u root -pcacti<pa.sql

[root@cacti cacti]# patch -p1 -N<cacti-plugin-0.8.7g-PA-v2.8.diff

[root@cacti cacti]# vim include/config.php

42 $url_path = "/cacti/"; /修改這一行的路徑



安裝插件

[root@cacti cacti]# cd /root/software/

[root@cacti software]# tar -zxvf monitor-latest.tgz

[root@cacti software]# tar -zxvf settings-latest.tgz

[root@cacti software]# tar -zxvf thold-latest.tgz

[root@cacti software]# mv monitor-0.9/ /var/www/html/cacti/plugins/monitor

[root@cacti software]# mv settings-0.6/ /var/www/html/cacti/plugins/settings

[root@cacti software]# mv thold-0.41/ /var/www/html/cacti/plugins/thold


在控制臺啟用插件


配置支持發送msn消息

[root@cacti software]# unzip sendMsg.zip

[root@cacti software]# mv sendMsg/ var/www/html/


[root@cacti software]# vim /var/www/html/cacti/plugins/thold/thold_functions.php

添加下面這兩行

560 exec("echo $subject>>/var/www/html/cacti/plugins/thold/alert.log");

561 exec("sh /var/www/html/cacti/plugins/thold/sendmessage.sh");


編寫個sendmessage.sh腳本,在/var/www/html/cacti/plugins/thold/這個目錄下(實現自動發送)

[root@cacti software]# vim /var/www/html/cacti/plugins/thold/sendmessage.sh

腳本內容


#!/bin/sh

echo `echo -n"date:"&&date +%Y-%m-%d-%H:%M` >>/var/www/html/sendMsg/msn.txt.1

cat /var/www/html/cacti/plugins/thold/alert.log>>/var/www/html/sendMsg/msn.txt.1

now=`date +%Y-%m-%d-%H:%M`

SA=(test)

msnaddr=(接收信息的帳號)

sendMsg()

{

num=0

while [ $num -lt 1 ];

do

wget ?post-data"sender=發送信息的帳號&password=密碼&recipient=${1}&message=${2}"http://127.0.0.1/sendMsg/index.php -O /var/www/html/sendMsg/index.php.1>/dev/null 2>&1

if [ -f /var/www/html/sendMsg/index.php.1]; then

if cat /var/www/html/sendMsg/index.php.1|grep -i successfully >/dev/null 2>&1;then

num=1

elif cat /var/www/html/sendMsg/index.php.1|grep -i "The user appears to be offline" >/dev/null2>&1;then

num=1

echo "The user is offline."

exit 0

elif cat /var/www/html/sendMsg/index.php.1 |grep-i "Something went wrong trying to connect to the server">/dev/null 2>&1;then

num=1

echo "MSN server is online."

exit 0

else

num=0

fi

rm -f /var/www/html/sendMsg/index.php.1

else

num=0

fi

done

}

mv /var/www/html/sendMsg/msn.txt/var/www/html/sendMsg/bak/msn$now.txt -f 1>/dev/null 2>&1

mv /var/www/html/sendMsg/msn.txt.1/var/www/html/sendMsg/msn.txt -f 1>/dev/null 2>&1

rm /var/www/html/cacti/plugins/thold/alert.log -f 1>/dev/null 2>&1

for i in 0

do

if cat /var/www/html/sendMsg/msn.txt ; then

messages=`cat /var/www/html/sendMsg/msn.txt`

sendMsg "${msnaddr[$i]}""$messages"

else

continue

fi

done



配置支持飛信報警

[root@cacti software]# tar -jxvf feition.tar.bz2

[root@cacti software]# mkdir -pv /var/www/html/sendsms/linuxso

[root@cacti software]# cp linuxso_20101113/* /lib/

[root@cacti software]# mv linuxso_20101113/* /var/www/html/sendsms/linuxso/

[root@cacti software]# vim /var/www/html/cacti/plugins/thold/thold_functions.php

添加這兩行

562 exec("echo $subject>>/var/www/html/cacti/plugins/thold/alert.log");

563 exec("/var/www/html/cacti/plugins/thold/sendsms.sh");


[root@cacti software]# vim /var/www/html/cacti/plugins/thold/sendsms.sh

#!/bin/sh

#send sms by fetion

#Write by pingsun2010@hotmail.com

if [ ! -e"/var/www/html/cacti/plugins/thold/alert.log" ];then

echo "Usage:alert.log does notexist"

exit

fi

if [ -n "`cat/var/www/html/cacti/plugins/thold/alert.log`" ]; then

admin="接收信息的帳號?

echo "sms $admin "`cat /var/www/html/cacti/plugins/thold/alert.log`>>/var/www/html/cacti/plugins/thold/sms.txt

echo "exit" >>/var/www/html/cacti/plugins/thold/sms.txt

else

echo "Usage:no alert"

exit

fi

if [ -n "`cat/var/www/html/cacti/plugins/thold/sms.txt`" ] ;then LD_LIBRARY_PATH=/var/www/html/sendsms/linuxso/var/www/html/sendsms/linuxso/fetion --mobile=發送信息的賬戶 --pwd=密碼 --to=$admin --file-utf8=/var/www/html/cacti/plugins/thold/sms.txt

rm -f /var/www/html/cacti/plugins/thold/sms.txt 1>/dev/null 2>&1

rm -f /var/www/html/cacti/plugins/thold/alert.log 1>/dev/null 2>&1

else

echo "Usgae:no message to send"

exit

fi


[root@cacti thold]# chmod a+x send*

給新建的腳本添加可執行權限


vim /var/www/html/cacti/plugins/thold/alert.log

隨便寫點兒內容,當飛信程序執行的時候會自動刪除里面的內容

可以新建alert.log以及sms.txt,其中在alert.log中添加一個內容。然后手工運行腳本進行測試,需要保證本機能正常接入互聯網。


目前cacti的環境已經搭建完成,cacti的使用還需要好好學習……

轉載于:https://blog.51cto.com/pjp5945/1317410

總結

以上是生活随笔為你收集整理的cacti及其相关插件的安装的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。