14.
MySQL master slave repliaction
installing mySQL Enterprise db1 & db2
editing my.cnf file db01
updating the owner of mysql directory's db1&db2
update host file db01& db02
configure master -slave DB01
start mysql DB01
creating replication user DB01
copy my.cnf file from db01 to db02
start mysql DB02
install plugins on db02 for cloning
changer master on db02
failover
6- MySQL Server Configuration
the guide show how to setup mysql master slave on mysql enterprise
you can obtain the enterprise iso from oracle website
installing mySQL Enterprise db1 & db2
we already downloaded the MySQL enterprise iso and added it on vm
we have added three spread disk on the vm that we use to create separate directory for the following
mysql data dir
mysql bin-log
mysql backup
also make sure to disable selinuix
once we have setup the separate mount point for the three directory we will now proceed with the
installation
the installation file itself will be compressed , we can use tar -xf to extract the file
we will start by installing mysql-commercial-backup-8.4.0-1.javascript.1.el8.x86_64.rpm using
yum localinstall
yum localinstall mysql-commercial-backup-8.4.0-1.javascript.1.el8.x86_64.rpm
now snice we found everything is working fine and we are able to install rpm packages on system, lets
continue installing the reset of the rpm package
note: you need to install the rpm in the order as showing in below command because some rpm
packages relay on the other for dependency
yum localinstall mysql-commercial-client-8.4.0-1.javascript.1.el8.x86_64.rpm
mysql-commercial-client-plugins-8.4.0-1.javascript.1.el8.x86_64.rpm mysql-
commercial-common-8.4.0-1.javascript.1.el8.x86_64.rpm mysql-commercial-icu-
data-files-8.4.0-1.javascript.1.el8.x86_64.rpm mysql-commercial-libs-8.4.0-
1.javascript.1.el8.x86_64.rpm mysql
-commercial-server-8.4.0-1.javascript.1.el8.x86_64.rpm mysql-commercial-
test-8.4.0-1.javascript.1.el8.x86_64.rpm
do the same on db2
editing my.cnf file db01
before we start the services for MySQL we need to update config for MySQL to point binlog and MySQL
data to new mount point we created
use any prefeed note editing tool i will be using vi
vi /etc/my.cnf
update datadir and and add log-bin and update it with binlog diretcory
updating the owner of mysql directory's db1&db2
you need to update owner of the directory we have setup for MySQL with MySQL user
chown -R mysql:mysql mysqldata/ chown -R mysql:mysql mysqlbinlog/ chown -R
mysql:mysql mysqlbackup/
update host file db01& db02
using any note editing tool and update the host file we hostname and ip of both DB
vi /etc/hosts
configure master -slave DB01
before we start the up MySQL
we will update my.cnf file with some important variables
- bin-address make it equal to 0.0.0.0
- server-id give unique server id for both master and slave
log_bin_trust_function_creators =1
lower_case_table_name=1
performance_schema_consumer_events_statements_history_long = ON
performance_schema=ON
performance-schema-instrument='statement/%=ON'
performance-schema-consumer-statements-digest=ON
innodb_monitor_enable=all
innodb_buffer_pool_size=2G or 70 to 80 % out of the memeory in the OS
below is the full my.cnf file after edititing
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/mysqldata
socket=/var/lib/mysql/mysql.sock
log-bin=/mysqlbinlog/mysql-bin.log
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
bind-address=0.0.0.0
server-id = 1
log_bin_trust_function_creators =1
lower_case_table_names=1
performance_schema_consumer_events_statements_history_long = ON
performance_schema=ON
performance-schema-instrument='statement/%=ON'
performance-schema-consumer-statements-digest=ON
innodb_monitor_enable=all
innodb_buffer_pool_size=2G
~
start mysql DB01
to start mysql using the below command
mysqld --initialize-insecure --user=mysql --lower_case_table_names=1
after that start mysql services
systemctl start mysqld systemctl enable mysqld
now you can login to mysql mysql -uroot
we will set password for the root user
set password='password';
exit and login again with root using the password you setup
creating replication user DB01
we will create user for replication on db1
create user 'repl' identified by 'repl123';
give the necessary grants for repl user for replication prepose
grant replication slave,backup_admin,clone_admin on *.* to 'repl'@'%';
grant select on performance_schema.* to 'repl'@'%';
copy my.cnf file from db01 to db02
to save time we will copy the my.cnf file from db01 to db02 using scp
next we will just update server-id in my.cnf file to unique one than one setup in db01
vi /etc/my.cnf
start mysql DB02
to start mysql using the below command
mysqld --initialize-insecure --user=mysql --lower_case_table_names=1
after that start mysql services
systemctl start mysqld systemctl enable mysqld
now you can login to mysql mysql -uroot
we will set password for the root user
set password='password';
install plugins on db02 for cloning
we will start by installing plugin for cloning instance of db01 to db02
install plugin clone soname "mysql_clone.so";
install plugin group_replication soname 'group_replication.so';
set global clone_valid_donor_list='mysql-enterprise-db01:3306';
set global log_error_verbosity=3;
on db1
also install the below plugin
install plugin clone soname "mysql_clone.so";
now clone the instance using the below command inside mysql console
clone instance from 'repl'@'mysql-enterprise-db01':3306 identified by
'repl123';
now stop mysqld on db02
and go to the data dir
and remove the auto.cnf file
then start mysqld on db02
changer master on db02
now we will change the master to db01 on db02
before that we need to get log position on db01
using the below command
SHOW BINARY LOG STATUS ;
so the log file is 000007 and postion is 573 this information is important when we start the replica
CHANGE MASTER TO MASTER_HOST='10.217.10.7', MASTER_USER='repl',
MASTER_password='repl123', MASTER_log_file='mysql-bin.000002',
MASTER_log_pos=1903 ;
now start replica by using the below command
START REPLICA;
now to verify use the below command
show replica status\G ;
failover
we will demonstrated how to failover to slave node
SET PRIMARY TO READ-ONLY
SET GLOBAL read_only = TRUE; SET GLOBAL event_scheduler = 'OFF'; FLUSH TABLES WITH
READ LOCK; SHOW MASTER STATUS;
Stop service on old primary
systemctl disable mysqld.service systemctl stop mysqld.service
RESET REPLICA ON NEW-PRIMARY
SHOW REPLICA STATUS\G
RESET MASTER;
stop replica ;
RESET REPLICA ALL;
SHOW REPLICA STATUS;
START MYSQL ON OLD-PRIMARY
systemctl enable mysqld.service
systemctl start mysqld.service
CONFIGURE OLD-PRIMARY TO BECOME REPLICA
before that obtain the log position from the new primary node (old slave)
show master status ;
RESET REPLICA ALL;
CHANGE master TO master_HOST='10.217.10.8', master_USER='repl',
master_PASSWORD='repl123', MASTER_log_pos=157 ;
START REPLICA;
SHOW REPLICA STATUS\G;
you may get the below erro related to our repl user usingf string_sha2_password
so we will have to alter user to be saved in mysql_+naitave_sql authecating methoid
alter USER 'repl'@'%' IDENTIFIED WITH mysql_native_password BY 'repl123';
stop and start the replica in old primary
stop replica
start replica ;
error is clear you may start testing replication