Linux伺服器開啟rsync下MySQL設定主從同步的過程

來源:互聯網
上載者:User

1.從資料庫伺服器開啟rsync

vi /etc/rsyncd.conf

編輯rsync配置

/usr/bin/rsync --daemon

啟動rsync

2.停止日誌收集伺服器的crontab

/etc/init.d/cron stop

3.停止主要資料庫rsync

ps aux |grep rsync

kill 進程號

4.停止主要資料庫crontab

/etc/init.d/cron stop

6.在主要資料庫設定從資料庫的同步帳號

GRANT REPLICATION SLAVE ON *.* TO 'name'@'ip' IDENTIFIED BY 'password';

7.編輯主要資料庫配置

vi /etc/my.cnf

在mysqld下增加

[mysqld]

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

server-id = 1

配置完需要重啟mysql

./bin/mysqladmin -uroot -p shutdown

./bin/mysqld_safe &

5.登入主要資料庫,加上唯讀鎖

flush tables with read lock;

6.擷取二進位日誌名和位移量

show master status;

7.將主要資料庫資料庫檔案打包

tar -cvf data.tar data

8.恢複主伺服器讀寫操作

unlock tables;

9.打包完發送至從伺服器

rsync -ua d name@ip::modname

10.停止從伺服器mysql

./bin/mysqladmin -uroot -p shutdown

11.從伺服器解壓檔案

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

12.編輯從伺服器配置

vi /etc/my.cnf

在mysqld下增加

[mysqld]

server-id = 2

其中server-id不要和主伺服器的server-id重複

13.使用--skip-slave-start選項啟動從資料庫

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

14.對從資料庫伺服器做相應設定,指定複製使用的使用者,主要資料庫伺服器的IP、連接埠以及開始執行複製的記錄檔和位置

CHANGE MASTER TO

MASTER_HOST='ip',

MASTER_PORT=3306,

MASTER_USER='name',

MASTER_PASSWORD='password',

MASTER_LOG_FILE='日誌名',

MASTER_LOG_POS=位置;

15.在從伺服器上,啟動slave

start slave;

16.查看slave狀態

show slave status\G

相關文章

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.