Adding Tunning Options

This commit is contained in:
Philippe Caseiro 2018-04-11 17:00:18 +02:00
parent edafc9a45e
commit 8b9bb4e7d7
5 changed files with 109 additions and 0 deletions

13
creolefuncs/mariadb.py Normal file
View File

@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
def getMemoryPercentage(percent):
import os
try:
percent = int(percent)
totalMemory = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
memoryToUse = (totalMemory*percent)/100
memoryMb = memoryToUse/(1024.**2)
return "{0}M".format(round(memoryMb,2))
except:
return "Error during memory percentage calculation"

View File

@ -1,6 +1,7 @@
<creole>
<files>
<file filelist='dbCluster' name='/etc/mysql/conf.d/galera.cnf' rm='True' mkdir='True'/>
<file filelist='dbTunning' name='/etc/mysql/conf.d/tunning.cnf' rm='True' mkdir='True'/>
<service_access service='mariadb'>
<port service_accesslist='mariadb' protocol='tcp'>3306</port>
<tcpwrapper service_accesslist='mariadb'>mariadb</tcpwrapper>
@ -44,6 +45,50 @@
</variable>
<variable name="accLimitTarget" type="string" description="Restriction d'accès à ces IP/noms d'hôtes (liste séparateur séparateur ',')" />
</family>
<!-- Tunning -->
<family name="DataBase Tunning" mode="expert">
<variable name="dbInnoDBBufferPoolPercentage" type="number" description="Pourcentage de mémoire à dédier à MariaDB">
<value>20</value>
</variable>
<variable name="dbMaxConnections" type="number" description="Nombre de connection maximum pour le serveur de bases de données (max_connections)">
<value>100</value>
</variable>
<variable name="dbThreadCacheSize" type="number" description="Nombre de threads mis en cache par le serveur MariaDB">
<value>16</value>
</variable>
<variable name="dbCacheQueryEnabl" type="oui/non" description="Activer la mise en cache des requêtes">
<value>non</value>
</variable>
<variable name="dbQueryCacheLimit" type="string" description="Taille maximum des résultats de requêtes à mettre en cache">
<value>900K</value>
</variable>
<variable name="dbQueryCacheMinRestUnit" type="string" description="Taille des blocks du cache des requêtes">
<value>2K</value>
</variable>
<variable name="dbQueryCacheSize" type="string" description="Taille maximum du cache des requêtes">
<value>80M</value>
</variable>
<variable name="dbTmpTableSize" type="string" description="Taille maximum des tables internes stockées en mémoire">
<value>64M</value>
</variable>
<variable name="dbEnableSlowQueryLogs" type="oui/non" description="Journaliser les requêtes lentes (Slow Query)">
<value>non</value>
</variable>
<variable name="dbSlowQueryLogFile" type="string" description="Fichier de journalisation des requêtes lentes">
<value>/var/log/mysql/slow-query.log</value>
</variable>
<variable name="dbSlowQueryLogTime" type="number" description="Durée à partir de laquelle une requête est considérée comme lente (en secondes)">
<value>1</value>
</variable>
<variable name="dbWaitTimeout" type="number" description="Durée maximum d'inactivité d'une session (en secondes)">
<value>20</value>
</variable>
<variable name="dbAutoOptimizeAndRepare" type="oui/non" description="Activer l'autoréparation et optimisation de toutes les bases de données">
<value>non</value>
</variable>
</family>
<family name="Database Cluster">
<variable name='ifDBCluster' type='string' description="Interface réseau dédiée à la grappe BDD"/>
@ -65,6 +110,9 @@
<variable name='dbSSTMethod' type='string' mode='expert' description='Méthode SST'>
<value>rsync</value>
</variable>
<variable name='dbClusterGcacheSize' type='number' mode='expert' description="Write-set Cache Size (gcache.size)">
<value>128</value>
</variable>
<!-- End -->
</family>
<separators>
@ -121,6 +169,19 @@
<target type='family'>Database</target>
<target type='service_accesslist'>dbCluster</target>
</condition>
<condition name='disabled_if_in' source="dbCacheQueryEnable">
<param>non</param>
<target type='variable'>dbQueryCacheLimit</target>
<target type='variable'>dbQueryCacheMinRestUnit</target>
<target type='variable'>dbQueryCacheSize</target>
</condition>
<condition name='disabled_if_in' source="dbEnableSlowQueryLogs">
<param>non</param>
<target type='variable'>dbSlowQueryLogTime</target>
<target type='variable'>dbSlowQueryLogFile</target>
</condition>
</constraints>
<help/>
</creole>

View File

@ -1,6 +1,7 @@
#!/bin/bash
todo=$(CreoleGet dbCreateFixAdmin 'non')
autoRepair=$(CreoleGet dbAutoOptimizeAndRepare 'non')
if [[ ${todo} != 'non' ]]
then
@ -60,5 +61,11 @@ then
chmod 600 ${readerfile}
rm -rf ${sqlFile}
fi
if [[ ${autoRepair} == "oui" ]]
then
mysqlcheck -u root --auto-repair --check --optimize --all-databases
fi
exit 0

View File

@ -15,6 +15,8 @@ wsrep_cluster_address="gcomm://%%nodeIP%slurp
%end for
"
# Tunning
wsrep_provider_options="gcache.size=%%dbClusterGcacheSizeMb"
# Galera Synchronization Configuration
wsrep_sst_method=%%dbSSTMethod

26
tmpl/tunning.cnf Normal file
View File

@ -0,0 +1,26 @@
[mysqld]
innodb_file_per_table=1
skip-name-resolve
innodb_buffer_pool_size=%%getMemoryPercentage(%%getVar('dbInnoDBBufferPoolPercentage', 10))
max_connections=%%dbMaxConnections
thread_cache_size=%%dbThreadCacheSize
%if %%dbCacheQueryEnable == 'oui'
query_cache_type = 1
query_cache_limit = %%dbQueryCacheLimit
query_cache_min_res_unit = %%dbQueryCacheMinResUint
query_cache_size = %%dbQueryCacheSize
%end if
tmp_table_size = %%dbTmpTableSize
max_heap_table_size = %%dbTmpTableSize
%if %%dbEnableSlowQueryLogs == "oui"
slow-query-log = 1
slow-query-log-file = %%dbSlowQueryLogFile
long_query_time = %%dbSlowQueryLogTime
%end if
wait_timeout = %%dbWaitTimeout