Building your Master-Slave Serve

2017-04-19  本文已影响0人  等流心0316

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!
上一篇 下一篇

猜你喜欢

热点阅读