Cacti如何監(jiān)控Mysql
cacti監(jiān)控mysql數(shù)據(jù)庫的方法
環(huán)境:
Cactiez或者cacti主機:192.168.12.5
被監(jiān)控mysql數(shù)據(jù)庫主機:192.168.5.231
1. 安裝監(jiān)控插件
- 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/
其實里面我們要監(jiān)控mysql用到的是:acti_host_template_x_db_server_ht_0.8.6i.xml和mysql_definitions.pl
其他則是監(jiān)控Apache和Nginx的,接下來我們會介紹到,這里不再詳細(xì)的講了。
- chown -R apache.apache /var/www/html/scripts
- chmod -R 755 /var/www/html/scripts
使用 http 訪問 cacti主機 導(dǎo)入
- /opt/mysql-cacti-templates-1.1.2/cacti_host_template_x_db_server_ht_0.8.6i.xml
- http://192.168.12.5
默認(rèn)CactiEZ 和Cacti別是 admin admin
控制臺 - 導(dǎo)入導(dǎo)出 - 模板導(dǎo)入 - 瀏覽
選中 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/";
這個賬戶和密碼是 被監(jiān)控端主機 給 Cacti主機 授權(quán)的 賬戶和密碼
Cacti需要這個賬戶和密碼去連接 被監(jiān)控機 查詢狀態(tài)
- mkdir -p /tmp/cacti/cache
- chown -R apache.apache /tmp/cacti
- chmod -R 755 /tmp/cacti
設(shè)置 cacti 緩存目錄在 /tmp/cacti/cache/ 并給予權(quán)限
3. 配置被監(jiān)控端(192.168.5.231)的mysql 給 cacti 主機授權(quán)
- 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 去訪問 本機數(shù)據(jù)
4. 在Cacti主機上(192.168.12.5) 監(jiān)控Mysql
4.1 為主機添加mysql模塊
控制臺 - 管理 - 設(shè)備 - 選中之前創(chuàng)建好的主機
然后移到最下面的 添加圖形模版 選中 Mysql相關(guān)模塊 然后保存
4.2 為mysql模塊創(chuàng)建圖形
控制臺 - 創(chuàng)建 - 創(chuàng)建圖形 - 選中該主機 - 選中mysql模塊 - 創(chuàng)建
4.3 插件mysql性能數(shù)據(jù)
監(jiān)視器 - 選中該主機 - 查閱對應(yīng)的mysql
完畢
-----一些數(shù)據(jù)庫操作語句
- 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的權(quán)限
- 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
【編輯推薦】
MRTG、Cacti、Rrdtool、Nagios、Zabbix大比拼