cacti 監控 mysql
環境:
Cactiez或者cacti主機:192.168.12.5
被監控mysql數據庫主機:192.168.5.231
1. 安裝監控插件
cd /opt
wget http://mysql-cacti-templates.googlecode.com/files/mysql-cacti-templates-1.1.6.tar.gz
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