progetti:cloud-areapd:mysql_high_availability
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
progetti:cloud-areapd:mysql_high_availability [2014/01/07 12:11] – [How connect to the MySQL Cluster as generic user] dorigoa@infn.it | progetti:cloud-areapd:mysql_high_availability [2015/03/03 09:07] (current) – [How to add users to MySQL Cluster] dorigoa@infn.it | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Install and setup MySQL HA using Percona XtraDB Multi-Master and HAProxy ====== | ||
+ | Author: | ||
+ | * Alvise Dorigo (INFN Padova) | ||
+ | |||
+ | Changes: | ||
+ | * 23-01-2015 - Added pre-req about mounted partition size's for ''/ | ||
+ | * 18-06-2014 - Added notes about start/ | ||
+ | * 07-01-2014 - Added info for admin and generic user access to MySQL cluster database | ||
+ | * 10-12-2013 - Added instructions to add new user in MySQL cluster | ||
+ | * 05-12-2013 - Added instruction to update to latest keepalived version (1.2.9) which supports the unicast trasmission | ||
+ | * 29-11-2013 - Added command to not allow xinetd logging successful connection (otherwise the logfile would grow too much, because '' | ||
+ | * 29-11-2013 - Added command to change xinetd' | ||
+ | * 27-11-2013 - Added link to HAProxy/ | ||
+ | * 27-11-2013 - Fixed the '' | ||
+ | |||
+ | ===== Reference links ===== | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | ===== Percona XtraDB MySQL Multi-Master ===== | ||
+ | |||
+ | |||
+ | |||
+ | ==== Prerequisites ==== | ||
+ | |||
+ | At least 3 nodes with: | ||
+ | * CentOS 6.4 Updated | ||
+ | * SELinux' | ||
+ | * EPEL 6-8 | ||
+ | * ip(6)tables disabled | ||
+ | * ntpd ON | ||
+ | * Each node should mount (usually in ''/ | ||
+ | |||
+ | Note: if the nodes are virtual, the virtual instances **must** run on different hardware. | ||
+ | |||
+ | ==== Install the Percona software ==== | ||
+ | On all three nodes execute the commands: | ||
+ | <code bash> | ||
+ | rpm -Uhv http:// | ||
+ | rpm --import http:// | ||
+ | rpm -e --nodeps mysql-libs | ||
+ | yum -y install Percona-XtraDB-Cluster-server-55 Percona-XtraDB-Cluster-client-55 Percona-XtraDB-Cluster-galera-2 | ||
+ | |||
+ | </ | ||
+ | ==== Configure Percona ==== | ||
+ | On all three nodes execute the following commands (substitute IPLIST' | ||
+ | <code bash> | ||
+ | export IPLIST=" | ||
+ | export MYIP=`ip -f inet addr show eth0 | grep inet | awk ' | ||
+ | export CLUSTER_NAME=" | ||
+ | cat << EOF > /etc/my.cnf | ||
+ | [mysqld] | ||
+ | # | ||
+ | datadir=/ | ||
+ | user=mysql | ||
+ | innodb_log_file_size=64M | ||
+ | innodb_file_per_table=1 | ||
+ | innodb_locks_unsafe_for_binlog=1 | ||
+ | |||
+ | # Path to Galera library | ||
+ | wsrep_provider=/ | ||
+ | # Cluster connection URL contains the IPs of node#1, node#2 and node#3 | ||
+ | wsrep_cluster_address=gcomm:// | ||
+ | # 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 is a recommended tuning variable for performance | ||
+ | innodb_locks_unsafe_for_binlog=1 | ||
+ | # 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=$MYIP | ||
+ | # SST method | ||
+ | wsrep_sst_method=xtrabackup | ||
+ | # Cluster name | ||
+ | wsrep_cluster_name=$CLUSTER_NAME | ||
+ | # Authentication for SST method | ||
+ | wsrep_sst_auth=" | ||
+ | EOF | ||
+ | |||
+ | yum -y install xinetd | ||
+ | echo " | ||
+ | chkconfig xinetd on | ||
+ | sed -i s' | ||
+ | sed -i ' | ||
+ | sed -i ' | ||
+ | service xinetd start | ||
+ | </ | ||
+ | ==== Bootstrap the Percona cluster ==== | ||
+ | Temporary choose a node as primary. In the primary node execute the commands: | ||
+ | <code bash> | ||
+ | / | ||
+ | chkconfig mysql on | ||
+ | mysql -u root -e " | ||
+ | mysql -u root -e "GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO ' | ||
+ | mysql -u root -e "GRANT PROCESS ON *.* TO ' | ||
+ | </ | ||
+ | On the other nodes execute: | ||
+ | <code bash> | ||
+ | / | ||
+ | chkconfig mysql on | ||
+ | </ | ||
+ | Now the MySQL-Percona cluster should be up & running (you can check with "'' | ||
+ | On all nodes of the cluster execute this commands (substitute '' | ||
+ | <code bash> | ||
+ | mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO ' | ||
+ | </ | ||
+ | ==== Basic checks ==== | ||
+ | On any node check the correct working of the script / | ||
+ | <code bash> | ||
+ | [root@percona1 ~]# / | ||
+ | HTTP/1.1 200 OK | ||
+ | Content-Type: | ||
+ | Connection: close | ||
+ | Content-Length: | ||
+ | |||
+ | Percona XtraDB Cluster Node is synced. | ||
+ | </ | ||
+ | |||
+ | Clustercheck, | ||
+ | <code bash> | ||
+ | dorigoa@lxadorigo 15:06:08 ~>telnet percona1.pd.infn.it 9200 | ||
+ | Trying 192.168.122.51... | ||
+ | Connected to percona1.pd.infn.it. | ||
+ | Escape character is ' | ||
+ | HTTP/1.1 200 OK | ||
+ | Content-Type: | ||
+ | Connection: close | ||
+ | Content-Length: | ||
+ | |||
+ | Percona XtraDB Cluster Node is synced. | ||
+ | Connection closed by foreign host. | ||
+ | </ | ||
+ | |||
+ | Note that both commands above, are saying that the cluster is synced. If any problem occurred during installation/ | ||
+ | |||
+ | ==== Notes about starting/ | ||
+ | Above, it has been showed how to bootstrap the cluster: the primary node must be started with the option **%%--wsrep-cluster-address=" | ||
+ | |||
+ | When the cluster is running, each node can be simply restarted (without the **'' | ||
+ | |||
+ | **But be careful**: not using the option is allowed only when at least one node is up. If the cluster is starting from a situation in which all nodes are OFF, one of them must be started with the option (the choice of which node is based on the assumption that that node has the last database' | ||
+ | |||
+ | ===== HAProxy ===== | ||
+ | ==== Prerequisites ==== | ||
+ | At least 2 nodes with: | ||
+ | * CentOS 6.4 Updated | ||
+ | * SELinux' | ||
+ | * EPEL 6-8 | ||
+ | * ip(6)tables disabled | ||
+ | * ntpd ON | ||
+ | |||
+ | ==== Install the HAProxy software ==== | ||
+ | On all two nodes execute: | ||
+ | <code bash> | ||
+ | yum -y install haproxy | ||
+ | </ | ||
+ | ==== Configure HAProxy ==== | ||
+ | On both two nodes execute the following commands (substitute the hostnames '' | ||
+ | <code bash> | ||
+ | mv / | ||
+ | cat << EOF > | ||
+ | global | ||
+ | log 127.0.0.1 | ||
+ | log 127.0.0.1 | ||
+ | maxconn 4096 | ||
+ | uid 188 | ||
+ | gid 188 | ||
+ | daemon | ||
+ | #debug | ||
+ | #quiet | ||
+ | |||
+ | defaults | ||
+ | log | ||
+ | mode http | ||
+ | option | ||
+ | option | ||
+ | retries 3 | ||
+ | option redispatch | ||
+ | maxconn 2000 | ||
+ | contimeout | ||
+ | clitimeout | ||
+ | srvtimeout | ||
+ | |||
+ | listen mysql-cluster 0.0.0.0: | ||
+ | mode tcp | ||
+ | balance roundrobin | ||
+ | option | ||
+ | |||
+ | server percona1.pd.infn.it 192.168.122.51: | ||
+ | server percona2.pd.infn.it 192.168.122.52: | ||
+ | server percona3.pd.infn.it 192.168.122.53: | ||
+ | |||
+ | listen mysql-cluster-failover :43306 | ||
+ | mode tcp | ||
+ | balance leastconn | ||
+ | option | ||
+ | server | ||
+ | server | ||
+ | server | ||
+ | EOF | ||
+ | |||
+ | service haproxy start | ||
+ | chkconfig haproxy on | ||
+ | </ | ||
+ | ==== Make the two HAProxy nodes redundant with Keepalived ==== | ||
+ | === Installing the newest version of Keepalived === | ||
+ | We observed that the version of keepalived 1.2.7 coming from the Epel repositories, | ||
+ | If you don't want to flood your LAN with a lot of multiscast message, you have to install the 1.2.9 version of Keepalived by following this procedure: | ||
+ | <code bash> | ||
+ | wget http:// | ||
+ | rpm -ivh keepalived-1.2.7-3.el6.src.rpm | ||
+ | cd rpmbuild/ | ||
+ | mv keepalived.spec keepalived.spec.orig | ||
+ | sed ' | ||
+ | cd ../SOURCES | ||
+ | wget http:// | ||
+ | cd - | ||
+ | yum -y install net-snmp-devel libnl-devel popt-devel rpm-build rpmlint kernel-devel gcc libtool make | ||
+ | rpmbuild -ba keepalived.spec | ||
+ | rpm -ivh ../ | ||
+ | </ | ||
+ | Otherwhise, just install the Keepalived package with this command: | ||
+ | <code bash> | ||
+ | yum install -y keepalived | ||
+ | </ | ||
+ | === Configuring Keepalived === | ||
+ | On both two nodes create the configuration file ''/ | ||
+ | <code bash> | ||
+ | mv / | ||
+ | cat << EOF > / | ||
+ | global_defs { | ||
+ | notification_email { | ||
+ | alvise.dorigo@pd.infn.it | ||
+ | } | ||
+ | notification_email_from noreply-keepalived-gridops@pd.infn.it | ||
+ | smtp_server 192.168.122.1 | ||
+ | smtp_connect_timeout 30 | ||
+ | router_id LVS_DEVEL | ||
+ | } | ||
+ | vrrp_script chk_haproxy { | ||
+ | script " | ||
+ | interval 1 | ||
+ | } | ||
+ | vrrp_instance VI_1 { | ||
+ | interface eth0 | ||
+ | state MASTER | ||
+ | smtp_alert | ||
+ | virtual_router_id 51 | ||
+ | priority 101 # on the nodes considered slaves, change 101 -> 100 | ||
+ | unicast_peer { | ||
+ | 192.168.122.53 # this is the other node's IP address | ||
+ | } | ||
+ | advert_int 1 | ||
+ | | ||
+ | auth_type PASS | ||
+ | auth_pass 1111 | ||
+ | } | ||
+ | # check every second | ||
+ | # add 2 points of prio if OK | ||
+ | # 101 on master, 100 on slaves | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | | ||
+ | chk_haproxy | ||
+ | } | ||
+ | EOF | ||
+ | |||
+ | echo << EOF >> / | ||
+ | net.ipv4.ip_nonlocal_bind = 1 | ||
+ | EOF | ||
+ | sysctl -p | ||
+ | service keepalived start | ||
+ | chkconfig keepalived on | ||
+ | </ | ||
+ | With the command "'' | ||
+ | <code bash> | ||
+ | ip addr sh eth0 | ||
+ | 2: eth0: < | ||
+ | link/ether 52: | ||
+ | inet 192.168.122.54/ | ||
+ | inet 192.168.122.56/ | ||
+ | inet6 fe80:: | ||
+ | | ||
+ | </ | ||
+ | ===== How connect to the MySQL Cluster as Admin ===== | ||
+ | Administration of the clustered database ('' | ||
+ | <code bash> | ||
+ | dorigoa@lxadorigo 11:42:54 ~>ssh mysql-cluster-01.cloud.pd.infn.it -l root | ||
+ | Last login: Fri Dec 20 09:19:36 2013 from mac-grid-01.pd.infn.it | ||
+ | [root@mysql-cluster-01 ~]# mysql -u root | ||
+ | Welcome to the MySQL monitor. | ||
+ | Your MySQL connection id is 4690147 | ||
+ | Server version: 5.5.34 Percona XtraDB Cluster (GPL), wsrep_23.7.6.r3936 | ||
+ | |||
+ | Copyright (c) 2009-2013 Percona LLC and/or its affiliates | ||
+ | Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. | ||
+ | |||
+ | Oracle is a registered trademark of Oracle Corporation and/or its | ||
+ | affiliates. Other names may be trademarks of their respective | ||
+ | owners. | ||
+ | |||
+ | Type ' | ||
+ | |||
+ | mysql> | ||
+ | </ | ||
+ | |||
+ | Please note that the virtual address '' | ||
+ | ===== How connect to the MySQL Cluster as generic user ===== | ||
+ | When a user needs to connect to the MySQL Cluster, it will use the option '-h < | ||
+ | <code bash> | ||
+ | dorigoa@lxadorigo 13:08:18 ~>mysql -u keystone -h mysql-cluster.cloud.pd.infn.it keystone -e " | ||
+ | +----------------------------------+----------------------------------+-----------+-----------+----------------------------------+---------------------------------+-------+ | ||
+ | | id | legacy_endpoint_id | ||
+ | +----------------------------------+----------------------------------+-----------+-----------+----------------------------------+---------------------------------+-------+ | ||
+ | | 55a3e6cf263446629510a430070e8556 | 399575e2f7804ef283017a15b2f386e6 | admin | regionOne | 02d1c4d4bb4e494e882be273dd940b9b | http:// | ||
+ | | 656621f6586140949d367fb076222d01 | 280045a6b1754b80bdb752ecc2fb3bc1 | public | ||
+ | | 7288cac2c0184563b5d6648918921181 | 399575e2f7804ef283017a15b2f386e6 | internal | ||
+ | | 94a86c5e3bec4ac58b66e19aaface2ab | 280045a6b1754b80bdb752ecc2fb3bc1 | admin | regionOne | 2ceadb76cc6f48639893a44e64631b75 | http:// | ||
+ | | d5db044832764a4f8953b9589e786dbd | 280045a6b1754b80bdb752ecc2fb3bc1 | internal | ||
+ | | d60b906ed4844f7e8217c6843e9c38e6 | 399575e2f7804ef283017a15b2f386e6 | public | ||
+ | +----------------------------------+----------------------------------+-----------+-----------+----------------------------------+---------------------------------+-------+ | ||
+ | </ | ||
+ | Please note that in order to make a generic user able to connect to the MySQL cluster through the alias FQDN '' | ||
+ | ===== How to add users to MySQL Cluster ===== | ||
+ | Every connection from any host to the mysql cluster' | ||
+ | <code bash> | ||
+ | GRANT ALL ON mydatabase.* TO ' | ||
+ | GRANT ALL ON mydatabase.* TO ' | ||
+ | GRANT ALL ON mydatabase.* TO ' | ||
+ | GRANT ALL ON mydatabase.* TO ' | ||
+ | GRANT ALL ON mydatabase.* TO ' | ||
+ | GRANT ALL ON mydatabase.* TO ' | ||
+ | GRANT ALL ON mydatabase.* TO ' | ||
+ | </ | ||
+ | ===== Avoid a problem of 'too many open files' ===== | ||
+ | Running the tool '' | ||
+ | In order to avoid it, put the following lines in the file ''/ | ||
+ | <code bash> | ||
+ | * soft nofile 60000 | ||
+ | * hard nofile 60000 | ||
+ | </ | ||
+ | and the following line in the file ''/ | ||
+ | <code bash> | ||
+ | fs.file-max = 900000 | ||
+ | </ | ||
+ | then run | ||
+ | <code bash> | ||
+ | sysctl -p | ||
+ | </ | ||
+ | --- // |