当前位置:Gxlcms > mysql > Mysql测试二:DRBD+Mysql高可用方案设置测试

Mysql测试二:DRBD+Mysql高可用方案设置测试

时间:2021-07-01 10:21:17 帮助过:18人阅读

测试环境:rhel3.5,drbd 8.0.7,mysql5.0.51-rc-log 1、首先从www.drbd.org下载了源代码包(我下载的8.0.7版本的包) 2、检查主机上面有没有linux的内核源代码,如果没有,需要找到相对应版本的源代码包安装上去。 3、开始安装drbd: 1) 解压:tar -zxvf dr

测试环境:rhel3.5,drbd 8.0.7,mysql5.0.51-rc-log

1、首先从www.drbd.org下载了源代码包(我下载的8.0.7版本的包)

2、检查主机上面有没有linux的内核源代码,如果没有,需要找到相对应版本的源代码包安装上去。

3、开始安装drbd:

1) 解压:tar -zxvf drbd-8.0.7.tar.gz

2) 进入drbd源码目录,根据kernel源码位置来编译drbd:

make KDIR=/usr/src/kernel/ (如果没有更改过内核,可以直接运行make,编译程序会到/lib/module里面去自己根据相关配置寻找到kernel源码)

make install

如果没有报错,应该基本install好了,检查是否生成了相应的文件:/etc/drbd.conf ; /etc/init.d/drbd ; 以及./drbd/drbd.ko

同时系统应该至少多了以下两个命令:drbdadm和drbdsetup

不要删除此源码目录,后面还会用到里面的./scripts/drbd.conf 和 ./drbd/drbd.ko

4、现在可以加载安装drbd模块了

insmod drbd.ko 或者 modprobe drbd

通过lsmod检查是否已经成功

#lsmod |grep drbd

如果有,则表示成功了

5、更改drbd配置文件:

/etc/drbd.conf

[root@mysql1 ha.d]# cat /etc/drbd.conf

on mysql1 {
device /dev/drbd0;
disk /dev/i2o/hda9;
address 10.0.65.45:8888;
flexible-meta-disk internal;
}

on mysql2 {
device /dev/drbd0;
disk /dev/sde2;
address 10.0.65.106:8888;
meta-disk internal;
}

6、primary node设置:

1) 创建matadata:

#drbdadm create-md all

2) 启动drbd:

#/etc/init.d/drbd start

3) 设置为主节点:

#drbdadm — –overwrite-data-of-peer primary all

4) 在新设备上面创建文件系统

#mkfs.ext3 /dev/drbd0

5) 将文件系统mount上

#mkdir /drbddata

#mount /dev/drbd0 /drbddata

7、secondary node设置:

1) 创建matadata:

#drbdadm create-md all

2) 启动drbd:

#/etc/init.d/drbd start

注:这里不要创建文件系统(因为这些信息都会从主节点同步过来的)。

8、primary和secondary节点都配置完并且都启动后,开始检查配置是否成功

1) 检查进程:

a) primary :
[root@mysql1 /]# ps -auxf |grep drbd
Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.3/FAQ
root 5454 0.0 0.0 3744 672 pts/0 S+ 17:36 0:00 \_ grep drbd
root 5389 0.6 0.0 0 0 ? S 17:16 0:07 [drbd0_worker]
root 5403 1.1 0.0 0 0 ? S 17:16 0:14 [drbd0_receiver]
root 5448 0.3 0.0 0 0 ? S 17:35 0:00 [drbd0_asender]

b) secondary:
root@mysql2:/>ps -auxf |grep drbd
Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.3/FAQ
root 5272 0.0 0.0 4752 640 pts/1 S+ 16:27 0:00 \_ grep drbd
root 5168 0.0 0.0 0 0 ? S 16:07 0:00 [drbd0_worker]
root 5182 2.3 0.0 0 0 ? S 16:07 0:29 [drbd0_receiver]
root 5270 1.9 0.0 0 0 ? S 16:25 0:03 [drbd0_asender]

可以看到两个节点的进程都起来了,每个drbd设备会有三个进程:drbd0_worker是drbd0的主要进城,drbd0_asender是 primary上drbd0的数据发送进程,drbd0_receiver是secondary上drbd0的数据接收进程。

2) 查看/dev/drbd文件的输出:

[root@mysql1 /]# cat /proc/drbd
version: 8.0.7 (api:86/proto:86)
GIT-hash: cf14288833afe95db396075f8530a5960d29e498 build by root@mysql1, 2008-03-01 17:02:58
0: cs:SyncSource st:Primary/Secondary ds:UpToDate/Inconsistent C r—
ns:6575584 nr:36 dw:289636 dr:6298278 al:142 bm:515 lo:1 pe:227 ua:30 ap:0
[====>...............] sync’ed: 21.8% (9336/11932)M
finish: 0:52:36 speed: 3,024 (4,176) K/sec
resync: used:1/31 hits:454805 misses:514 starving:0 dirty:0 changed:514
act_log: used:0/257 hits:72258 misses:154 starving:0 dirty:12 changed:142

root@mysql2:/>cat /proc/drbd
version: 8.0.7 (api:86/proto:86)
GIT-hash: cf14288833afe95db396075f8530a5960d29e498 build by root@mysql2, 2008-02-29 21:21:46
0: cs:SyncTarget st:Secondary/Primary ds:Inconsistent/UpToDate C r—
ns:36 nr:5550548 dw:5550552 dr:89 al:2 bm:326 lo:2 pe:97 ua:1 ap:0
[==>.................] sync’ed: 13.5% (10330/11932)M
finish: 0:28:37 speed: 6,148 (4,248) K/sec
resync: used:2/31 hits:391148 misses:451 starving:0 dirty:0 changed:451
act_log: used:0/257 hits:7 misses:2 starving:0 dirty:0 changed:2

