zabbix mysql优化 my.cnf_zabbix数据库优化之数据库优化(二)
zabbix数据库优化之数据库优化二
简介
数据库history设置是保存7天。然后如果你没有分区。虽然数据在减少但是表空间不会减少。浪费硬盘空间的同事缓存内的cache部分也没有被释放。分区后可以迁移分区合并分区删除已经没有数据的分区优化表空间优化buffer内存。
一,前期操作
清空表
Truncate table table_name;
导出库
mysqldump -uroot -p -all-databases >zabbix.sql
整理表空间碎片
Alter table tables_name engine=innodb;
二,迁移mysql
1调整升级mysql到5.7最新的存储过程需要
2调整mysql参数
检测你的参数是不是设置的合理
pt-variable-advisor --source-of-variables vars.vxt
三,分区操作
分区资料链接如下
核心部分
DELIMITER $$
CREATE PROCEDURE `partition_maintenance_all`(SCHEMA_NAME VARCHAR(32))
BEGIN
CALL partition_maintenance(SCHEMA_NAME, 'history', 20, 24, 20);
CALL partition_maintenance(SCHEMA_NAME, 'history_log', 20, 24, 20);
CALL partition_maintenance(SCHEMA_NAME, 'history_str', 20, 24, 20);
CALL partition_maintenance(SCHEMA_NAME, 'history_text', 20, 24, 20);
CALL partition_maintenance(SCHEMA_NAME, 'history_uint', 20, 24, 20);
CALL partition_maintenance(SCHEMA_NAME, 'trends', 20, 24, 20);
CALL partition_maintenance(SCHEMA_NAME, 'trends_uint', 20, 24, 20);
END$$
DELIMITER ;
创建分区的存储过程
CALL partition_maintenance(SCHEMA_NAME, 'history', 20, 24, 20);
保留天数20天
时间间隔24小时
创建分区数 例如 保留20天 创建分区数20
时间间隔1小时
创建分区数量 24*20
CALL partition_maintenance(SCHEMA_NAME, ;hisuozy', 20, 1, 22*24):
调用存储过程;创建分区;
call maintenance(‘zabbix’);
四,手动操作分区
手动清数据 清除7月30号前分区数据
call partition_drop('zabbix','history','201707300000');
call partition_drop('zabbix','history_log','201707300000');
call partition_drop('zabbix','history_str','201707300000');
call partition_drop('zabbix','history_text','201707300000');
call partition_drop('zabbix','history_uint','201707300000');
call partition_drop('zabbix','trends','201707300000');
call partition_drop('zabbix','trends_uint','201707300000');
五,注意事项
注意 partition_maintenance存储过程假如你设置的是保留20天 那么20天前的分区会被清除
清除实际调用的
call partition_drop('zabbix','history',201707110000’);
分组报错
注意:
5.7 group by需要。默认是不能select多col9`n6
set sql_mode=NO_ENGINE_SUBSTITUTION;
六,效果展示
七,附:
#########删除201708110000之前的所有数据。同时可以删除已经没有数据的分区
call partition_drop('zabbix','history','201708110000');
call partition_drop('zabbix','history_log','201708110000');
call partition_drop('zabbix','history_str','201708110000');
call partition_drop('zabbix','history_text','201708110000');
call partition_drop('zabbix','history_uint','201708110000');
call partition_drop('zabbix','trends','201708110000'); #建议保留
call partition_drop('zabbix','trends_uint','201708110000'); #建议保留
########## 创建分区
CALL partition_maintenance('zabbix', 'history', 5, 24, 10);
CALL partition_maintenance('zabbix', 'history_log', 5, 24, 10);
CALL partition_maintenance('zabbix', 'history_str', 5, 24, 10);
CALL partition_maintenance('zabbix', 'history_text', 5, 24, 10);
CALL partition_maintenance('zabbix', 'history_uint', 5, 24, 10);
CALL partition_maintenance('zabbix', 'trends', 5, 24, 10);
CALL partition_maintenance('zabbix', 'trends_uint', 5, 24, 10);
保留天数 5天 注意5天前将被删除
创浆蕬间间隔 24小时
创建分区数 10 分区不会自动创建所以可以创建多点一共保留15个分区
附件1
服务器配置24c 64g
[mysqld]
datadir=/database/
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
##数据更新时timestamp列自动更新
explicit_defaults_for_timestamp=1
innodb_file_per_table=on
skip_name_resolve=1
#事物提交刷新事物日志
innodb_flush_log_at_trx_commit=0
#Key_read_requests从缓存读取索引的请求次数。
#Key_reads从磁盘读取索引的请求次数。
#自适应hash索引
innodb_adaptive_hash_index=on
#开启临接页刷新 insert多开启。update多不开启
innodb_flush_neighbors=1
#异步io
innodb_use_native_aio=on
#更改时区设置避免system阻塞
#time_zone ='+8:00'
#InnoDB 用于写入磁盘上日志文件 的缓冲区大小innodb_page_size=32k或64k innodb_log_buffer_size至少16M
innodb_page_size=32k
innodb_log_buffer_size=64M
key_buffer_size=128M
##grup by分组必须加大
tmp_table_size=512M
max_heap_table_size=512M
#其扫描 每个线程为其扫描的每个 表分配一个大小以字节为单位的缓冲区
read_buffer_size=4M
#多范围读取优化缓存区大小。注意order by排序顺序读取表。每session
read_rnd_buffer_size=16M
#排序缓冲
sort_buffer_size=512M
max_connections=1024
#开启查询缓存
query_cache_type=1
query_cache_size=64M
innodb_write_io_threads = 24
innodb_read_io_threads = 24
innodb_page_cleaners=4
#设置change_buffer占buffer比例(insert update)
innodb_change_buffer_max_size=50
#预读当你连续读取设定的数量的page后会触发读取这个extent的剩余page。
innkdb_rcntom_read_ahead=on
#并发
innodb_thread_concurrency = 24
#缓存线程
thread_cache_size=500
max_connect_errors=3000
max_connections=3000
#自动递增锁模式
innodb_autoinc_lock_mode=2
#所有的change都缓冲
innodb_change_buffering=all
#缓冲池配置20个池每个1G
innodb_buffer_pool_chunk_size=1G
innodb_buffer_pool_instances=28
innodb_buffer_pool_size=28G
[mysqld_safe]
log-error=/database/error.log
pid-file=/database/mysqld.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
补充自动清除分区py:#!/usr/local/python-3.5.0/bin/python3.5
#-*- coding:utf-8 -*-
import pymysql,datetime
class db_action(object):
def __init__(self,host,port,user,password,database="mysql",charset="utf8"):
self.host=host
self.port=port
self.user=user
self.password=password
self.database=database
self.charset=charset
self.__cursor=self.__conn().cursor()
def __conn(self):
return pymysql.Connect(host=self.host,port=self.port,user=self.user,\
password=self.password,database=self.database,\
charset=self.charset)
def callproc(self,pl,t):
ret=self.__cursor.callproc(pl,args=t)
return ret
if __name__ == '__main__':
db=db_action(host='172.16.7.145',port=3306,user='root',password="zabbix",database="zabbix",charset='utf8')
rets=[]
ret=db.callproc('partition_drop',('zabbix','history',(datetime.datetime.now()+datetime.timedelta(days=-1)).strftime('%Y%m%d0000'),))
rets.append(ret)
ret=db.callproc('partition_drop',('zabbix','history_log',(datetime.datetime.now()+datetime.timedelta(days=-1)).strftime('%Y%m%d0000'),))
rets.append(ret)
ret=db.callproc('partition_drop',('zabbix','history_str',(datetime.datetime.now()+datetime.timedelta(days=-1)).strftime('%Y%m%d0000'),))
rets.append(ret)
ret=db.callproc('partition_drop',('zabbix','history_text',(datetime.datetime.now()+datetime.timedelta(days=-1)).strftime('%Y%m%d0000'),))
rets.append(ret)
ret=db.callproc('partition_drop',('zabbix','history_uint',(datetime.datetime.now()+datetime.timedelta(days=-1)).strftime('%Y%m%d0000'),))
rets.append(ret)
with open('/root/pariton_clear.log',encoding='utf-8',mode='a+') as f:
f.write(str(rets)+'\n')
contable00 10 * * * /usr/local/python-3.5.0/bin/python3.5 /etc/zabbix/shell/Partition_Clear.py
自动创建分区
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import pymysql,datetime,time
class DB_Action(object):
def __init__(self,host,port,user,password,database="mysql",charset="utf8"):
self.host=host
self.port=port
self.user=user
self.password=password
self.database=database
self.charset=charset
self.__conn=self.__connect()
self.__cursor=self.__conn.cursor()
def __connect(self):
return pymysql.Connect(host=self.host,port=self.port,user=self.user,\
password=self.password,database=self.database,\
charset=self.charset)
def callproc(self,partition_name,tuple_args):
'''存储过程'''
self.__cursor.callproc(partition_name,tuple_args)
self.__conn.commit()
def execute(self, tables_name):
'''sql'''
ret = self.__cursor.execute('select count(*) from PARTITIONS WHERE TABLE_NAME=%s and TABLE_ROWS=0',\
[tables_name])
return self.__cursor.fetchone()[0]
def __del__(self):
self.__cursor.close()
self.__conn.close()
if __name__ == '__main__':
datatables_list=['history','history_log','history_str','history_text','history_uint','trends','trends_uint']
par_conn=DB_Action(host='172.16.7.145',port=3306,user='root',password="zabbix",database="information_schema",charset='utf8')
par_count=par_conn.execute('history')
with open('/root/pariton_create.log', encoding='utf-8', mode='a+') as f:
f.write('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+str(time.strftime('%Y-%m-%d',time.localtime()))+'\n')
for tables in datatables_list:
f.write('{0}分区统计'.format(tables) + str(par_count)+'\n')
call_count=DB_Action(host='172.16.7.145',port=3306,user='root',password="zabbix",database="zabbix",charset='utf8')
if par_count<=10:
for tables in datatables_list:
call_count.callproc('partition_maintenance',('zabbix', tables, 365, 24, 90))
par_count=par_conn.execute('history')
with open('/root/pariton_create.log', encoding='utf-8', mode='a+') as f:
f.write('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+str(time.strftime('%Y-%m-%d',time.localtime()))+'\n')
for tables in datatables_list:
f.write('{0}分区统计'.format(tables) + str(par_count)+'\n')
补充zabbix server配置文件LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=1024
DebugLevel=3 #日志级别
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
StartPollers=100 #poller进程 100
StartPollersUnreachable=30 #无法访问的主机轮询进程30
StartPingers=30 #ping轮询数量
StartDiscoverers=30
StartTimers=10
SenderFrequency=30 #发送报警超时
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
CacheSize=4096M #存储主机,项目和触发器数据的共享内存
CacheUpdateFrequency=120 #执行配置缓存的更新频率
StartDBSyncers=24 #数据库同步进程
HistoryCacheSize=2048M
HistoryIndexCacheSize=2048M
TrendCacheSize=2048M #趋势数据最大2G
ValueCacheSize=2048M #缓存项历史数据请求,历史值缓存
Timeout=30
UnreachablePeriod=120 #几秒钟的不可达性将主机视为不可用。 不可用
UnavailableDelay=60 #主机在不可用期间内检查可用性的频率(秒)。 不可用
UnreachableDelay=5 #不可达检测频率 解决wait for 3 seconds
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=2000 #记录慢查询
HousekeepingFrequency=1 #从历史记录,警报和警报表中删除不必要的信息 不超过4个小时 每隔1小时启动一次,删除过期数据
MaxHousekeeperDelete=1000000 #清除过期数据,超过这个阀值的行都会被清理。
补充图片
1,系统任务队列查看
2,mysql status计量分析
3,io吞吐查看
4,my.cnf配置文件检查
5,io buys计量
6,engine计量
zabbix mysql优化 my.cnf_zabbix数据库优化之数据库优化(二)相关推荐
- zabbix mysql 表空间_Zabbix监控达梦数据库表空间
技术实现思路 利用Zabbix监控工具的定制功能.借鉴Zabbix对Oracle的监控原理,实现达梦数据库表空间监控.通过自动发现脚本发现达梦数据库表空间,然后再制定额外的属于达梦表空间的监控项,配置 ...
- zabbix mysql 8g优化_Zabbix分区优化
Zabbix分区优化 Zabbix数据库优化 目的: 快速清理历史数据,并减少数据存储容量 方法: 历史表使用分区表(删除分区表速度快),使用Tokudb引擎(适合大量insert少量update和s ...
- 熟悉mysql数据库设计和性能优化_Mysql数据库性能优化
Mysql数据库性能优化,可以从下面三点入手: 数据库设计 SQL语句优化 架构优化 一.数据库设计优化 1.适度的违反范式,适度 遵循三大范式就会带来查询时经常需要join,导致查询效率降低 ...
- 数据库调优策略:优化MySQL服务器、优化数据库结构、大表优化、隐藏索引对调优的帮助
文章目录 1. 数据库调优的措施 1.1 调优的目标 1.2 定位调优问题 1.3 调优的维度和步骤 2. 优化MySQL服务器 2.1 优化服务器硬件 2.2 优化MySQL的参数 3. 优化数据库 ...
- 【学习笔记】MySQL数据库高级版 - 索引优化、慢查询、锁机制等
本文是尚硅谷周阳(阳哥)老师的MySQL高级篇视频的学习笔记.由于视频比较老,所以在高版本的MySQL中索引的地方做了优化,和视频的内容不完全一样,不过大体一致.从第四节锁机制开始的部分还没有整理. ...
- mysql与数据处理,[转载]Mysql数据库千万级数据处理优化
转载:http://blog.sina.com.cn/s/blog_6dcd17320100tm6o.html 1. 对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by ...
- Mysql数据库高级、sql优化
https://note.youdao.com/ynoteshare/index.html?id=53cd90b2a1d930e1f5c7558a3f595696&type=notebook& ...
- MySQL数据库:SQL语句优化
数据库最常用的优化方式有:SQL语句和索引.数据库表结构.系统配置.硬件. 优化效果:SQL语句和索引 < 数据库表结构 < 系统配置 < 硬件,成本也是递增的. 优化方法 设计符合 ...
- MySQL主从延时这么长,要怎么优化
点击上方"java全栈技术"关注,每天学习一个java知识点 原创: 58沈剑 MySQL主从复制,读写分离是互联网常见的数据库架构,该架构最令人诟病的地方就是,在数据量较大并发量 ...
- 数据库的这些性能优化,你做了吗?
在互联网项目中,当业务规模越来越大,数据也越来越多,随之而来的就是数据库压力会越来越大. 我们可能会采取各种方式去优化,比如之前文章提到的缓存方案,SQL优化等等,除了这些方式以外,这里再分享几个针对 ...
最新文章
- 1.python全栈之路:python基础
- 算法基础课-动态规划-区间dp-AcWing 282. 石子合并:区间dp
- Java程序员从笨鸟到菜鸟之(八十七)跟我学jquery(三)jquery动态创建元素和常用函数示例
- python安装系统要求_python需要什么系统 | window重装系统教程
- C语言实现了一个顺序栈(附完整源码)
- idea 快捷键整理
- 运维利器:万能的 strace
- 使用 iPerf 测试 Azure VM 之间的网速
- Android 代码实现查看SQLite数据库中的表
- 用最简单的操作,做最精准的AI模型!
- 目前人们把通用计算机,计算机与信息社会基础知识测试题.doc
- 【CFD学习】网格无关性验证
- 林期苏曼属性标签编辑_标签制作软件如何制作商品标签模板
- 【微信技术-微信小程序】------- 渐进式骨架屏(加载流)(第二篇)
- 中职网络安全操作系统渗透
- Python数据分析实战之一--某网站二手房交易信息(数据处理)
- 《大话设计模式 C++版》
- 聊天室项目(一)-展示
- u盘中毒自动生成exe的 处理办法
- 从瞳代到“瞳代”再到品牌,暴利的美瞳的变与未变
热门文章
- C#单元测试如何查看输出的调试信息?
- wpf(第一个应用实例)
- 有两个集合,两个集合都是10万个数据(已排序),判断B是不是A的子集,算法时间复杂度为Q(N)...
- 榜单:全球 35 位 35 岁以下科技创新青年
- lua游戏开发实践指南光盘_Godot游戏开发实践之三:容易被忽视的Resource
- 自定义注解!绝对是程序员装逼的利器!!
- C++之父:比特币是用C++开发的,我为此感到遗憾。
- 看程序员如何给女朋友解释什么是锟斤拷?
- 国内Java面试总是问StringBuffer,StringBuilder区别是啥?档次为什么这么低?
- 云原生架构沙龙(成都站)圆满结束(附胶片下载)