标签:thread name tar 一个 mysq rest state 步骤 ddr
192.168.205.17: as master server
192.168.205.27: as slave server
OS: centos 7 1810 with mini install
mariadb-5.5.60
当数据库运行了一段时间后,如何再做主从复制。
1. 配置主服务器
2. 备份主服务器
3. 配置主恢复从服务器
4. 测试
[root@Master ~]#yum install mariadb-server
[root@Master ~]#mkdir /data/{mysql,logs}
[root@Master ~]#chown -R mysql:mysql /data/{mysql,logs}
[root@Master ~]#vi /etc/my.cnf
[mysqld]
server_id=17 #服务器ID必须唯一
datadir=/data/mysql #数据文件路径
log_bin=/data/logs/bin #日志文件路径
[root@Master ~]#systemctl restart mariadb
MariaDB [(none)]> GRANT replication slave on *.* to repluser@‘192.168.205.%‘ identified by ‘centos‘;
[root@Master ~]#mysqldump -A --single-transaction --master-data=1 -F >/data/all.mysql
[root@Master ~]#scp /data/all.mysql 192.168.205.27:/data/
[root@slave ~]#yum install mariadb-server
[root@slave ~]#vi /etc/my.cnf
[mysqld]
datadir=/data/mysql
read-only #只给slave数据只读权限,当然只能限制普通帐号
log-bin=/data/logs/bin
server-id=27 #修改server-id一样和主不一样才行
[root@slave ~]#mkdir /data/{mysql,logs}
[root@slave ~]#chown mysql:mysql /data/{mysql,logs}
[root@salve data]#vi all.mysql
CHANGE MASTER TO
MASTER_HOST=‘192.168.205.17‘,
MASTER_USER=‘repluser‘,
MASTER_PASSWORD=‘centos‘,
MASTER_LOG_FILE=‘bin.000005‘,
MASTER_LOG_POS=245;
[root@slave ~]#systemctl restart mariadb
[root@slave ~]#mysql
MariaDB [(none)]> show variables like ‘server_id‘;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 27 |
+---------------+-------+
1 row in set (0.00 sec)
MariaDB [(none)]> show variables like ‘read_only‘;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only | ON |
+---------------+-------+
1 row in set (0.00 sec)
MariaDB [(none)]> show slave status\G
...
Slave_IO_Running: No
Slave_SQL_Running: No
...
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status\G
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.205.17
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: bin.000005
Read_Master_Log_Pos: 402
Relay_Log_File: mariadb-relay-bin.000003
Relay_Log_Pos: 523
Relay_Master_Log_File: bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hellodb |
| mysql |
| performance_schema |
| test |
| zhaoli |
+--------------------+
6 rows in set (0.00 sec)
[root@slave data]#ss -nt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 96 192.168.205.27:22 192.168.205.1:17526
ESTAB 0 0 192.168.205.27:56360 192.168.205.17:3306
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| hellodb |
| mysql |
| performance_schema |
| test |
| zhaoli |
+--------------------+
7 rows in set (0.00 sec)
标签:thread name tar 一个 mysq rest state 步骤 ddr
原文地址:https://blog.51cto.com/127601/2426639