Instalacion del cluster de Percona en Ubuntu 16

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á