输出文件上面最开始是drbd的版本信息,然后就是数据同步的一些状态信息,从mysql的文档上介绍了每一个状态的意思如下:

cs — connection state
st — node state (local/remote)
ld — local data consistency
ds — data consistency
ns — network send
nr — network receive
dw — disk write
dr — disk read
pe — pending (waiting for ack)
ua — unack’d (still need to send ack)
al — access log write count

3) 更进一步验证数据是否同步正确了:

a) 在mysql1上将该文件系统umount,然后执行drbdadm secondary all,改成secondary模式

[root@mysql1 /]# umount /drbddata

[root@mysql1 /]# drbdadm secondary all

b) 在原mysql2 执行drbdadm primary all 改成primary模式,再mount文件系统

root@mysql2:/>drbdadm primary all

root@mysql2:/>mount /dev/drbd0 /drbddata

检查之前在mysql1下写入的文件是否已经完全同步到mysql2下面,经验证,数据已经同步好了

4) 最后连同mysql一起手工测试一次切换:

a) 主节点mysql1下关闭mysql,释放资源,将资源切换成secondary模式:

[root@mysql1 ha.d]# mysqladmin -u root shutdown
[root@mysql1 ha.d]# umount /drbddata
[root@mysql1 ha.d]# drbdadm secondary all

b) 次节点mysql2下获取资源,mount上,切换成primary模式,并启动mysql:

root@mysql2:/root/mysql-5.0.51a>drbdadm primary all
root@mysql2:/root/mysql-5.0.51a>mount /dev/drbd0 /drbddata
root@mysql2:/usr/local/mysql/bin>./mysqld_safe –user=mysql &
[1] 27900
root@mysql2:/usr/local/mysql/bin>Starting mysqld daemon with databases from /drbddata/mysqldata
root@mysql2:/usr/local/mysql/bin>
root@mysql2:/usr/local/mysql/bin>
root@mysql2:/usr/local/mysql/bin>tail -f /drbddata/mysqldata/mysql2.err
080303 13:53:25 mysqld started
080303 13:53:26 InnoDB: Started; log sequence number 0 43656
080303 13:53:26 [Note] /usr/local/mysql/libexec/mysqld: ready for connections.
Version: ‘5.0.51a-log’ socket: ‘/usr/local/mysql/sock/mysql.sock’ port: 3306 Source distribution

c) 登入数据库中检查数据,这里我同时在新的主节点上面测试了写,以便在后面切换回主节点后检查数据是否也正常:

root@mysql2:/usr/local/mysql/bin>mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.51a-log

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| test |
+——————–+
3 rows in set (0.03 sec)

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+—————-+
| Tables_in_test |
+—————-+
| t1 |
| t2 |
| t3 |
+—————-+
3 rows in set (0.00 sec)

mysql> create table t4(id int);
Query OK, 0 rows affected (0.07 sec)

mysql> exit
Bye
root@mysql2:/usr/local/mysql/bin>

d) 再通过之前相同的切换步骤切换回各自原来的模式,启动主节点的mysql,并检查数据:

[root@mysql1 ha.d]# drbdadm primary all

[root@mysql1 ha.d]# mount /dev/drbd0 /drbddata

[root@mysql1 ha.d]# mysqld_safe –user=mysql &
[1] 8451
[root@mysql1 ha.d]# Starting mysqld daemon with databases from /drbddata/mysqldata

[root@mysql1 ha.d]#
[root@mysql1 ha.d]#
[root@mysql1 ha.d]#
[root@mysql1 ha.d]#
[root@mysql1 ha.d]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.51a-log

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+—————-+
| Tables_in_test |
+—————-+
| t1 |
| t2 |
| t3 |
| t4 |
+—————-+
4 rows in set (0.00 sec)

mysql> insert into t4 values(111);
Query OK, 1 row affected (0.01 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from t4;
+——+
| id |
+——+
| 111 |
+——+
1 row in set (0.00 sec)

几个注意点:

1、除了primary节点的文件系统是手工创建的之外,其他的所有secondary节点的文件系统都是通过同步完成的,两边的设备大小好像并不要求完全一样的大小,在我测试的过程中,两边用于drbd设备的分区大小相差很大,但好像并没有出现错误,从drbd相关文档上看到这个并不会导致问题。但是如果主节点比备节点大,而且用的空间也超出了备节点空间大小会有问题,具体会怎样还没有测试到。

2、在mount drbd的设备之前,该节点必须已经设置为primary模式,而且如果一边没有umount,另一边是无法mount上的,直接mount会报如下错误:

root@mysql2:/>mount /dev/drbd0 /drbddata
mount: block device /dev/drbd0 is write-protected, mounting read-only

也就是说,在同步的过程中,只有一个节点的数据可见,也就是不能通过我们人直接简单的查看数据文件等方式之间验证数据是否正常。不过看文档说好像可以通过手动设置一些信息来查看是否正常(You can manually set this information for a number of reasons, including when you want to check the physical status of the secondary device (since you cannot mount a DRBD device in primary mode), or when you are temporarily moving the responsibility of keeping the data in check to a different machine (for example, during an upgrade or physical move of the normal primary node). )。这里的内容等后面再详细研究一下。

人气教程排行