机器 | 角色 |
---|
cdh001 | master 写服务 |
cdh002 | slave 读服务 |
- 两台机器分别部署MySQL
- 修改
/etc/my.cnf
中的server-id
,两个MySQL必须不同。 - master节点:
su - mysqladmin
mysql -uroot -p
mysql> grant replication slave on *.* to repluser@'%' identified by 'password';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 1025 | | | |
+------------------+----------+--------------+------------------+-------------------+
- slave节点
su - mysqladmin
cd /usr/local/mysql
mkdir relay_log
mysql -uroot -p
mysql> change master to
-> master_host='masterIP',
-> master_port=3306,
-> master_user='repluser',
-> master_password='password',
-> master_log_file='mysql-bin.000003',
-> master_log_pos=1025;
mysql> start slave;
mysql> show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes