網(wǎng)站建設哪家好,找成都創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、小程序制作、集團企業(yè)網(wǎng)站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了雙牌免費建站歡迎大家使用!
master | slave | |
---|---|---|
IP | 192.168.7.71 | 192.168.7.72 |
主機名 | master01 | slave01 |
OS | CentOS7 | CentOS7 |
MySQL版本 | 5.7.28 | 5.7.28 |
略
# vim /etc/my.cnf
[mysqld]
log-bin = mysql-bin
server-id = 1
# 重啟服務
systemctl start mysqld
grant replication slave on *.* to repluser@'192.168.7.%' identified by '123.com';
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
[mysqld]
server-id = 2
read_only = ON #設為只讀,但是對超級用戶無效。
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.7.71',
-> MASTER_USER='repluser',
-> MASTER_PASSWORD='123.com',
-> MASTER_PORT=3306,
-> MASTER_LOG_FILE='mysql-bin.000001',
-> MASTER_LOG_POS=154;
mysql> start slave;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.7.71
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 154
Relay_Log_File: slave01-relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...省略信息...
master.info:用于保存slave連接至master時的相關信息,例如賬號、密碼、服務器地址等
relay-log.info:保存在當前slave節(jié)點上已經(jīng)復制的當前二進制日志和本地relay log日志的對應關系