6.开启另一个终端,对主数据库做快照
|
1
2
|
[root@Test01 mysql]#tar -zcvf backup.tar.gz www blog |
7.库解锁
|
1
|
mysql> unlock tables; |
从节点:
1.安装mysql,方法同上,不在赘述。
2.修改My.cnf配置文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
[root@Test02 mysql]# vi /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0log-bin=mysql-binserver-id = 2#master-host = 192.168.1.10#master-user = root#master-password = 584911644#master-port = 3306#master-log-pos = 196#master-log-file = mysql-bin.000001#master-connect-retry=60replicate-do-db=www //告诉slave只做www数据库的更新replicate-do-db=blog //告诉slave只做blog数据库的更新log-slave-updates[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid"/etc/my.cnf" 23L, 551C |
3.把之前主数据库压缩的数据拷贝到对应位置
我这里用的是SecureFX,当然,方法很多,也不细说了,可谓是条条大路通罗马。
4.启动数据库
|
1
|
[root@Test02 mysql]# service mysqld start |
|
1
|
Starting mysqld: [ OK ] |
5.配置,启动Slave
注意:Slave_IO_Running:是否要从 Master Server 复製 Binary Log 资料,必须为 Yes。Slave_SQL_Running:是否要执行从 Master Server 复製过来的 Binary Log 资料,必须为 Yes。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
mysql> slave stop;Query OK, 0 rows affected (0.00 sec)mysql> change master to master_host='192.168.1.10',master_user='repl',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=196;Query OK, 0 rows affected (0.04 sec)mysql> slave start;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.1.10 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 339 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 394 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: www,blog Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 339 Relay_Log_Space: 550 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error:1 row in set (0.00 sec) |
四)后期测试
主节点-数据增加:
|
1
2
3
4
5
6
7
8
9
10
|
mysql> insert into www values(2);Query OK, 1 row affected (0.00 sec)mysql> select * from www;+------+| id |+------+| 1 || 2 |+------+2 rows in set (0.00 sec) |
从节点数据同步验证:
|
1
2
3
4
5
6
7
8
|
mysql> select * from www;+------+| id |+------+| 1 || 2 |+------+2 rows in set (0.00 sec) |
主节点-数据删除:
|
1
2
3
4
5
6
7
8
9
|
mysql> delete from www where id ='2';Query OK, 1 row affected (0.04 sec)mysql> select * from www;+------+| id |+------+| 1 |+------+1 row in set (0.00 sec) |
从节点数据同步验证:
|
1
2
3
4
5
6
7
|
mysql> select * from www;+------+| id |+------+| 1 |+------+1 row in set (0.00 sec) |
综述:
Test02,从数据库上能做到同步数据库的更新操作,目前是WWW和blog两张表。当然,这里只是抛砖引玉的作用,大家可以举一反三,根据自己实际需求,做出最好的环境搭建��配置。
最近在弄RHCS和keepalived,闲来有空就记录几笔数据库slave配置,方便大家学习和自己的积累。
