Guest User

Untitled

a guest
Jul 29th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. ### ON MASTER
  2.  
  3. ```
  4. $ yum install mariadb-server
  5. $ systemctl restart mariadb
  6. $ systemctl enable mariadb
  7. $ mysql_secure_installation
  8. ```
  9.  
  10. On /etc/my.cnf, add
  11. ```
  12. server_id=1
  13. log-basename=master
  14. log-bin
  15. ```
  16.  
  17. ```
  18. $ systemctl restart mariadb
  19. $ mysql -u root -p
  20. MariaDB [(none)]> STOP SLAVE;
  21. MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY '123';
  22. MariaDB [(none)]> FLUSH PRIVILEGES;
  23. MariaDB [(none)]> FLUSH TABLES WITH READ LOCK;
  24. MariaDB [(none)]> SHOW MASTER STATUS;
  25. +--------------------+----------+--------------+------------------+
  26. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  27. +--------------------+----------+--------------+------------------+
  28. | mariadb-bin.000001 | 460 | | |
  29. +--------------------+----------+---------
  30.  
  31. ```
  32.  
  33. Keep session on, don’t logout. Open new terminal and dump the db to file:
  34.  
  35. ```
  36. $ mysqldump --all-databases --user=root --password --master-data > masterdatabase.sql
  37. ```
  38.  
  39. Back on the previous ternimal:
  40.  
  41. ```
  42. MariaDB [(none)]> UNLOCK TABLES;
  43. ```
  44.  
  45. Copy the dump file to slave server
  46.  
  47. ```
  48. $ scp masterdatabase.sql root@slave.server.com:/root/
  49. ```
  50.  
  51.  
  52.  
  53. ### ON SLAVE
  54.  
  55. ```
  56. $ yum install mariadb-server
  57. $ systemctl restart mariadb
  58. $ systemctl enable mariadb
  59. $ mysql_secure_installation
  60. ```
  61.  
  62. On /etc/my.cnf, put server_id=2. Then import the copy from the master database.
  63.  
  64. ```
  65. $ mysql -u root -p < masterdatabase.sql
  66. $ systemctl restart mariadb
  67. $ mysql -u root -p
  68. MariaDB [(none)]> STOP SLAVE;
  69. MariaDB [(none)]>
  70. CHANGE MASTER TO
  71. MASTER_HOST='master.server.com',
  72. MASTER_USER='slave',
  73. MASTER_PASSWORD='mypassword',
  74. MASTER_PORT=3306,
  75. MASTER_LOG_FILE='mariadb-bin.000001',
  76. MASTER_LOG_POS=460,
  77. MASTER_CONNECT_RETRY=10;
  78.  
  79. MariaDB [(none)]> SLAVE START;
  80. MariaDB [(none)]> SHOW SLAVE STATUS\G;
  81. ```
Add Comment
Please, Sign In to add comment