設定 mysql 成 master / slave 架構

準備兩台 mysql server , 用 vmware ESX server , clone 了兩台出來 , 也順便把 dbs 的 aggregator 弄了一套在上面
e2e8905137d0c2753f1eb106aa59eee4

  1. 加個 master 端的 repl 帳號 , 只允許 REPLICATION SLAVE 權限
    GRANT REPLICATION SLAVE ON *.* TO ‘repl’@’%’ IDENTIFIED BY ‘xxxxxx’;
    — 小心 % 要改一下!
  2. Setting the Replication Master Configuration 改 master 的 /etc/my.cnf 檔
    [mysqld]
    log-bin=mysql-bin
    server-id=1
  3. Setting the Replication Slave Configuration 改 slave 的 /etc/my.cnf 檔 , 主要是設 server-id , 把那個 log-bin=mysql-bin 註解掉
  4. 把 master 要 replication 的 database 搬一份到 slave

    in master server:

    cd /var/lib/mysql

    tar cf – db_item/ | ssh [email protected] ‘cd /var/lib/mysql/ ; tar xf –’

    ( 172.30.0.183 是此例的 slave )

  5. Setting Up Replication with New Master and Slaves
  6. unlock master

    in master:

    unlock tables;

  7. startup slave ,

    execute change master to command:

    change master to master_host=’172.30.0.182′ , master_user=’repl’ , master_password=’xxxxx’ , master_log_file=’mysql-bin.000005′, master_log_pos=791;

  8. in slave:

    start slave;
  9. done!