---
title: "cacti-0.8.7i使用percona-monitoring-plugins监控mysql等"
author: "willvvv"
date: "2012-03-14T16:36:33Z"
tags: ["Linux", "MySQL", "SSH", "cacti", "keygen"]
categories: ["操作系统"]
slug: "cacti-0-8-7i-percona-monitoring-plugins-mysql"
draft: false
lastmod: "2012-06-01T18:40:05Z"
id: 1453566
url: "https://willvvv.iteye.com/blog/1453566"
---

注意文中RemoteServerIP，cactiserverIP，remoteIP等替换为自己的IP

 

1.MySQL主机添加监控账号，建议所有被监控MySQL服务的主机设置统一的账号和密码  
1.1   使用root登录到mysq的命令行  
1.2   GRANT SUPER, PROCESS ON \*.* TO 'cactiuser'@'cactiserverIP' IDENTIFIED BY "cactipassword";

1.3   flush privileges;  
1.4   在cacti服务器上测试账号，mysql -h RemoteServerIP -e "SELECT VERSION()" -u cactiuser -pcactipassword       
       
2.ssh远程自动登录配置  
2.1   在cacti服务器上生成ssh的key  
      \[root@cactiserver ~]# mkdir /etc/cactiuser  
      \[root@cactiserver ~]# ssh-keygen

```
      Generating public/private rsa key pair.
      Enter file in which to save the key (/root/.ssh/id_rsa): /etc/cactiuser/id_rsa
      Enter passphrase (empty for no passphrase):
      Enter same passphrase again:
      Your identification has been saved in /etc/cactiuser/id_rsa.
      Your public key has been saved in /etc/cactiuser/id_rsa.pub.
      The key fingerprint is:
      7c:34:8d:33:a0:1c:a0:43:cd:89:41:5e:81:66:2e:84 root@cactiserver.localdomain
```

 

      \[root@cactiserver ~]# cd /etc/cactiuser/  
      \[root@cactiserver cactiuser]# ls  
      id\_rsa  id\_rsa.pub  
      \[root@cactiserver cactiuser]# chown -R cactiuser id\_rsa  
      \[root@cactiserver cactiuser]# chown -R cactiuser id\_rsa.pub  
      \[root@cactiserver cactiuser]# chown -R cactiuser:cactiuser id\_rsa.pub  
      \[root@cactiserver cactiuser]# chown -R cactiuser:cactiuser id\_rsa  
      \[root@cactiserver cactiuser]# chmod -R 0400 /etc/cactiuser/id\_rsa  
       
2.2   在被监控的主机上增加用户cactiuser  
      \[root@remoteServer ~]# cd /home  
      \[root@remoteServer home]# groupadd cactiuser  
      \[root@remoteServer home]# useradd cactiuser -g cactiuser  
      \[root@remoteServer home]# cd /home/cactiuser/  
      \[root@remoteServer cactiuser]# mkdir .ssh  
       
2.3   用SCP把cacti服务器上cactiuser的公共key复制到被监控的主机  
      \[root@remoteServer cactiuser]# scp id\_rsa.pub root@remoteIP:/home/cactiuser/.ssh/  
       
2.4   被监控主机配置

      \[root@remoteServer ~]# cd /home/cactiuser/.ssh/  
      \[root@remoteServer .ssh]# mv id\_rsa.pub authorized\_keys

      \[root@remoteServer .ssh]# cd /home/cactiuser

      \[root@remoteServer cactiuser]# chown -R cactiuser:cactiuser .ssh  
       
2.5   在cacti服务器上测试  
      ssh -i /etc/cactiuser/id\_rsa cactiuser@remoteIP echo "it works"  
       
3.配置文件修改

3.1   把percona-monitoring-plugins-0.9.0\\cacti\\scripts下ss\_get\_by\_ssh.php和ss\_get\_mysql\_stats.php复制到cacti的scripts文件夹下  
3.2   vi ss\_get\_by\_ssh.php  
      $ssh\_user   = 'cactiuser';                      # SSH username  
      $ssh\_port   = 22;                               # SSH port  
      $ssh\_iden   = '-i /etc/cactiuser/id\_rsa';       # SSH identity  
3.3   $mysql\_user = 'cactiuser';  
      $mysql\_pass = 'cactipassword';  
      $mysql\_port = 3306;  
3.4  测试 

```
 su -cactiuser -c 'php /usr/local/apache/htdocs/cacti/scripts/ss_get_by_ssh.php --type memory --host RemoteIP --items gu,gv'
gu:611717120 gv:841474048
```

 

 

 

4.导入模板，新建图像

 

5.图像截图

![](http://dl.iteye.com/upload/attachment/0064/8268/f9eb164e-d61b-323e-aba1-14f6b0922c00.png)

 

参考链接：

http://www.percona.com/doc/percona-monitoring-plugins/cacti/mysql-templates.html

http://www.percona.com/doc/percona-monitoring-plugins/cacti/ssh-based-templates.html