Consul, ProxySQL And MySQL HA
CLICK HERE ===== https://blltly.com/2t2yn9
Remember this value since we will use it later.Add the following section at the end of /etc/mysql/my.cnf for group replication settings:[mysqld]# General Group replication settingsgtid_mode = ONenforce_gtid_consistency = ONmaster_info_repository = TABLErelay_log_info_repository = TABLEbinlog_checksum = NONElog_slave_updates = ONlog_bin = binlogbinlog_format = ROWtransaction_write_set_extraction = XXHASH64loose-group_replication_bootstrap_group = OFFloose-group_replication_start_on_boot = OFFloose-group_replication_ssl_mode = REQUIREDloose-group_replication_recovery_use_ssl = 1# TODO: Shared replication group configurationloose-group_replication_group_name = "2777fc39-ef8e-458f-b8fc-af74f398331f"loose-group_replication_ip_whitelist = "SERVER_2_IP, SERVER_3_IP, SERVER_4_IP"loose-group_replication_group_seeds = "SERVER_2_IP:33060, SERVER_3_IP:33060, SERVER_4_IP:33060"# TODO: Configurations for Single-primary (DEFAULT) or Multi-primary / multi-master mode? #loose-group_replication_single_primary_mode = OFF#loose-group_replication_enforce_update_everywhere_checks = ON# TODO: Host-specific configurationsserver_id = YOUR_SERVER_NUMBERbind-address = "YOUR_SERVER_IP"report_host = "YOUR_SERVER_IP"loose-group_replication_local_address = "YOUR_SERVER_IP:33060". Remember that you need to fill in your own information for SERVER_X_IP, YOUR_SERVER_IP, and YOUR_SERVER_NUMBER. Also, you will need to manually REJOIN the group after the service is restarted with the above setting (loose-group_replication_start_on_boot = OFF).Restart MySQL Service:systemctl restart mysqlRemember to open ports for MySQL service and MySQL Group Replication service.Login to MySQL console on each server to create a new user and grant replication permission:# mysql -u root -pmysql> SET SQL_LOG_BIN=0;mysql> CREATE USER 'REP_USER'@'%' IDENTIFIED BY 'REP_PASSWORD' REQUIRE SSL;mysql> GRANT REPLICATION SLAVE ON *.* TO 'rep'@'%';mysql> FLUSH PRIVILEGES;mysql> SET SQL_LOG_BIN=1;mysql> CHANGE MASTER TO MASTER_USER='REP_USER', MASTER_PASSWORD='REP_PASSWORD' FOR CHANNEL 'group_replication_recovery';mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';. Remember to choose your user (e.g. rep) and password (e.g. [email protected]) in the above configuration.Verify that the group replication plugin is on with the command SHOW PLUGINS; in MySQL console.Start MySQL Group Replication serviceTo start replication, we will need to start a bootstrapped node (the first node), and then start replication services on remaining nodes.
Configuring ProxySQL as the DB Connection proxyInstall and start ProxySQL on SERVER_1apt-get install -y lsb-releasewget -O - ' _pub_key' | apt-key add -echo deb -1.4.x/$(lsb_release -sc)/ ./ | tee /etc/apt/sources.list.d/proxysql.listapt-get update -yapt-get install proxysqlservice proxysql startLogin to the ProxySQL Admin Interface with MySQL client via the port 6032 and change the admin password (if you want):mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> 'Admin> SHOW DATABASES;Admin> UPDATE global_variables SET variable_value='admin:password' WHERE variable_name='admin-admin_credentials';Admin> LOAD ADMIN VARIABLES TO RUNTIME; Admin> SAVE ADMIN VARIABLES TO DISK;As you might see, I need to copy the memory settings to the runtime realm, then save them to disk to make them persist. The reason is that updating operations here only affect the memory layer.Add 3 MySQL nodes to the ProxySQL backends:Admin> INSERT INTO mysql_servers(hostgroup_id, hostname, port) VALUES (2, 'SERVER_2_IP', 3306), (2, 'SERVER_3_IP', 3306), (2, 'SERVER_4_IP', 3306);>Admin> SAVE MYSQL SERVERS TO DISK;>Admin> LOAD MYSQL SERVERS TO RUNTIME;Admin> SELECT * FROM mysql_servers;Admin> SELECT hostgroup_id, hostname, status FROM runtime_mysql_servers;Check the above result to be sure that all 3 nodes are in ONLINE status.
When you set any query rules inside table mysql_query_rules, then your query gets analyzed by the Query Processor to decide which destination hostgroup it should be forwarded to. (according to mysql_query_rules.destination_hostgroup)
When we load MYSQL SERVERS, our writer host also gets configured in the reader hostgroup automatically by ProxySQL to handle all those queries which are redirected to reader hostgroup in case no slaves are online.This feature is dependent on reader/writer hostgroup which we configured in table mysql_replication_hostgroups.
So bonus point here is we can decrease the weightage assigned to master servers inside mysql_server table for reader hostgroup , so that our most of read queries will go on server which has higher weight.
When the Query Processor scans the query rules trying to find a match with no success and it reaches the end, it will apply the default_hostgroup for the specific user according to mysql_users entry.In our case, user sysbench has a default_hostgroup=0, therefore any query not matching the above rules [Eg ALL WRITES ] will be sent to hostgroup 0 [Master].Below stats tables are used to validate if your query rules getting used by incoming traffic.
Then do not worry , ProxySQL is coming up with new feature to make sure your application get latest updated data. Currently this feature is available only with row based replication with GTID enabled. We have also blog on proxysql for Xtradb cluster
But, here my question is, as per the blog after save the configuration, the master will be added in readers host group too . But, it is not happening for me . Still, i have two rows in the table mysql_servers .
We recognize that planet.mysql.com is an important information feed. It is responsible for a massive ratio of the traffic on my blog, and no doubt for many others. Indie blog posts, or small-team blog posts, practically depend on planet.mysql.com to get visibility.
Crash safe means even if a slave mysqld/OS crash, you can recover the slave and continue replication without restoring MySQL databases onto the slave. To make crash safe slave work, you have to use InnoDB storage engine only, and in 5.6 you need to set relay_log_info_repository=TABLE and relay_log_recovery=1.
Galera cluster performance is as fast as the slowest node. Having an asynchronous replication slave can minimize the impact on the cluster if you send long-running reporting/OLAP type queries to the slave, or if you perform heavy jobs that require locks like mysqldump. The slave can also serve as a live backup for onsite and offsite disaster recovery.
If your application runs on PHP, you can use MySQL native driver (mysqlnd) to perform read/write splitting without big changes on the application side. Java users can use ConnectorJ to do read/write splitting with some minor changes on the coding side. Since the connector itself performs the routing, the extra network latency involved in proxy-based solutions is avoided.
We have blogged previously about backup strategies for MySQL. ClusterControl supports mysqldump and xtrabackup (full and incremental) to perform backups. Backups can be performed or scheduled on any database node (master or slaves) and stored locally or stored centrally on the ClusterControl node. When storing backups on the ClusterControl node, the backup is first created on the target database node and then streamed over using netcat to the controller node. You can also choose to backup individual databases or all databases. Backup progress is available underneath it and you will get a notification on the backup status each time it is created.
ClusterControl has ability to restore backups (mysqldump and xtrabackup) created by ClusterControl or externally via some other tool. For external backup, the backup files must exist on the ClusterControl node and only xbstream, xbstream.gz and tar.gz extensions are supported. 2b1af7f3a8