Advertisement
nguyenhappy92

How to Install Master-Master Replication MariaDB

Sep 21st, 2019
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. 10.11.23.140 master01
  2. 10.50.50.141 master02
  3.  
  4. ## I. Both Master Server
  5.  
  6. yum install epel-release -y
  7. yum update -y
  8. vi /etc/yum.repos.d/mariadb.repo
  9.  
  10. # MariaDB 10.2 CentOS repository list - created 2019-09-20 16:34 UTC
  11. # http://downloads.mariadb.org/mariadb/repositories/
  12. [mariadb]
  13. name = MariaDB
  14. baseurl = http://yum.mariadb.org/10.2/centos7-amd64
  15. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  16. gpgcheck=1
  17.  
  18. => Create repo at link https://downloads.mariadb.org/mariadb/repositories
  19. yum install MariaDB-server MariaDB-client -y
  20. systemctl start mariadb
  21. systemctl enable mariadb
  22. /usr/bin/mysql_secure_installation # create root mariadb
  23. vi /root/.my.cnf # create quickly access mysql root
  24. [client]
  25. user =root
  26. password =ye74b87EYP7CsdAFDD
  27. chmod 400 /root/.my.cnf
  28. mkdir -p /var/log/mariadb/
  29. chown -R mysql. /var/log/mariadb/
  30.  
  31. ## II. Server Master 01
  32. vi /etc/my.cnf.d/server.cnf
  33. server_id = 1
  34. log_bin = /var/log/mariadb/mariadb-bin.log
  35. log_bin_index = /var/log/mariadb/mariadb-bin.log.index
  36. relay_log = /var/log/mariadb/mariadb-relay-bin
  37. relay_log_index = /var/log/mariadb/mariadb-relay-bin.index
  38. expire_logs_days = 10
  39. max_binlog_size = 100M
  40. log_slave_updates = 1
  41. auto-increment-increment = 2
  42. auto-increment-offset = 1
  43. bind-address = x.x.x.x # replace x.x.x.x by IP Address of master01
  44.  
  45. systemctl restart mariadb
  46. CREATE USER 'replicate'@'%' IDENTIFIED BY 'B94Dz357dpj4KE7U';
  47. GRANT REPLICATION SLAVE ON *.* TO 'replicate'@'%' IDENTIFIED BY 'B94Dz357dpj4KE7U';
  48. FLUSH PRIVILEGES;
  49. FLUSH TABLES WITH READ LOCK;
  50. => Test user and password new create at master server 02 with command line mysql -u replicate -p -h x.x.x.x -P 3306
  51. SHOW MASTER STATUS;
  52. CHANGE MASTER TO master_host='10.11.23.141', master_port=3306, master_user='replicate', master_password='B94Dz357dpj4KE7U', master_log_file='mariadb-bin.000002', master_log_pos=344;
  53. START SLAVE;
  54. UNLOCK TABLES;
  55. SHOW SLAVE STATUS\G;
  56.  
  57. ### III. Server Master 02
  58. vi /etc/my.cnf.d/server.cnf
  59. server_id = 2
  60. log_bin = /var/log/mariadb/mariadb-bin.log
  61. log_bin_index = /var/log/mariadb/mariadb-bin.log.index
  62. relay_log = /var/log/mariadb/mariadb-relay-bin
  63. relay_log_index = /var/log/mariadb/mariadb-relay-bin.index
  64. expire_logs_days = 10
  65. max_binlog_size = 100M
  66. log_slave_updates = 1
  67. auto-increment-increment = 2
  68. auto-increment-offset = 2
  69. bind-address = x.x.x.x # replace x.x.x.x by IP Address of master02
  70.  
  71. systemctl restart mariadb
  72. CREATE USER 'replicate'@'%' IDENTIFIED BY 'B94Dz357dpj4KE7U';
  73. GRANT REPLICATION SLAVE ON *.* TO 'replicate'@'%' IDENTIFIED BY 'B94Dz357dpj4KE7U';
  74. FLUSH PRIVILEGES;
  75. FLUSH TABLES WITH READ LOCK;
  76. => Test user and password new create at master server 01 with command line mysql -u replication -p -h x.x.x.x -P 3306
  77. CHANGE MASTER TO master_host='10.11.23.140', master_port=3306, master_user='replicate', master_password='B94Dz357dpj4KE7U', master_log_file='mariadb-bin.000002', master_log_pos=344;
  78. START SLAVE;
  79. SHOW MASTER STATUS;
  80. UNLOCK TABLES;
  81. SHOW SLAVE STATUS\G;
  82. #### IV. Test
  83. Master 01
  84. create database test;
  85. create table test.flowers (`id` varchar(10));
  86. Master02
  87. show tables in test;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement