On the Linux server, when rsync is enabled, MySQL sets master-slave synchronization.

Source: Internet
Author: User
1. Enable rsyncvietcrsyncd. conf on the database server to edit rsync and configure usrbinrsync -- daemon to start rsync2. stop crontab of the log Collection Server

1. Enable rsyncvi/etc/rsyncd. conf on the database server to edit rsync configuration/usr/bin/rsync -- daemon to start rsync2. stop crontab on the log collection server.

1. Enable rsync from the Database Server

Vi/etc/rsyncd. conf

Edit rsync Configuration

/Usr/bin/rsync -- daemon

Start rsync

2. Stop the crontab of the log Collection Server

/Etc/init. d/cron stop

3. Stop the primary database rsync

Ps aux | grep rsync

Kill process number

4. Stop the primary database crontab

/Etc/init. d/cron stop

6. Set a synchronization account from the database in the primary database

Grant replication slave on *. * TO 'name' @ 'IP' identified by 'Password ';

7. Edit master database configuration

Vi/etc/my. cnf

Add under mysqld

[Mysqld]

Log-bin =/home/mysql/log/mysql-bin.log

Server-id = 1

Restart mysql after Configuration

./Bin/mysqladmin-uroot-p shutdown

./Bin/mysqld_safe &

5. log on to the primary database and add a read-only lock.

Flush tables with read lock;

6. Obtain the binary log name and offset

Show master status;

7. Package the primary database files

Tar-cvf data.tar data

8. Restore read/write operations on the master server

Unlock tables;

9. The package is sent to the slave server.

Rsync-ua d name @ ip: modname

10. Stop the slave server mysql

./Bin/mysqladmin-uroot-p shutdown

11. Extract files from the server

Tar-xvf data.tar-C/home/mysql

12. Edit slave server configuration

Vi/etc/my. cnf

Add under mysqld

[Mysqld]

Server-id = 2

The server-id must not be the same as the server-id of the master server.

13. Use the -- skip-slave-start option to start the slave Database

./Bin/mysqld_safe -- skip-slave-start &

14. Configure slave database server to specify the users used for replication, the IP address and port of the master database server, and the log files and locations for starting replication.

CHANGE MASTER

MASTER_HOST = 'IP ',

MASTER_PORT = 3306,

MASTER_USER = 'name ',

MASTER_PASSWORD = 'Password ',

MASTER_LOG_FILE = 'Log name ',

MASTER_LOG_POS = location;

15. Start slave on the slave server

Start slave;

16. view the slave status

Show slave status \ G

,

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.