IntroductionThis page describes the process of rebuilding a Rebuild Slave-DB & Replication. Since the mysqldump MySQL Dump command locks the tables, it is not necessary that there is no need to create it when there is no traffic on the master databasemachine. It can be done during operational hours. With --master-data the command mysqldump stores the correct position for inserting the replication on the slave server. Warning |
---|
If the hard disk of the slave is full, please refer to the instructions on the bottom of this page | below - "Slave Disk Full".Login to slave server
Step-By-Step Guide
Warning |
---|
jtel does not take responsibility for any mishaps which result in attempting to execute the procedure described on this page, and also does not advise attempting this procedure, if no previous experience with database operations is present. The minimum requirement is that you have basis knowledge about relational databases in general and the MySQL database in particular. |
STOP SLAVELogin to the Slave Database MySQL and stop the slave SQL. Leave MySQL again afterwards. Use Login to MySQL with credentials USER and PWD, then stop slave and leave MySQL again. Use the following commands for this: Translations Ignore |
---|
mysql -uUSER -pPWD
STOP SLAVE;
|
RESET SLAVE;
Restart MySQL Server with the following command: Write a MySQL dump. Now perform the following steps on the master server. Create a backup directory and change to the same. The MySQL dumb is now executed with the following command mysqldump -uUSER -pPWD --single-transaction --master-data=2 --databases JTELWeb JTELStats JTELLog --add-drop-database --add-drop-table --events --routines --triggers > filename.sql
As of release 3.12 the following command is required: mysqldump -uUSER -pPWD --single-transaction --master-data=2 --databases JTELWeb JTELStats JTELStats2 JTELLog --add-drop-database --add-drop-table --events --routines --triggers > filename.sql
Here is a brief explanation of this: <Name LogFile> and <Position LogFile> are saved through --master-data in the dumpuse only the JTEL databases '--databases'delete all databases before import '--add-drop-database'delete all tables of the databases before import '--add-drop-table'Implement all routines and procedures in the dump '--events --routines'Additionally the parameter --default_character_set utf8 can be used
Warning |
---|
In versions 3.12, 3.14 and 3.15 If someone logs on to the portal while the dump is being pulled, it will go wrong. Enclosed a SQL query. If the time changes after executing the query, a login has taken place. If this happens, the dump has to be pulled again and in the meantime it has to be permanently checked if a login has taken place. Only if this is not the case, the dump can be replicated error-free to the slave. SELECT Max(dtAcdLoggedIn) FROM Users; In versions 3.11 and below and version 3.16 this problem does not exist. | Copy MySQL dump from master database server to slave database server Use the tool of your choice: command line (scp), WinSCP, ...
We switch back to the slave server and now import the mysqldump. Translations Ignore |
---|
mysql -uUSER -pPWD (we are now in MySql)
SET foreign_key_checks = 0;
drop database JTELLog;
drop database JTELStats;
drop database JTELWeb;
drop database JTELStats2;
SET foreign_key_checks = 1;
source <filename>;
| We are now determining the replication parameters, as we will need them in a moment:
- In the mysqldump file at the very beginning we find a line in the comment block that looks like this:
CHANGE MASTER TO MASTER_LOG_FILE='binlog.000872', MASTER_LOG_POS=11940974;Memorize the parameters MASTER_LOG_FILE und MASTER_LOG_POS . - We need the name or IP of the Master DB Server
- We need the password of user
repl on the Master DB Server. This is usually always the password of the user root - the easiest way to try it is to log on from the slave to the master with this password: mysql -h <masterIP> -u repl -p<Passwort> - if this works, then you know. Now on the slave server there is already a consistent, fairly new state of the data. It is now only necessary to reconfigure the replication. The following commands do this:mysql -uUSER -pPWD
CHANGE MASTER TO MASTER_HOST='<name or ip of master servers>',MASTER_USER='repl',MASTER_PASSWORD='<passwort>',MASTER_LOG_FILE='<Name LogFile>', MASTER_LOG_POS=<Position LogFile>; Here all parameters must be replaced with those from step 5.
Phase 1 - MySQL DumpA MySQL Dump of the master database is now created. Perform the following steps to create a MySQL Dump and save it to the STORE:
Warning |
---|
| The mysqldump command is different, depending on the jtel portal release, as well as the MySQL software release installed on the databases. All different options and how to find out which one to choose is specified below. |
Warning |
---|
title | Master-Master Replication |
---|
| The mysqldump commands on this page can NOT be used to realign a master-master replication. Visit the following page for that description Restore MySQL Master-Master Replication |
jtel Portal software releaseLog in to the Load Balancer of the cluster and execute the following commands as the jtel user Code Block |
---|
# Find out which software release is installed
cd /srv/jtel/shared/JTELCarrierPortal
git status
# If /srv/jtel/.. does not exist on the load balancer, attempt this
cd /home/jtel/shared/JTELCarrierPortal
git status
# Expected output
release-stable/3.XX |
Create Backup Directory Info |
---|
The following commands are designed to be executed on the load balancer as jtel user |
Code Block |
---|
# Create backup directory SLAVE MySQL Dump - Until jtel Portal release 3.12
mkdir /srv/jtel/shared/backup/DATUM
# If /srv/jtel/.. does not exist on the load balancer, attempt this
mkdir /srv/jtel/shared/backup/DATUM
|
Create MySQL Dump Warning |
---|
title | CAUTION - CREDENTIALS+IP-Adresses |
---|
| Credentials and IP-Adresses need to be changed before the following mysqldump commands can be executed |
Info |
---|
The following commands are designed to be executed on the load balancer as jtel user |
MySQL Dump - Until jtel Portal release 3.12 Code Block |
---|
# Change to backup directory
cd /srv/jtel/shared/backup/DATUM
# Create MysQL Dump
mysqldump -uUSER -pPWD -h<Alias or IP-Adress of master database> --single-transaction --master-data=1 --databases JTELWeb JTELStats JTELLog --add-drop-database --add-drop-table --events --routines --triggers > acd-dbm_<yyyymmdd>.sql |
MySQL Dump - From jtel Portal release 3.12 until latest release Code Block |
---|
# Change to backup directory
cd /srv/jtel/shared/backup/DATUM
# Create MysQL Dump
mysqldump -uUSER -pPWD -h<Alias or IP-Adress of master database> --single-transaction --master-data=1 --databases JTELWeb JTELStats JTELStats2 JTELLog --add-drop-database --add-drop-table --events --routines --triggers > acd-dbm_<yyyymmdd>.sql |
Warning |
---|
In versions 3.12, 3.14 and 3.15 If someone logs on to the portal while the dump is being pulled, it will go wrong. Enclosed a SQL query. If the time changes after executing the query, a login has taken place. If this happens, the dump has to be pulled again and in the meantime it has to be permanently checked if a login has taken place. Only if this is not the case, the dump can be replicated error-free to the slave. SELECT Max(dtAcdLoggedIn) FROM Users; In versions 3.11 and below and version 3.16 this problem does not exist. |
MySQL Dump - From MySQL 8.0.27To Check for MySQL Version, log in to the master database server and execute the following command Code Block |
---|
mysql --version |
Code Block |
---|
# Change to backup directory
cd /srv/jtel/shared/backup/DATUM
# Create MysQL Dump
mysqldump -uUSER -pPWD -h<Alias or IP-Adress of master database> --single-transaction --source-data --databases JTELWeb JTELStats JTELStats2 JTELLog --add-drop-database --add-drop-table --events --routines --triggers > acd-dbm_<yyyymmdd>.sql |
Brief Explanation of the mysqldump command<Name LogFile> and <Position LogFile> are saved through --master-data or --source-data in the dump use only the JTEL databases '--databases' delete all databases before import '--add-drop-database' delete all tables of the databases before import '--add-drop-table' Implement all routines and procedures in the dump '--events --routines' Additionally the parameter --default_character_set utf8 can be used
Phase 2 - Import Dump on Slave Database Info |
---|
The following commands are designed to be run from the Load Balancer as root user. After the source <acd-dbm_<yyyymmdd>.sql> is executed, the dump will start importing into the slave database. Once it is finished, the Slave SQL is started. Brief explanation - tmux: tmux is a tool used to create sub-sessions within a ssh terminal. The tool is a good option for this specific operation, since the sub-session can be exited but the processes which were started will still be running in the background. This prevents failure by accidental loss of the ssh terminal, and provides the ability to view the MySQL process list to check the progress of the import Tmux cheat sheet: https://tmuxcheatsheet.com/ |
Import Dump - tmux Code Block |
---|
# switch to root user
su root
# start tmux sub-session
tmux new
# change to the directory where the dump file is located
cd /srv/jtel/shared/backup/DATE/
# copy the name
ls -als
# log in to mysql and import the dump
mysql -uroot -p<password>
source <acd-dbm_<yyyymmdd>.sql> |
Import Dump - No tmux Code Block |
---|
# switch to root user
su root
# change to the directory where the dump file is located
cd /srv/jtel/shared/backup/DATE/
# copy the name
ls -als
# log in to mysql and import the dump
mysql -uroot -p<password>
source <acd-dbm_<yyyymmdd>.sql> |
Start Slave - tmux Code Block |
---|
# If not attached to the sub-session anymore
tmux attach
# Start Slave SQL
START SLAVE;
# Check Slave Status
SHOW SLAVE STATUS \G |
Start Slave - No tmux Code Block |
---|
# Start Slave SQL
START SLAVE;
# Check Slave Status
SHOW SLAVE STATUS \G |
Slave Disk FullThere are several reasons why the slave disk can become full. Following is a summary of the different cases and further below is a detailed explanation: Case |
---|
Temp directory full |
---|
Lots of "relay logs" available |
---|
ibdata files on the slave "very large" |
---|
Still no disk space > 20% free |
---|
tmp Directory Is FullIntroductionNow we check the slave status (a few times) with the command and expect the following result:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Now the replication is running again. The name of the logfile and the position should promptly correspond pretty much to the show master status on the master database. Do not forget to clean up data garbage! I.e. delete mysqldumps and directories at least on the slave. A backup can remain on the master database, provided there is enough space. Slave Disk FullThere are several reasons why the slave disk can become full. tmp directory is fullBackgroundEvery time a query creates a tmp table, it is written to the temp directory, usually /tmp. This happens when the maximum size exceeds the maximum "in memory" table size. This is defined with the variables tmp_table_size aswell as max_heap_table_size . See also https://dev.mysql.com/doc/refman/5.6/en/internal-temporary-tables.html for more information. The tables in /tmp are kept until the respective DB connection is closed or a DROP TEMPORARY TABLE is called. If the /tmp directory is full, it is likely that a DROP TEMPORARY TABLE is missing somewhere. This can also happen through customer queries to the DB. The installation of tmpwatch creates help in a permanent way Hints: - On CentOS 6 the /tmp directory is then by default freed from files that have not been accessed for > 10 days
- Circumstantially this may not be sufficient
- On CentOS 7 the /tmp directory is then freed by default from files that have not been accessed for> 1 day
Procedure- Space must first be made available. Just mercilessly delete everything from /tmp.
- If this provides enough space, then restart the mysql service first: service mysql restart
- If there is enough space (at least about 20%), then proceed with replication as described above.
Lots of "relay logs" availableIntroductionMySQL first writes the relay logs from the master to a file. Once replication is interrupted, but the slave relay process continues to operate, the disk is filled by relay logs. This step should be done in any case, especially before the next one (ibdata too large) to make room. ProcedureThe files for the database are usually located in /var/lib/mysql If not, the location can be found in /etc/my.cnf The corresponding entry is datadir=(pfad) Alle Relay Logs löschenDelete all relay logs: translations-ignore Info |
---|
cd /var/lib/mysql rm mysqld-relay-bin* |
Restart MySQL service translations-ignore Code Block |
---|
service mysqld restart |
If enough space is available (at least 20%) then proceed with the slave recovery as described above. ibdata files on the slave "very large"IntroductionThe files for the database are usually located in /var/lib/mysql Due to not clearly documented MySQL internas, the file /var/lib/mysql/ibdata1 can be huge compared to the master database. To remedy this, you have to proceed a little more rigorously. ProcedureIf no less than 100% disk can be achieved by the steps above: Unsubscribe the MySQL service from the autostart: Translations Ignore |
---|
Code Block |
---|
systemctl disable mysqld | service mysqld disableRestart the computer with : translations-ignore Code Block |
---|
systemctl reboot now |
Only works if less than 100% disk is reached (possibly after reboot above) then Log on to the mysql server: translations-ignore Code Block |
---|
mysql -u root -p |
Drop all JTEL databases: translations-ignore Code Block |
---|
SET FOREIGN_KEY_CHECKS=0; |
SET FOREIGN_KEY_CHECKS=1; |
Press CTRL+C to return to the command line, and then translations-ignore Code Block |
---|
service mysqld stop |
rm /var/lib/mysql/ibdata* |
rm /var/lib/mysql/ib_log_* |
Start MySql Server, and enable it again if necessary: translations-ignore Code Block |
---|
service mysqld start |
Check disk space, and proceed with Slave Restore as described above. Still no disk space > 20% freeIntroductionThe slave disk space is still full, more than 80% of the space on the drive is used by normal operation SolutionIn this case the slave is simply too small. The The hard disk must be expanded (as with extending the STORE role, apply only to the logical volume where the MySQL database data resides). Then Then perform the steps again, if the disk is too small, then restore the slave as described above. Or the slave is completely rebuilt with a larger plate.
|