drbd构建篇

  DRBD简介
DRBD(Distributed Replicated Block Device),分布式复制块设备,是一种通过TCP/IP网络实现块设备数据实时镜像的方案。利用这种方案,单一主节点模式(single primary mode)双机系统能够实时地将业务数据保存在主备节点的磁盘中,正常情况下两个节点的数据是一模一样的。
根据官方的说明文档,如果系统内核(linux)版本低于2.6.33,在安装软件之前需要加载DRBD模块,如果高于(或等于)2.6.33,则只安装客户端软件。
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
配置需求:
两台Linux主机
node1:192.168.112.139  (两块SCSI硬盘), 并划分一个新的独立分区。/dev/sdb1
node2:192.168.112.130  (两块SCSI硬盘),并划分一个新的独立分区。/dev/sdb1
 
以下操作在2台机器同时执行:
[root@Jiechao ~]# /usr/sbin/ntpdate pool.ntp.org
[root@Jiechao ~]# echo '*/10 * * * * /usr/sbin/ntpdate pool.ntp.org'>>/var/spool/cron/root
[root@Jiechao ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               Jiechao localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.112.129 node1
192.168.112.130 node2
--------------------------------------------------------------------------------------------------------------------------
在node1节点上操作:
vi /etc/sysconfig/network
把HOSTNAME=Jiechao 改为:HOSTNAME=node1
在node2节点上操作:
vi /etc/sysconfig/network
把HOSTNAME=JieC 改为:HOSTNAME=node2
node1和node2节点主机改为hostname,并重启系统。
[root@Jiechao ~]# reboot
 
Broadcast message from root (pts/1) (Wed Dec 21 05:18:49 2011):
 
The system is going down for reboot NOW!
----------------------------------------------------------------------------------------------------------------------------
为node1,node2节点划分一个新的独立分区:(2台机器必须执行)
[root@node1 ~]# fdisk /dev/sdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
 
 
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
Command (m for help): n   #添加一个分区
Command action
   e   extended
   p   primary partition (1-4)
p                  #查看硬盘现有哪些分区,现在查看应该还无分区
Partition number (1-4): 1     #分区1
First cylinder (1-2610, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): 200
 
Command (m for help): w    #把创建好的分区写入磁盘表
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
安装drbd。
2台机器上共同执行以下操作:
 
[root@node1 ~]# yum install -y drbd83 kmod-drbd83
[root@node1 ~]# modprobe drbd
[root@node1 ~]# lsmod |grep drbd
drbd                  228528  0 
 
[root@node1 ~]# cat /etc/drbd.conf 
#
# please have a a look at the example configuration file in
# /usr/share/doc/drbd83/drbd.conf
global { usage-count yes; }
common { syncer { rate 10M; } }
resource db {
        protocol C;
        net {
        }
        on node1 {
                device    /dev/drbd0;
                disk      /dev/sda1;
                address   192.168.112.129:7789;
                meta-disk  internal;
        }
        on node2 {
                device    /dev/drbd0;
                disk      /dev/sda1;
                address   192.168.112.130:7789;
                meta-disk  internal;
        }
}
 
创建drbd源
[root@node1 ~]# drbdadm create-md db
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
success
[root@node1 ~]# netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:738                 0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:199               0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0    132 192.168.112.129:22          192.168.112.1:4609          ESTABLISHED 
DRBD的启动、关闭以及测试
[root@node1 ~]#  /etc/init.d/drbd start
Starting DRBD resources: [ 
db
Found valid meta data in the expected location, 1645019136 bytes into /dev/sdb1.
d(db) s(db) n(db) ]..........
***************************************************************
[root@node2 ~]#  /etc/init.d/drbd start
Starting DRBD resources: [ 
db
Found valid meta data in the expected location, 1645019136 bytes into /dev/sdb1.
d(db) s(db) n(db) ]..........
***************************************************************
[root@node1 ~]# cat /proc/drbd 
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by [email protected], 2010-06-04 08:04:16
 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r----
    ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:1606380
[root@node2 ~]# cat /proc/drbd 
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by [email protected], 2010-06-04 08:04:16
 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r----
    ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:1606380
--------------------------------------------------------------------------------------------------------------------------------------
设置主机:在node1执行:
[root@node1 ~]# drbdsetup /dev/drbd0 primary -o
[root@node1 ~]#  cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by [email protected], 2010-06-04 08:04:16
 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----
    ns:72704 nr:0 dw:0 dr:72704 al:0 bm:4 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:1533676
        [>....................] sync'ed:  4.9% (1533676/1606380)K delay_probe: 11
        finish: 0:02:27 speed: 10,384 (10,384) K/sec
------------------------------------------------------------------------------------------------------------------------------------------------
测试:
主节点磁盘操作(node1节点)
[root@node1 ~]# mkfs.ext3 /dev/drbd0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
200928 inodes, 401595 blocks
20079 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=415236096
13 block groups
32768 blocks per group, 32768 fragments per group
15456 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912
 
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
 
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
 
[root@node1 ~]#  mkdir /drbd
[root@node1 ~]# mount /dev/drbd0 /drbd
[root@node1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      9.5G  1.3G  7.8G  14% /
/dev/mapper/VolGroup00-LogVol03
                      2.9G   69M  2.7G   3% /home
/dev/mapper/VolGroup00-LogVol02
                      2.9G   69M  2.7G   3% /opt
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 125M     0  125M   0% /dev/shm
/dev/drbd0            1.6G   35M  1.4G   3% /drbd
[root@node1 ~]# cd /drbd/
[root@node1 drbd]# ll
total 16
drwx------ 2 root root 16384 Dec 25 01:17 lost+found
[root@node1 drbd]# mkdir test
[root@node1 drbd]# cd test/
[root@node1 test]# cat jc.cf 
this is node1 test.
[root@node1 test]# cd /
[root@node1 /]# umount /drbd/
[root@node1 /]# drbdsetup 0 secondary
-----------------------------------------------------------
启用备机磁盘:在node2节点主机上操作:
[root@node2 ~]# drbdadm primary db
[root@node2 ~]# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by [email protected], 2010-06-04 08:04:16
m:res  cs         ro                 ds                 p  mounted  fstype
0:db   Connected  Primary/Secondary  UpToDate/UpToDate  C
[root@node2 ~]# mkdir /drbd
[root@node2 ~]#  mount /dev/drbd0 /drbd
[root@node2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      9.5G  1.4G  7.6G  16% /
/dev/mapper/VolGroup00-LogVol03
                      2.9G   97M  2.6G   4% /opt
/dev/mapper/VolGroup00-LogVol02
                      2.9G   69M  2.7G   3% /home
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 125M     0  125M   0% /dev/shm
/dev/drbd0            1.6G   35M  1.4G   3% /drbd
[root@node2 ~]#  cd /drbd
[root@node2 drbd]# ll
total 20
drwx------ 2 root root 16384 Dec 25 01:17 lost+found
drwxr-xr-x 2 root root  4096 Dec 25 01:20 test
[root@node2 drbd]# cd test/
[root@node2 test]# cat jc.cf 
this is node1 test.
 
呵呵。结果已经出来了。证明DRBD已经配置成功。

你可能感兴趣的:(安装,primary,休闲,设备,客户端软件)