1.1 环境准备
1.1.1 添加新磁盘,分区并格式化
fdisk -uc /dev/sdb
mkfs.ext4 /dev/sdb1
dd if=/dev/zero of=/dev/sdb1bs=1M count=1
1.1.2 在hosts文件中添加以下记录
cat /etc/host
172.16.1.111 test01
172.16.1.112 test02
172.16.1.113 web
1.1.3 关闭selinux和iptables
setenforce 0
/etc/init.d/iptables stop
1.1.4 测试约定
主机名,系统版本及内核版本:
[root@test01 ~]# uname -nr
test01 2.6.32-573.el6.x86_64
[root@test01 ~]# cat /etc/RedHat-release
CentOS release 6.7 (Final)
[root@test02 ~]# uname -nr
test02 2.6.32-573.el6.x86_64
[root@test02 ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[root@web ~]# uname -nr
web 2.6.32-573.el6.x86_64
[root@web ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
测试IP:
test01 172.16.1.111
test02 172.16.1.112
web 172.16.1.113
虚拟IP 172.16.1.100
1.2 DRBD的安装
1.2.1 配置DRBD
默认官方源中没有drbd软件,所以使用elrepo源
[root@test01 ~]# rpm --importhttps://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@test01 ~]# rpm -Uvh
Retrieving
Preparing... ########################################### [100%]
1:elrepo-release ########################################### [100%]
[root@test01 ~]# yum installdrbd84-utils kmod-drbd84 -y
[root@test01 ~]# modprobe drbd
[root@test01 ~]# lsmod|grepdrbd
drbd 365931 0
libcrc32c 1246 1 drbd
编辑配置文件
[root@test01 ~]# vim/etc/drbd.conf
# You can find an examplein /usr/share/doc/drbd.../drbd.conf.example
#include"drbd.d/*.res";
global{
usage-count no;
}
common{
syncer{
rate 200M;
}
}
resource r1 {
protocol C;
startup{
wfc-timeout 120;
degr-wfc-timeout 120;
}
disk {
on-io-error detach;
}
net {
timeout 60;
connect-int 10;
ping-int 10;
max-buffers 2048;
max-epoch-size 2048;
cram-hmac-alg"sha1";
shared-secret"Mysql-abcD";
}
on test01 {
device /dev/drbd0;
disk /dev/sdb1;
address 172.16.1.31:6666;
meta-disk internal;
}
on test02 {
device /dev/drbd0;
disk /dev/sdb1;
address 172.16.1.41:6666;
meta-disk internal;
}
}
1.2.3 初始化设
[root@test01 ~]# drbdadmcreate-md r1
initializing activity log
NOT initializing bitmap
Writing meta data...
New drbd meta data blocksuccessfully created.
[root@test01 ~]# drbdadm up r1
[root@test01 ~]# cat /proc/drbd
version: 8.4.6(api:1/proto:86-101)
GIT-hash:833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-0914:35:00
0: cs:Connected ro:Secondary/Secondaryds:Inconsistent/Inconsistent C r-----
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0ua:0 ap:0 ep:1 wo:f oos:5241660
现在两个节点都处于Secondary状态
将test01手动提升至primary。并将/dev/drbd0进行格式化以供挂在使用
[root@test01 ~]# drbdadmprimary --force r1
[root@test01 ~]# cat/proc/drbd
version: 8.4.6(api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70build by root@test01, 2015-12-07 10:40:31
0: cs:Connected ro:Primary/Secondaryds:UpToDate/UpToDate C r-----
ns:1047484 nr:0 dw:0 dr:1048148 al:0 bm:0lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
1.2.4 格式化虚拟分区