agosto 21, 2017 13:10 by
Admin
INSTALAR CLUSTER PERCONA 5.6
1º deshabilitamos apparmor
Comprobamos: apparmor_status
Deshabilitamos:
ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
2º pedir clave
apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
3º añadir los repositorios en /etc/apt/sources.list
deb http://repo.percona.com/apt VERSION main
deb-src http://repo.percona.com/apt VERSION main
Sustituyendo VERSION por la versión de UBUNTU
4º apt-get update
5º apt-get install percona-xtradb-cluster-56
6º Configurar my.cnf
Ejemplo:
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
datadir=/var/lib/mysql
user=mysql
# Path to Galera library
wsrep_provider=/usr/lib/libgalera_smm.so
# Cluster connection URL contains the IPs of node#1, node#2 and node#3
wsrep_cluster_address=gcomm://192.168.0.240,192.168.0.241,192.168.0.242
# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW
# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB
# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2
# Node #1 address
wsrep_node_address=192.168.0.240
# SST method
wsrep_sst_method=xtrabackup-v2
# Cluster name
wsrep_cluster_name=mysql_cluster
# Authentication for SST method
wsrep_sst_auth="sstuser:s3cretPass"
#allow MyISam replication
wsrep_replicate_myisam = ON
#
# * Basic Settings
#
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 16M
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
7º Arrancar nodo principal con esta instrucción
/etc/init.d/mysql bootstrap-pxc
Resultado:
root@PERCONANODE1:/etc/mysql# /etc/init.d/mysql bootstrap-pxc
* Bootstrapping Percona XtraDB Cluster database server mysqld [ OK ]
Una vez arrancado entramos en el mysql
mysql –u root –p
Comprobamos que el galera esta funcionando:
Show status like ‘wsrep%’;
Añadimos el usuario que va a tener los permisos para la replicación:
CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 's3cretPass';
GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';
FLUSH PRIVILEGES;
Añadimos el usuario root@% para el acceso remoto
CREATE USER 'root'@'%' IDENTIFIED BY 'contraseña’;
Ahora le damos permiso con todos los roles administrativos
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'contraseña' WITH GRANT OPTION;
Repetimos los pasos en los nodos 2 y 3 cambiando en el my.cnf las IP del nodo
Arrancamos el servicio con /etc/init.d/mysql start
CONFIGURACION HAPROXY
En primer lugar creamos una entrada para el puerto 9200/tcp en el fichero services añadiendo la línea en el fichero /etc/services
mysqlchk 9200/tcp # mysqlchk
Instalamos xinetd con apt-get install xinetd
Cambiamos de directorio a /opt
Creamos el fichero mysqlchk con la siguiente configuración:
#!/bin/bash
#
# This script checks if a mysql server is healthy running on localhost. It will
# return:
#
# "HTTP/1.x 200 OK\r" (if mysql is running smoothly)
#
# - OR -
#
# "HTTP/1.x 500 Internal Server Error\r" (else)
#
# The purpose of this script is make haproxy capable of monitoring mysql properly
#
# Author: Unai Rodriguez
#
# It is recommended that a low-privileged-mysql user is created to be used by
# this script. Something like this:
#
# mysql> GRANT SELECT on mysql.* TO 'mysqlchkusr'@'localhost' \
# -> IDENTIFIED BY '257retfg2uysg218' WITH GRANT OPTION;
# mysql> flush privileges;
MYSQL_HOST="localhost"
TMP_FILE="/tmp/mysqlchk.out"
ERR_FILE="/tmp/mysqlchk.err"
#
# We perform a simple query that should return a few results :-p
#
WSSREP_STATUS=`/usr/bin/mysql --login-path=mysqlchkusr --host=$MYSQL_HOST -e "show status like 'wsrep_local_state';" | awk '{if (NR!=1){print $2}}' 2>/dev/null`
#
# Check the galera cluster consistent on node, your solution still allow connect to node even if cluster is desynced but mysql hear on
# 3306
#
#
if [ "$WSSREP_STATUS" == "4" ]
then
# mysql is fine, return http 200
/bin/echo -e "HTTP/1.1 200 OK\r\n"
/bin/echo -e "Content-Type: Content-Type: text/plain\r\n"
/bin/echo -e "\r\n"
/bin/echo -e "MySQL is running.\r\n"
/bin/echo -e "\r\n"
else
# mysql is fine, return http 503
/bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"
/bin/echo -e "Content-Type: Content-Type: text/plain\r\n"
/bin/echo -e "\r\n"
/bin/echo -e "MySQL is *down*.\r\n"
/bin/echo -e "\r\n"
fi
Grabamos y le cambiamos los permisos con chmod +x mysqlchk
Creamos el usuario mysqlchkusr en el mysql con la siguiente orden
mysql> GRANT SELECT on mysql.* TO 'mysqlchkusr'@'localhost' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
mysql> flush privileges;
Creamos el alias de usuario y password ya que pasar el usuario y contraseña por un script en mysql es altamente inseguro y no nos permite atacar al ejecutable mysqlchk de /opt, por tanto, ejecutamos la siguiente orden
mysql_config_editor set --login-path=mysqlchkusr --host=localhost --user=mysqlchkusr --password
Nos pedirá el password, que es el que previamente hayamos puesto al crear el usuario en la base de datos.
Ahora vamos a /etc/xinetd.d y editamos el fichero mysqlchk y debe contener este texto, este fichero ya está creado pero la línea server manda a una ruta que es la que hay que cambiar por el ejecutable que hemos creado en /opt/mysqlchk
# default: on
# description: mysqlchk
service mysqlchk
{
# this is a config for xinetd, place it in /etc/xinetd.d/
disable = no
flags = REUSE
socket_type = stream
type = UNLISTED
port = 9200
wait = no
user = nobody
server = /opt/mysqlchk
log_on_failure += USERID
only_from = 0.0.0.0/0
#
# Passing arguments to clustercheck
# "
# Recommended: server_args = user pass 1 /var/log/log-file 0 /etc/my.cnf.local"
# Compatibility: server_args = user pass 1 /var/log/log-file 1 /etc/my.cnf.local"
# 55-to-56 upgrade: server_args = user pass 1 /var/log/log-file 0 /etc/my.cnf.extra"
#
# recommended to put the IPs that need
# to connect exclusively (security purposes)
per_source = UNLIMITED
}
Luego cambiamos los permisos con chmod 0644 mysqlchk
Reiniciamos el servidor
Una vez reiniciado, si hacemos un telnet a la IP del nodo puerto 9200 nos tiene que dar un código 200 si el mysql está levantado y un 503 si no lo está
928987b6-cfa4-498e-a004-b980bbcccab0|5|3.0
febrero 16, 2012 13:36 by
Admin
Desde SQL no podemos activar un trabajo de mantenimiento realizando backup de nuestros datos a una unidad de red tipo NAS, por lo que, realizar un desembolso de este tipo para estas tareas resulta del todo inviable. SQL no nos reconoce la unidad aun mapeándola como unidad de red, solo reconocerá los discos físicos del servidor.
Por tanto, hemos invertido en un NAS de red pero no podemos volcar nuestros backup de SQL directamente desde una tarea de backup de SQL.
Podemos optar por la opción más trabajosa y que nos exige un cálculo del tiempo para sincronizar tareas y es, realizar una copia normal en un disco del servidor y posteriormente, mediante un script mover esos datos a otra ubicación.
Descartamos por tanto realizar copias de SQL en dispositivos de red? Definitivamente NO, se puede hacer, como? Aquí te explicamos como realizarlo.
Es necesario implementar el CmdShell en SQL, pero OJO en muchos sitios activar esta característica está catalogado como un agujero de seguridad, y ciertamente lo es, puesto que si un buen hacker se hace con el control de nuestra base de datos, puede acceder a disco mediante comandos cmdshell y eliminar, cambiar o renombrar ficheros.
Esta recomendación queda a criterio de cada administrador de Bases de Datos.
Por tanto, aunque no es recomendable su uso, por ejemplo para una granja de servidores web, en los que el acceso a registros de la base de datos se hace a través de programación, si somos pulcros en nuestra programación, podremos ejecutarlos sin problemas.
Sería bueno que MS evolucionara el SQL para que reconociera, al menos las unidades mapeadas de red, bueno, vamos a meternos en materia.
Activar CmdShell en SQL 2005: EXEC master.dbo.sp_configure 'show advanced options',1 RECONFIGURE EXEC master.dbo.sp_configure 'xp_cmdshell',1 RECONFIGURE
Activar CmdShell en SQL 2008: USE master GO EXECUTE sp_configure 'show advanced options', 1 RECONFIGURE WITH OVERRIDE GO EXECUTE sp_configure 'xp_cmdshell', '1' RECONFIGURE WITH OVERRIDE GO EXECUTE sp_configure 'show advanced options', 0 RECONFIGURE WITH OVERRIDE GO
Una vez ejecutado ya tenemos acceso a los comandos CMD.
Como configurar nuestro backup: Vamos de nuevo a la consola del SQL y nos vamos a los planes de mantenimiento y creamos un nuevo plan que llamaremos Copias_red
En el cuadro de herramientas que tenemos en la parte inferior izquierda de nuestra consola de SQL arrastramos al subplan un elemento Tarea Ejecutar Instruccion T-SQL, en Ingles estará como Execute T-SQL Statement Task.
Abrimos la tarea y establecemos que la conexión sea con el servidor local.
El código que vamos a implementar es el siguiente:
SET LANGUAGE spanish execxp_cmdshell ‘net use \\xxx.xxx.xxx.xxx\recurso password/user:nombre de usuario’ DECLARE @Archivo AS nvarchar(100) SET @Archivo = N'\\xxx.xxx.xxx.xxx\recursocompartido\nombrefichero' + DATENAME(WEEKDAY, GETDATE()) + '.bak' BACKUP DATABASE [NOMBREBBDD] TO DISK = @Archivo WITH NOFORMAT, INIT, NAME = N'NOMBREBBDD-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10; exec xp_cmdshell 'net use \\xxx.xxx.xxx.xxx\recurso /D'
En este script tendremos que cambiar SET LANGUAGE spanish por english si queremos los nombres del día en inglés \\xxx.xxx.xxx.xxx\recurso por la ruta UNC por la IP del disco de red y recurso compartido password, por la password del recurso nombre de usuario por el usuario, si fuera miembro de un dominio pues dominio\usuario nombredefichero por el nombre del fichero que va a tener el backup, esto seguido del nombre del día de la semana, con esto aseguramos tener una semana completa de backup y que posteriormente los vaya sobreescribiendo.NOMBREBBDD, lo sustituimos por el nombre de la base de datos de la que queremos realizar el backup.
Finalmente el comando exec xp_cmdshell 'net use \\xxx.xxx.xxx.xxx\recurso /D' es para desconectarnos del recurso de red.
Una vez introducido nuestro script, programamos el momento de realizar el backup y listo, ya tenemos nuestras copias en nuestro dispositivo de red.
Espero que os haya servido
Alberto
f87e6553-e305-4105-a6c1-37cce7774205|0|.0