MySQL master-slave Replication

Source: Internet
Author: User

Master server: 172.16.15.20
Slave server: 172.16.15.30

1. Install mysql

 
 
  1. # pvcreate /dev/sda5   
  2. # vgcreate myvg /dev/sda5  
  3. # lvcreate -L 10G -n mydata myvg  
  4. # mkdir -p /data/mydata  
  5. # mke2fs -j /dev/myvg/mydata   
  6. # mount /dev/myvg/mydata /data/mydata/  
  7.  
  8. # tar xf mysql-5.5.24-linux2.6-i686.tar.gz  -C /usr/local/  
  9. # cd /usr/local/  
  10. # ln -s mysql-5.5.24-linux2.6-i686/ mysql  
  11. # cd mysql  
  12. # useradd -r mysql  
  13. # chown -R mysql.mysql .  
  14. # scripts/mysql_install_db --datadir=/data/mydata/ --user=mysql 
  15. # chown -R root .  
  16. # cp support-files/my-large.cnf /etc/my.cnf  
  17. # vim /etc/my.cnf   
  18. thread_concurrency = 2 
  19. datadir = /data/mydata  
  20.  
  21. # cp support-files/mysql.server /etc/rc.d/init.d/mysqld  
  22. # chmod +x /etc/rc.d/init.d/mysqld  
  23. # service mysqld start 

2. Configure the master server and add users

 
 
  1. Mysql>Grant replication slave, replication client on *. * TO repluser @ '192. 172.% 'identified by 'redhat ';
  2.  
  3. Mysql>Flush privileges;
  4.  
  5. (Note: You must check the log and log location used later)
  6. Mysql>Show master status;
  7. + ------------------ + ---------- + -------------- + ------------------ +
  8. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  9. + ------------------ + ---------- + -------------- + ------------------ +
  10. |Mysql-bin.000001|335|
  11. + ------------------ + ---------- + -------------- + ------------------ +
  12. 1 row in set (0.00 sec


3. Configure the slave server

 
 
  1. # Vim/etc/my. cnf
  2. Relay-log=Mysql-Relay // Add relay logs
  3. Server-id=2// Modify the ID and the master.
  4.  
  5. # Service mysqld restart takes effect
  6.  
  7. Add the following command
  8. Mysql>CHANGE MASTERMASTER_HOST='2017. 16.15.20', // Specify the master server
  9. -> MASTER_USER='Repluser', // Specify the user
  10. -> MASTER_PASSWORD='Redhat', // Password
  11. -> MASTER_LOG_FILE='Mysql-bin.000001', // Specify the log
  12. -> MASTER_LOG_POS=355; // Specify the log location
  13.  
  14. You can run the following command to view the configuration information:
  15. Mysql>Show slave status \ G
  16.  
  17. Start the slave service thread
  18. Mysql>Start slave;
  19.  
  20. Prohibit write from the server, and restart the service will become invalid.Read_only= On is written into the configuration file:
  21. SET GLOBALRead_only= On;
  22.  
  23. Add the following in the configuration file [mysqld] so that the mysql service of the slave server does not start the slave service thread automatically during startup and starts it manually.
  24. Skip-slave-start=1 

4. Test

 
 
  1. Create data on the master server
  2. Mysql>Create database tb1;
  3. Mysql>Use tb1;
  4. Mysql>Create table test (name varchar (10 ));
  5. Mysql>Insert into test values ('jack'), ('Tom ');

View:

650) this. width = 650; "border = 0>

Then we can see the copied information on the server:

650) this. width = 650; "border = 0>

  • 1
  • 2
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.