zabbix升級 mysql優化

./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2


apt-get install libmysqlclient-dev


--aptitude search snmp | grep dev


apt-get install  libxml2 libxml2-dev


apt-get install libsnmp-dev


apt-get install libcurl4-gnutls-dev


fuser -k 80/tcp



mysql -u zabbix -p zabbix < /usr/local/zabbix-3.2.0alpha1/database/mysql/schema.sql

mysql -u zabbix -p zabbix < /usr/local/zabbix-3.2.0alpha1/database/mysql/images.sql

mysql -u zabbix -p zabbix < /usr/local/zabbix-3.2.0alpha1/database/mysql/data.sql


apt-get dist-upgrade -u


--default-character-set=UTF8


*************************************************************************************************************************


wget http://repo.zabbix.com/zabbix/3.0/debian/pool/main/z/zabbix/zabbix-server-mysql_3.0.4-1+wheezy_amd64.deb


dpkg -i zabbix-server-mysql_3.0.4-1+wheezy_amd64.deb


apt-get update



apt-get install zabbix-server-mysql zabbix-frontend-php

********************************************************************************************************************************************************************


統計數據庫大小 

SELECT table_schema , sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB"  FROM information_schema.TABLES GROUP BY table_schema;


統計表大小並排序 

SELECT table_name AS "Tables",

round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"

FROM information_schema.TABLES

WHERE table_schema = 'zabbix'

ORDER BY (data_length + index_length) DESC;



use zabbix;

truncate table history;

optimize  table history;

truncate table history_str;

truncate table history_uint;


**********************************************************************

#!/bin/bash


# Author: ZhiPeng Wang.

# Last Modified: 2014/6/2


User="root"

Passwd="wangzhipeng"

Date=`date -d $(date -d "-30 day" +%Y%m%d) +%s` #取30天之前的時間戳


$(which mysql) -u${User} -p${Passwd} -e "

use zabbix;

DELETE FROM history WHERE 'clock' < $Date;

optimize table history;

DELETE FROM history_str WHERE 'clock' < $Date;

optimize table history_str;

DELETE FROM history_uint WHERE 'clock' < $Date;

optimize table history_uint;

DELETE FROM  trends WHERE 'clock' < $Date;

optimize table  trends;

DELETE FROM trends_uint WHERE 'clock' < $Date;

optimize table trends_uint;

DELETE FROM events WHERE 'clock' < $Date;

optimize table events;



該參數定義了數據緩衝區buffer pool大小,類似於oracle的db_cache_size

mysql> show global variables like 'innodb_buffer_pool_size';
+-------------------------+-----------+
| Variable_name           | Value     |
+-------------------------+-----------+
| innodb_buffer_pool_size | 134217728 |
+-------------------------+-----------+
1 row in set (0.00 sec)

那麼如何設置該參數大小呢?首先查看運行時buffer pool相關數據指標:

mysql> show global status like 'Innodb_buffer_pool_pages_data';
+-------------------------------+-------+
| Variable_name                 | Value |
+-------------------------------+-------+
| Innodb_buffer_pool_pages_data | 314   |
+-------------------------------+-------+
1 row in set (0.00 sec)

mysql> show global status like 'Innodb_buffer_pool_pages_total';
+--------------------------------+-------+
| Variable_name                  | Value |
+--------------------------------+-------+
| Innodb_buffer_pool_pages_total | 8191  |
+--------------------------------+-------+
1 row in set (0.00 sec)

mysql> show global status like 'Innodb_page_size';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| Innodb_page_size | 16384 |
+------------------+-------+
1 row in set (0.00 sec)

上述三項指標的含義如下:

Innodb_buffer_pool_pages_data
The number of pages in the InnoDB buffer pool containing data. The number includes both dirty and
clean pages.

Innodb_buffer_pool_pages_total
The total size of the InnoDB buffer pool, in pages.

Innodb_page_size
InnoDB page size (default 16KB). Many values are counted in pages; the page size enables them to be
easily converted to bytes

計算Innodb_buffer_pool_pages_data/Innodb_buffer_pool_pages_total*100%
當結果 > 95% 則增加 innodb_buffer_pool_size, 建議使用物理內存的 75%
當結果 < 95% 則減少 innodb_buffer_pool_size, 
建議設置大小爲: Innodb_buffer_pool_pages_data* Innodb_page_size * 1.05 / (1024*1024*1024)



Linux下面 my.cnf

innodb_buffer_pool_size = 10240M



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章