Building your Master-Slave Server On Ubuntu 14.04

Step 0 Preparation

  1. Make sure you have two ubuntu systems with mysql installed.
  2. The master server is the main server, which is daily in use. and the slave server means a backup server.
  3. Modify /etc/mysql/my.cnf in both master and slave servers and uncomment #bind-address to make remote access possible.
  4. Use mysql -u root -p to login the master server and authorize with grant replication slave,reload,super on *.* to ${username} @${slave server ip} identified by '${pwd}';

Note: You can test with mysql -u ${username} -h ${master server ip} -p on your slave server machine.

Step 1 Set up Master Server

  1. Run sudo nano /etc/mysql/my.cnf and modify the file like (default commented)
    server-id               = 100

    log_bin                 = /var/log/mysql/mysql-bin.log

    binlog_do_db            = ${the db name you want to configure}

    binlog_ignore_db        = mysql
  1. Run service mysql restart to restart msyql service.
  2. Use mysql -u root -p to login mysql and enter show master status; and you may see
mysql>show master status;
   +------------------+----------+--------------+------------------+
   | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
   +------------------+----------+--------------+------------------+
   | mysql-bin.000001 |      107 |              |                  |
   +------------------+----------+--------------+------------------+
   1 row in set (0.00 sec)
    Please remember the File and Position.

Step 2 Set up Slave Server

  1. Run sudo nano /etc/mysql/my.cnf and modify the file like (default commented)
    server-id               = 111

    log_bin                 = /var/log/mysql/mysql-bin.log

    binlog_do_db            = ${the db name you want to configure}

    binlog_ignore_db        = mysql
  1. Run service mysql restart to restart msyql service.
  2. Use mysql -u root -p to login mysql and run stop slave;
  3. Enter
change master to master_host='${master server ip}',master_user='${username}',master_password='${pwd}',master_log_file='${File}',master_log_pos=${Position};
  1. Then start slave by start slave;
  2. Run show slave status; to test whether successfully configure. You may see as
    Slave_IO_Running: Yes 
    Slave_SQL_Running: Yes 
    if these two show YES, well done!
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容