十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
主节点上线运行了一段时间后,数据量日益增大,故需要添加slave节点来更好地支撑业务的发展。但是,此时也有一定量的用户了,所以不能把主节点停机,而是在不停机的情况下添加slave节点,具体实现方法如下:
成都创新互联公司是一家专注于成都网站制作、做网站与策划设计,祁连网站建设哪家好?成都创新互联公司做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:祁连等地区。祁连做网站价格咨询:13518219792master | slave | |
---|---|---|
IP | 192.168.7.71 | 192.168.7.72 |
主机名 | master01 | slave01 |
OS | CentOS7 | CentOS7 |
MySQL版本 | 5.7.28 | 5.7.28 |
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| db2 |
| mysql |
| performance_schema |
| sys |
+--------------------+
[root@master01 ~]#mysqldump -p -A -F --single-transaction --master-data=1 > /backup/fullbackup_`date +%F_%T`.sql
Enter password:
[root@master01 ~]#ll /backup/
total 832
-rw-r--r-- 1 root root 849153 Nov 29 20:22 fullbackup_2019-11-29_20:22:04.sql
[root@master01 ~]#scp -p /backup/fullbackup_2019-11-29_20\:22\:04.sql root@192.168.7.72:/data/
fullbackup_2019-11-29_20:22:04.sql 100% 829KB 14.9MB/s 00:00
grant replication slave on *.* to repluser@'192.168.7.%' identified by '123.com';
[mysqld]
server-id = 2
read_only = ON #设为只读,但是对超级用户无效。
[root@slave01 ~]#mysql -p < /data/fullbackup_2019-11-29_20\:22\:04.sql
Enter password:
[root@slave01 ~]#mysql -p -e "show databases"
Enter password:
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| db2 |
| mysql |
| performance_schema |
| sys |
+--------------------+
[root@slave01 ~]#grep '^CHANGE MASTER' /data/fullbackup_2019-11-29_20\:22\:04.sql
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=154;
[root@slave01 ~]#mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
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.000003',
-> MASTER_LOG_POS=154;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
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.000003
Read_Master_Log_Pos: 154
Relay_Log_File: slave01-relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...省略信息...
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。