Shogun Posted June 1, 2013 Report Share Posted June 1, 2013 Buenas, hoy os traigo un script que facilita la tarea de detectar problemas y cuellos de botella en servidores MySQL, y en general, optimizar sus recursos y funcionamiento. Se trata de un script perl que se puede utilizar tanto bajo Linux como FreeBSD: FreeBSD cd /root fetch mysqltuner.pl chmod 755 mysqltuner.pl ./mysqltuner.pl Linux cd /root wget mysqltuner.pl chmod 755 mysqltuner.pl ./mysqltuner.pl A continuación nos mostrará una serie de estadísticas y recomendaciones sobre nuestro servidor tal que así: Es bastante sencillo de entender, pero si no tenemos conocimientos del tema lo mejor es seguir las recomendaciones del final, éstas se refieren a variables que se encuentran en my.cnf (fichero de configuración de mysql) éste fichero se puede encontrar en varios lugares según el sistema así que lo mejor será mirar primero en /etc/my.cnf (localización más común) y si no lo encontramos ahí, buscarlo tal que asi: locate my.cnf Y a continuación editamos el fichero con las recomendaciones que mencionamos arriba. Si la variable no está en my.cnf, simplemente la añadimos. Aquí un ejemplo del fichero my.cnf del WOM: [client] port = 3306 socket = /tmp/mysql.sock # Here follows entries for some specific programs # The MySQL server [mysqld] port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 384M max_allowed_packet = 1M table_open_cache = 512 sort_buffer_size = 4M read_buffer_size = 2M read_rnd_buffer_size = 16M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size = 32M # Try number of CPU's*2 for thread_concurrency thread_concurrency = 4 max_connections=250 # Don't listen on a TCP/IP port at all. This can be a security enhancement, # if all processes that need to connect to mysqld run on the same host. # All interaction with mysqld must be made via Unix sockets or named pipes. # Note that using this option without enabling named pipes on Windows # (via the "enable-named-pipe" option) will render mysqld useless! # #skip-networking # Replication Master Server (default) # binary logging is required for replication #log-bin=mysql-bin # required unique id between 1 and 2^32 - 1 # defaults to 1 if master-host is not set # but will not function as a master if omitted server-id = 1 # Replication Slave (comment out master section to use this) # # To configure this host as a replication slave, you can choose between # two methods : # # 1) Use the CHANGE MASTER TO command (fully described in our manual) - # the syntax is: # # CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>, # MASTER_USER=<user>, MASTER_PASSWORD=<password> ; # # where you replace <host>, <user>, <password> by quoted strings and # <port> by the master's port number (3306 by default). # # Example: # # CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, # MASTER_USER='joe', MASTER_PASSWORD='secret'; # # OR # # 2) Set the variables below. However, in case you choose this method, then # start replication for the first time (even unsuccessfully, for example # if you mistyped the password in master-password and the slave fails to # connect), the slave will create a master.info file, and any later # change in this file to the variables' values below will be ignored and # overridden by the content of the master.info file, unless you shutdown # the slave server, delete master.info and restart the slaver server. # For that reason, you may want to leave the lines below untouched # (commented) and instead use CHANGE MASTER TO (see above) # # required unique id between 2 and 2^32 - 1 # (and different from the master) # defaults to 2 if master-host is set # but will not function as a slave if omitted #server-id = 2 # # The replication master for this slave - required #master-host = <hostname> # # The username the slave will use for authentication when connecting # to the master - required #master-user = <username> # # The password the slave will authenticate with when connecting to # the master - required #master-password = <password> # # The port the master is listening on. # optional - defaults to 3306 #master-port = <port> # # binary logging - not required for slaves, but recommended #log-bin=mysql-bin # # binary logging format - mixed recommended #binlog_format=mixed # Uncomment the following if you are using InnoDB tables #innodb_data_home_dir = /var/db/mysql #innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend #innodb_log_group_home_dir = /var/db/mysql # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 384M #innodb_additional_mem_pool_size = 20M # Set .._log_file_size to 25 % of buffer pool size #innodb_log_file_size = 100M #innodb_log_buffer_size = 8M #innodb_flush_log_at_trx_commit = 1 #innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size = 256M sort_buffer_size = 256M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout Como vimos arriba al ejectutar mysqltuner.pl bajo el epigrafe Variables nos recomienda subir sort_buffer_size por encima de 2M y read_rnd_buffer_size sobre 16M, así que esas son las variables que tendríais que editar, a continuación reiniciar el servidor mysql y dejarlo correr unos días antes de ejecutar de nuevo mysqltuner.pl, así hasta que no os de ningún "aviso" en rojo, lo cual significa que el servidor está optimizado al máximo, no así su uso de memoria como veremos ahora. Otra cosa que se puede hacer si tenemos algo de confianza es justo lo contrario, reducir valores excesivos. Un ejemplo de esto lo tenemos en la salida de mysqltuner.pl que nos dice lo siguiente: InnoDB Data Size / Buffer Pool 3.5 MB / 128 MB Es decir que tenemos reservados 128 MB para algo que solo ocupa 3. Buscamos el culpable en my.cnf #innodb_buffer_pool_size = 384M Está comentado por lo que toma el valor default de 128, lo dejaríamos por ejemplo así, dejando memoria libre para otras tareas: innodb_buffer_pool_size = 16M fuuton97, TheSanto and Rafa23Alzira 3 Quote Link to comment Share on other sites More sharing options...
Rafa23Alzira Posted June 1, 2013 Report Share Posted June 1, 2013 Posteas poco, pero cuando posteas es de calidad, gracias Shogun Quote Link to comment Share on other sites More sharing options...
Shogun Posted June 1, 2013 Author Report Share Posted June 1, 2013 He añadido la parte final que se me había "colado" Añado que no os rompais mucho la cabeza con tablas fragmentadas, por lo menos en el uso que le da en Metin2 pasarse el día haciendo Optimize Tables os va a ayudar poco, si eso hacerlo cada varios meses y pista. Quote Link to comment Share on other sites More sharing options...
TheSanto Posted June 1, 2013 Report Share Posted June 1, 2013 cuando hago cd /root fetch mysqltuner.pl me sale fetch: mysqltuner.pl: No such file or directory Quote Link to comment Share on other sites More sharing options...
Shogun Posted June 1, 2013 Author Report Share Posted June 1, 2013 cuando hago cd /root fetch mysqltuner.pl me sale fetch: mysqltuner.pl: No such file or directory Prueba con fetch Debes iniciar sesión para ver el contenido del enlace en esta publicación. Synea, ♥ TesT ♥, 4Metin and 3 others 5 1 Quote Link to comment Share on other sites More sharing options...
TheSanto Posted June 2, 2013 Report Share Posted June 2, 2013 si pero se me queda en lo de user de administrador de mysql y la pass que hay que poner ahy? Quote Link to comment Share on other sites More sharing options...
fuuton97 Posted June 3, 2013 Report Share Posted June 3, 2013 Cuál password se coloca de administrador?? Quote Link to comment Share on other sites More sharing options...
Rafa23Alzira Posted June 3, 2013 Report Share Posted June 3, 2013 Cuando instalais el dedicado os pide una pass de mysql, si no me equivoco será esa. Quote Link to comment Share on other sites More sharing options...
Shogun Posted June 3, 2013 Author Report Share Posted June 3, 2013 por defecto la pass de administrador de mysql está en blanco Quote Link to comment Share on other sites More sharing options...
TheSanto Posted June 11, 2013 Report Share Posted June 11, 2013 pues yo meto el usuario y cuando me pide la pass le doy enter y me dice [!!] Attempted to use login credentials, but they were invalid. xxx# y si pruebo en el otro dedicado no me deja hacer ./mysqltuner.pl Quote Link to comment Share on other sites More sharing options...
Shogun Posted June 11, 2013 Author Report Share Posted June 11, 2013 Si no sabes la pass de tu servidor mysql no te puedo ayudar en eso Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.