Zabbix 3.0 監控MySQL

來源:互聯網
上載者:User

標籤:監控   zabbix   mysql   

Mysql監控 
  zabbix內建了一個監控mysql的模板,但是真正監控mysql的並不是zabbix內建的模板。而是percona公司的一個監控mysql模板 
 percona官網: www.percona.com

Percona組成介紹

1、php指令碼    用來資料擷取2、shell指令碼  用來調用採集資訊3、zabbix設定檔4、zabbix模板檔案

安裝文檔:https://www.percona.com/doc/percona-monitoring-plugins/LATEST/zabbix/index.html 
  percona 利用的是php來擷取mysql的相關資訊,所以如果我們想使用percona外掛程式監控mysql就需要在agent端安裝php。在安裝文檔上有寫哦~ 
650) this.width=650;" src="http://static.zybuluo.com/abcdocker/r6pp7vo0np74knqr71uf9iww/1.png" alt="1.png-135.5kB" style="border:0px;font-family:inherit;font-style:inherit;margin:0px;padding:0px;vertical-align:middle;height:auto;" />

安裝步驟: 查看上面的連結也可以進行安裝 
我們安裝在zabbix-server上,因為上面有一個MySQL

[[email protected] web]# yum install [[email protected] web]# yum install percona-zabbix-templates php php-mysql -y#percona外掛程式是通過php去擷取mysql的參數,所以我們要安裝php和php-mysql我們可以查看它都安裝了那些軟體[[email protected] web]# rpm -ql percona-zabbix-templates    /var/lib/zabbix/percona    /var/lib/zabbix/percona/scripts    var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh  #shell指令碼    /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php      #php擷取mysql資訊    /var/lib/zabbix/percona/templates    /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf #zabbix設定檔    /var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6.xml  #zabbix模板檔案在percona組成我們已經說過了,此處只是略微介紹。

我們將zabbix模板下載下來

[[email protected] web]# sz /var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6.xml

  然後我們需要將模板通過web介面匯入到zabbix中 
650) this.width=650;" src="http://static.zybuluo.com/abcdocker/i6hykczdfwx54sl0ronn0j8g/2.png" alt="2.png-310.6kB" style="border:0px;font-family:inherit;font-style:inherit;margin:0px;padding:0px;vertical-align:middle;height:auto;" />
650) this.width=650;" src="http://static.zybuluo.com/abcdocker/2smjc5pi86jhgs14sh3m0i87/2.png" alt="2.png-90kB" style="border:0px;font-family:inherit;font-style:inherit;margin:0px;padding:0px;vertical-align:middle;height:auto;" />
提示:如果出現錯誤,可能是zabbix 3.0版本的問題。我們這裡提供了一個生產的模板 
下載連結:http://pan.baidu.com/s/1pLjKvxh 密碼:75g0 
然後從新上傳即可

複製設定檔

[[email protected] web]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/[[email protected] web]# ls /etc/zabbix/zabbix_agentd.d/#安裝完軟體包後會在/var/lib/zabbix/percona/templates/目錄下產生一個設定檔,我們將它拷貝,因為在前面的博文中,我們已經修改過zabbix的設定檔[Include=/etc/abbix/zabbix_agentd.d/] 所以將設定檔放在這個目錄下,zabbix就會自己在這個目錄下尋找相關資訊[[email protected] web]# systemctl restart zabbix-agent.service    重啟一下!

下面就應該配置與MySQL的串連 
/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf建立一個檔案

[[email protected] ~]# cat /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf<?php$mysql_user = ‘root‘;$mysql_pass = ‘‘;#使用者名稱密碼可以自己建立,有密碼寫密碼,沒密碼為空白就好了

提示: 正常這裡的使用者我們應該建立一個專門用來監控的,由於我這裡是測試環境。就不浪費時間了

測試

查看是否可以擷取到值,隨便找一個測試

[[email protected] ~]# cat /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf     選擇一個肯定有值的key[[email protected] ~]# cat /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf|grep gmUserParameter=MySQL.read-views,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gm測試結果如下:[[email protected] ~]# cd /var/lib/zabbix/percona/scripts/[[email protected] scripts]# ./get_mysql_stats_wrapper.sh gm1[[email protected] scripts]# ./get_mysql_stats_wrapper.sh gw9736342可以擷取到值,說明沒有問題

溫馨提示: shell指令碼中資料庫的路徑是localhost,如果我們沒有授權localhost會擷取不到值

[[email protected] scripts]# cat get_mysql_stats_wrapper.sh HOST=localhost        RES=`HOME=~zabbix mysql -e ‘SHOW SLAVE STATUS\G‘ | egrep ‘(Slave_IO_Running|Slave_SQL_Running):‘ | awk -F: ‘{print $2}‘ | tr ‘\n‘ ‘,‘`    #mysql是通過命令來擷取的,如果環境變數不一樣 也可能造成影響

Zabbix_Web介面配置 
  模板已經上傳到zabbix中,這時候我們就需要進行設定了 
650) this.width=650;" src="http://static.zybuluo.com/abcdocker/ym7z1qqf1cgdhpio5cf71677/1.png" alt="1.png-155.4kB" style="border:0px;font-family:inherit;font-style:inherit;margin:0px;padding:0px;vertical-align:middle;height:auto;" />
650) this.width=650;" src="http://static.zybuluo.com/abcdocker/zcnqi1p9rjw1bdz0mfqvqgau/2.png" alt="2.png-106.9kB" style="border:0px;font-family:inherit;font-style:inherit;margin:0px;padding:0px;vertical-align:middle;height:auto;" />
提示: 我們還需要授權/tmp下的一個檔案,因為預設情況下 zabbix在檔案中擷取的值 
650) this.width=650;" src="http://static.zybuluo.com/abcdocker/nts92qoge4turbbq6w8ecrzn/3.png" alt="3.png-60.7kB" style="border:0px;font-family:inherit;font-style:inherit;margin:0px;padding:0px;vertical-align:middle;height:auto;" />
修改完就可以擷取值了,所以我們還需要測試 
650) this.width=650;" src="http://static.zybuluo.com/abcdocker/t0lns42e53pbmxyrzu3bczbc/4.png" alt="4.png-131.9kB" style="border:0px;font-family:inherit;font-style:inherit;margin:0px;padding:0px;vertical-align:middle;height:auto;" />

結果如 
650) this.width=650;" src="http://static.zybuluo.com/abcdocker/1278tv0fy21ahcj1m7q29las/5.png" alt="5.png-202.5kB" style="border:0px;font-family:inherit;font-style:inherit;margin:0px;padding:0px;vertical-align:middle;height:auto;" />
思想: 
  如果出現錯誤我們需要先查看shell的指令碼,因為shell是去調用php。 錯誤的因素有很多,最簡單的方法就是用shell 後面加上key 看看是否可以有值。 
  其中報錯最多的地方就是php和mysql串連的問題,還有我們mysql授權的一些問題


本文出自 “小菜鳥” 部落格,請務必保留此出處http://baishuchao.blog.51cto.com/12918589/1958378

Zabbix 3.0 監控MySQL

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.