A Environment description
OS environment: CentOS 5.5 x86_64 (development environment)
DRBD version:
Drbd83-8.3.13-2.el5.centos.x86_64
Kmod-drbd83-8.3.13-1.el5.centos.x86_64
MySQL version: MySQL 5.5.28
Keepalived version: keepalived-1.1.19-1.i386.rpm
drbd3:192.168.0.96
drbd4:192.168.0.97
drbd_vip:192.168.0.100
Two DRBD deployment
A) define host name
# vim/etc/hosts
192.168.0.96 drbd3
192.168.0.97 Drbd4
b) Create a partition
Create two 10G size partitions on drbd3 and Drbd4, with no file system formatting for partitions
c) Yum Deployment DRBD
Yum-y Install drbd83* kmod-drbd83
d) Configuring DRBD
# vim/etc/drbd.conf
global{
Usage-count No; #这个问你让不让官网统计
}
Common {
syncer {rate 100M;} #传输速度
}
Resource R0 {
Protocol C; #传输协议 (protocol description below)
startup {
}
Disk {
On-io-error detach;
}
NET {#处理脑裂方法 (explained below)
Cram-hmac-alg "SHA1"; #两台服务器通信间的算法
Shared-secret "Foofunfactory";
# After-sb-0pri Disconnect;
# After-sb-1pri Disconnect;
# After-sb-2pri Disconnect;
After-sb-0pri discard-younger-primary;
After-sb-1pri discard-secondary;
After-sb-2pri CALL-PRI-LOST-AFTER-SB;
Rr-conflict Disconnect;
}
Syncer {
Rate 100M;
Al-extents 257;
}
On drbd3{#这里一定要是hosts定义的名称
device/dev/drbd0; #逻辑设备路径
Disk/dev/hda3; #真实设备路径
Address 192.168.0.96:7789;
Meta-disk internal;
}
On drbd4{
device/dev/drbd0;
Disk/dev/hda3;
Address 192.168.0.97:7789;
Meta-disk internal;
}
}
Execute on DRBD3:
Drbdadm CREATE-MD r0 (Create a data block for the DRBD record information, which will normally be prompted below)
Writing Meta Data ...
Initializing activity log
Not initialized bitmap
New DRBD Meta data block successfully created.
Performed on Drbd4: Drbdadm create-md r0
#/etc/init.d/drbd start service, 2 machines are started, this start sometimes you have to fill in Yes
Execute on DRBD3: Drbdadm----Overwrite-data-of-peer primary r0 set as primary node
Mkfs.ext3/dev/drbd0
Mount/dev/drbd0/data
Test:
On the DRBD3:
cd/data/
Touch test
Umount/dev/drbd0
Drbdadm secondary R0
Execute on DRBD4:
DRBDADM Primary R0
mount/dev/drbd0/data/
Description of the DRBD protocol:
A protocol: Once the data is written to the disk and sent to the network, it is considered to have completed the write operation
B Protocol: Receive acknowledgement is considered to have completed the write operation
C Protocol: A write acknowledgement is received that the write operation is completed
DRBD NET handles brain crack Description:
Three processes for a DRBD device:
Each DRBD device has three processes:
1) Drbd0_worker is the main process of drbd0
2) Drbd0_asender is the data sending process of DRBD0 on primary
3) Drbd0_receiver is the data write process for drdb0 on secondary
Some points to note about DRBD:
1) The Mount DRBD device must have previously switched the device to the primary state
2) Two nodes, only one is in primary state at the same time, and the other is secondary state
3) nodes in the secondary state cannot be mounted
4) It is best to use partitions of the same size as the main preparation.
When using DRBD, it is recommended to use the InnoDB storage engine while opening the Binlog log and setting the Innodb_flush_log_at_commit=1. The MyISAM storage engine is prone to data loss and file corruption on DRBD.
DRBD after brain fissure treatment:
On the DRDB4.
Drbdadm secondary R0
Drbdadm-–discard-my-data Connect R0
Drbdadm Connect R0
On the drbd3.
Drbdam Disconnect R0
Drbdadm Connect R0
Three MySQL Deployment
To add a MySQL user:
Useradd Mysql–s/sbin/nologin
To install the CMake tool:
wget http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz
Tar zxfv cmake-2.8.7.tar.gz
CD cmake-2.8.7
./configure && make && make install
Install MySQL
Tar zxfv mysql-5.5.28.tar.gz
Cd.. /mysql-5.5.28
Cmake-dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/data/3306-dwith_innobase_storage_engine=on-dmysql _tcp_port=3306-dmysql_unix_addr=/data/3306/my
Sqld.sock-denabled_local_infile=1-dextra_charsets=all-ddefault_charset=utf8-ddefault_collation=utf8_general_ci -dsysconfdir=/etc/mysql/3306 && make && make install
cd/usr/local/mysql/
Chown-r MySQL.
Chgrp-r MySQL.
scripts/mysql_install_db--user=mysql--datadir=/data/3306
Create a PID and authorize
CP Support-files/mysql.server/etc/init.d/mysqld
Four Keepalived deployment
Deployment keepalived:
RPM-IVH keepalived-1.1.19-1.i386.rpm
The configuration file on Drbd3 is as follows:
-----------------/etc/keepalived/keepalived.conf-----------------
! Configuration File for Keepalived
Global_defs {
router_id 192.168.0.96
}
Vrrp_script Chk_mysql {
Script "/etc/keepalived/check_mysql.sh"
Interval 5
Weight-10
}
Vrrp_instance Vi_1 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 52
Priority 100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.0.100
}
Track_script {
Chk_mysql
}
}
---------------------------------check_mysql.sh----------------------------------------
#!/bin/bash
A= ' ps-c mysqld--no-header |wc-l '
If [$A-eq 0];then
/bin/umount/data/
Drbdadm secondary R0
Killall keepalived
Fi
------------------------------------------to_master.sh--------------------------------------------
#!/bin/bash
DRBDADM Primary R0
/bin/mount/dev/drbd0/data/
/etc/init.d/mysqld start
The configuration file on Drbd4 is as follows:
-----------------/etc/keepalived/keepalived.conf-----------------
! Configuration File for Keepalived
Global_defs {
router_id 192.168.0.97
}
Vrrp_sync_group vi{
Group {
Vi_1
}
notify_master/etc/keepalived/to_master.sh
notify_backup/etc/keepalived/to_backup.sh
}
Vrrp_instance Vi_1 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 52
Priority 90
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.0.100
}
}
------------------------------------------to_master.sh--------------------------------------------
#!/bin/bash
DRBDADM Primary R0
/bin/mount/dev/drbd0/data/
/etc/init.d/mysqld start
------------------------------------------to_backup.sh-------------------------------------------
#!/bin/bash
/etc/init.d/mysqld stop
/bin/umount/dev/drbd0
Drbdadm secondary R0
Mysql+drbd+keepalived