Test environment: rhel3.5, drbd8.0.7, mysql5.0.51-rc-log1, first download the source code package from www.drbd.org (I downloaded the 8.0.7 package) 2. check whether there is linux kernel source code on the host, if not, find the corresponding version of the source code package to install it. 3. Start to install drbd: 1) unzip: tar-zxvfdr
Test environment: rhel3.5, drbd 8.0.7, mysql5.0.51-rc-log 1. First download the source code package from www.drbd.org (my downloaded version 8.0.7 package) 2. check whether there is any linux kernel source code on the host. If not, find the corresponding version of the source code package and install it. 3. Start to install drbd: 1) unzip: tar-zxvf dr
Test environment: rhel3.5, drbd 8.0.7, mysql5.0.51-rc-log
1. Download the source code package from www.drbd.org)
2. check whether there is any linux kernel source code on the host. If not, find the corresponding version of the source code package and install it.
3. Start to install drbd:
1) unzip: tar-zxvf drbd-8.0.7.tar.gz
2) Go To The drbd source code directory and compile drbd Based on the kernel source code location:
Make KDIR =/usr/src/kernel/(if the kernel has not been changed, you can directly run make, compile the program to/lib/module and find the kernel source code based on the relevant configuration)
Make install
If no error is reported, install it and check whether the corresponding file is generated:/etc/drbd. conf;/etc/init. d/drbd; and. /drbd. ko
At the same time, the system should have at least two additional commands: drbdadm and drbdsetup
Do not delete this source code directory. The./scripts/drbd. conf and./drbd. ko files will be used later.
4. Now you can load and install the drbd module.
Insmod drbd. ko or modprobe drbd
Use lsmod to check whether the operation is successful
# Lsmod | grep drbd
If yes, the operation is successful.
5. Modify the drbd configuration file:
/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 settings:
1) Create matadata:
# Drbdadm create-md all
2) Start drbd:
#/Etc/init. d/drbd start
3) set as the master node:
# Drbdadm--overwrite-data-of-peer primary all
4) create a file system on the new device
# Mkfs. ext3/dev/drbd0
5) mount the File System
# Mkdir/drbddata
# Mount/dev/drbd0/drbddata
7. secondary node settings:
1) Create matadata:
# Drbdadm create-md all
2) Start drbd:
#/Etc/init. d/drbd start
Note: Do not create a file system here (because the information will be synchronized from the master node ).
8. After the primary and secondary nodes are configured and started, check whether the configuration is successful.
1) Check the process:
A) primary:
[Root @ mysql1/] # ps-auxf | grep drbd
Warning: bad syntax, perhaps a bogu '-'? See/usr/share/doc/procps-3.2.3/FAQ
Root 5454 0.0 0.0 3744 672 pts/0 S + \ _ grep drbd
Root 5389 0.6 0.0 0 0? S [drbd0_worker]
Root 5403 1.1 0.0 0 0? S [drbd0_receiver]
Root 5448 0.3 0.0 0 0? S [drbd0_asender]
B) secondary:
Root @ mysql2:/> ps-auxf | grep drbd
Warning: bad syntax, perhaps a bogu '-'? See/usr/share/doc/procps-3.2.3/FAQ
Root 5272 0.0 0.0 4752 640 pts/1 S + \ _ grep drbd
Root 5168 0.0 0.0 0 0? S [drbd0_worker]
Root 5182 2.3 0.0 0 0? S [drbd0_receiver]
Root 5270 1.9 0.0 0 0? S [drbd0_asender]
We can see that the processes on both nodes are up, and each drbd device has three processes: drbd0_worker is the main city of drbd0, and drbd0_asender is the data sending process of drbd0 on primary, drbd0_receiver is the data receiving process of drbd0 on secondary.
2) view the output of the/dev/drbd file:
[Root @ mysql1/] # cat/proc/drbd
Version: 8.0.7 (api: 86/proto: 86)
GIT-hash: cf14288833afe95db396075f8530a5960d29e498 build by root @ mysql1, 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
The output file first contains the version information of drbd, and then some status information of data synchronization. The meaning of each status is described in the mysql document as follows:
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) further verify whether the data synchronization is correct:
A) On mysql1, run the file system umount, run drbdadm secondary all, and change it to secondary mode.
[Root @ mysql1/] # umount/drbddata
[Root @ mysql1/] # drbdadm secondary all
B) Run drbdadm primary all in the original mysql2 to change to the primary mode, and then mount the file system.
Root @ mysql2:/> drbdadm primary all
Root @ mysql2:/> mount/dev/drbd0/drbddata
Check whether the files written in mysql1 have been fully synchronized to mysql2. After verification, the data has been synchronized.
4) Finally, manually test the switchover together with mysql:
A) Close mysql under mysql1 on the master node, release resources, and switch resources to secondary mode:
[Root @ mysql1 ha. d] # mysqladmin-u root shutdown
[Root @ mysql1 ha. d] # umount/drbddata
[Root @ mysql1 ha. d] # drbdadm secondary all
B) obtain resources under the next node mysql2, mount the resource, switch to the primary mode, and start 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) log on to the database and check the data. Here I also tested the Data Writing on the new master node to check whether the data is normal after switching back to the master node:
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-
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) switch back to the original mode through the same previous switching steps, start mysql on the master node, and check the data:
...
[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-
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 |
+ -- +
| 1, 111 |
+ -- +
1 row in set (0.00 sec)
Notes:
1. Except that the file system of the primary node is manually created, the file systems of all other secondary nodes are synchronized. The device sizes on both sides do not seem to require the same size, during my testing, the partition sizes used for the drbd Device on both sides vary greatly, but it seems that there is no error. This does not cause any problems from the drbd documentation. However, if the master node is larger than the slave node, and the space used exceeds the size of the slave node, the problem may occur. How can this problem be solved.
2. Before you mount a drbd device, the node must have been set to the primary mode. If there is no umount on one side and the other side cannot be mounted, the following error will be reported if you mount the node directly:
Root @ mysql2:/> mount/dev/drbd0/drbddata
Mount: block device/dev/drbd0 is write-protected, mounting read-only
That is to say, during the synchronization process, only the data of one node is visible, that is, we cannot simply check the data files and verify whether the data is normal. However, it seems that You can manually set some information to check whether it is normal (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 ).). The content here will be studied in detail later.
Original article address: Mysql Test 2: DRBD + Mysql high-availability solution Setup test. Thank you for sharing it with me.