Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. Database replication is a great way to ensure resilience of critical data am get back to business as soon as possible.
  2. The following are steps in setting up mysql replication. The procedure shows setting a single master and slave database.
  3. You can however scale the number of slaves just by giving each slave a unique ID.
  4.  
  5. There are tasks that are common across all replication setup:
  6.  
  7. 1. On the master, you must enable binary logging and configure a unique server ID. This might require a server restart.
  8.  
  9. 2. On each slave that you want to connect to the master, you must configure a unique ID. This might require a server restart.
  10.  
  11. 3. Create a separate user for your slaves to use during authentication with the master when reading the binary log for replication.(This is optional)
  12.  
  13. 4. Note down the current position in the binary log from the Master database. You need this information when configuring the
  14. slave so that the slave knows where within the binary log to start executing events.
  15.  
  16. 5. Configure the slave with settings for connecting to the master, such as the host name, login credentials, and binary log file name and position.
  17.  
  18. ####### CONFIGURING The MASTER #######
  19. (Using binary log file position based replication)
  20.  
  21. Step 1. To Enable binary logging and establish a unique server ID, shut down the MySQL server (service mysqld stop);
  22. Then add the below two lines in the my.cnf file or its windows equivalent my.ini under [mysqld] entry.
  23. In linux, this is normally located at /etc/my.cnf
  24.  
  25. log-bin=mysql-bin
  26. server-id=1
  27.  
  28. log-bin: is the prefix name of the binary logs. it is created in the data directory of mysql, usually located at /var/lib/mysql
  29.  
  30. if this option is left blank, the master will use the host name as the log-bin value.
  31. You can also give an absolute path to where this logs will be stored.
  32.  
  33. server-id: is the unique id given to each entity in a replication environment. It must be a positive interger between 1 and (232)−1
  34.  
  35. If these options already exist, but are commented out, uncomment the options and alter them according to your needs
  36.  
  37. After making the changes, restart the server.
  38.  
  39.  
  40. Step 2: Create a user in the master that will be used by the slave to authenticate for replication purpose. Remember, it's the slave that drives the process.
  41.  
  42. To create users, log in to your mysql server with a user that has create user and grant privileges, otherwise the followinf will not work.
  43.  
  44. CREATE USER 'User_Name_Goes_Here'@'Host_goes_here' IDENTIFIED BY 'the_password';
  45. GRANT REPLICATION SLAVE ON *.* TO 'User_Name_Goes_Here'@'Host_goes_here';
  46.  
  47. example. Say we want to create a user with the name= "replication", password = "replPass" and the host from where the slave sits and will connect from is 192.168.0.6 we would do this.
  48.  
  49. CREATE USER 'replication'@'192.168.0.6' IDENTIFIED BY 'replPass';
  50. GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.6';
  51.  
  52.  
  53. Step 3: Record a bin log position from where our slave will start reading replication events.
  54. To get a master bin log cordinate, run the following query in the master:
  55.  
  56. mysql> show master status;
  57. +------------------+-----------+--------------+------------------+-------------------+
  58. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
  59. +------------------+-----------+--------------+------------------+-------------------+
  60. | mysql-bin.000005 | 171690390 | | | |
  61. +------------------+-----------+--------------+------------------+-------------------+
  62. 1 row in set (0.00 sec)
  63.  
  64. You should get output that is similar to the above, however if your master has not data and binary logging was previously not enable, it will return
  65.  
  66. And that's it for the Master. Now to slave configuration.
  67.  
  68. ####### CONFIGURING The Slave #######
  69.  
  70. Configuring the slave is pretty easy:
  71. Step 1: Stop the slave mysql and add 'server-id' to the my.cnf file of the slave. It should be different from the ID set in the master. After this, restart the slave server. service mysqld restart.
  72.  
  73. step 2:
  74.  
  75.  
  76. options:
  77.  
  78. log-bin=mysql-bin
  79. server-id=1
  80. max_binlog_size=1073741824 (size if bin-log before rolling (master))
  81. binlog_format =STATEMENT (server/slave)
  82. expire_logs_days = 7
  83. binlog-ignore-db = "mysql" (slave)
  84.  
  85.  
  86.  
  87. CHANGE MASTER TO
  88. MASTER_HOST='172.17.0.16',
  89. MASTER_USER='DRCRepl',
  90. MASTER_PASSWORD='inmobia',
  91. MASTER_LOG_FILE='mysql-bin.000005',
  92. MASTER_LOG_POS=119532836;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement