Chinaunix首页 | 论坛 | 博客
  • 博客访问: 504176
  • 博文数量: 240
  • 博客积分: 791
  • 博客等级: 军士长
  • 技术积分: 1694
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-23 18:21
文章分类

全部博文(240)

文章存档

2013年(21)

2012年(219)

我的朋友

分类:

2012-07-27 10:59:19

CentOS版本:CentOS release 5.5 (Final)
系统磁盘:/dev/sda(系统安装要的swap和/目录)
          /dev/sdb(用作drbd使用)

两台主机:ip 10.0.17.155
             10.0.17.156

第一步:定义host:

[root@mysql-n1 ~]# vi /etc/hosts
10.0.17.155     mysql-n1
10.0.17.156     mysql-n2

第二步:创建磁盘(前提有这样一块硬盘,由于我是在vm上面做的实验,所以多模拟出来了

一块硬盘,linux认盘,就是根据盘的个数,自己辨别,第一块就是sda,第二块就是sdb)


[root@mysql-n1 ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *         262        5221    39841200   83  Linux
/dev/sda2               1         261     2096451   82  Linux swap / Solaris

Partition table entries are not in disk order

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

[root@mysql-n1 ~]# fdisk /dev/sdb

依次输入:n-->p-->1 回车-->回车-->w完成


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)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p  
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):
Using default value 2610

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@mysql-n1 ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *         262        5221    39841200   83  Linux
/dev/sda2               1         261     2096451   82  Linux swap / Solaris

Partition table entries are not in disk order

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  83  Linux


第三步:安装drbd
[root@mysql-n1 ~]# yum -y install kmod-drbd83 drbd83

第四步:配置drbd(我只配置/etc/drbd.conf),把配置好的scp到另一台服务器上
global { usage-count no; }
common { syncer { rate 200M; } }
resource r0 {
            protocol C;
            net {
                 cram-hmac-alg sha1;
                 shared-secret "MySQL_HA";
            }

            disk{
               on-io-error detach;
               fencing resource-only;
            }
            startup{
               wfc-timeout 120;
               degr-wfc-timeout 120;
            }
            on mysql-n1 {
                 device    /dev/drbd0;
                 disk      /dev/sdb1;
                 address   10.0.17.155:7898;
                 meta-disk  internal;
            }
            on mysql-n2 {
                 device    /dev/drbd0;
                 disk      /dev/sdb1;
                 address   10.0.17.156:7898;
                 meta-disk  internal;
            }
       }

第五步:DRBD创建元数据库信息:
[root@mysql-n1 ~]# drbdadm create-md all
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.

[root@mysql-n2 ~]# drbdadm create-md all
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.

第六步:启动DRBD
[root@mysql-n1 ~]# /etc/init.d/drbd start

第七步:设置primary节点&mkfs
[root@mysql-n1 ~]# drbdadm primary all(报错,执行下面操作)
0: State change failed: (-2) Need access to UpToDate data
Command 'drbdsetup 0 primary' terminated with exit code 17
[root@mysql-n1 ~]# drbdadm -- --overwrite-data-of-peer primary all

[root@mysql-n1 ~]# mkfs.ext3 /dev/drbd0


第八步:查看drbd的状态
[root@mysql-n1 ~]# cat /proc/drbd
version: 8.3.13 (api:88/proto:86-96)
GIT-hash: 83ca112086600faacab2f157bc5a9324f7bd7f77 build by

mockbuild@builder10.centos.org, 2012-05-07 11:56:36
 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
    ns:5043196 nr:0 dw:0 dr:5051264 al:0 bm:307 lo:1 pe:5 ua:64 ap:0 ep:1 wo:b

oos:15921556
        [===>................] sync'ed: 24.1% (15548/20472)M
        finish: 0:02:02 speed: 129,304 (126,064) K/sec

其中:ro是角色信息:Primary/Secondary(代表这个是主节点)
                    Secondary/Primary(代表这个是副节点)

      ds是磁盘状态:UpToDate/Inconsistent(正在同步,数据还没有一致)
                    UpToDate/UpToDate    (同步完成,数据一致)
      ns是网络传输的数据包:以K为字节
    
      dw是磁盘写操作
      dr是磁盘读操作
       
      
第九步:挂载DRBD分区到/data目录下
[root@mysql-n1 ~]# mkdir /data
[root@mysql-n1 ~]# mount /dev/drbd0 /data
[root@mysql-n1 ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              37G  4.5G   31G  13% /
tmpfs                 502M     0  502M   0% /dev/shm
/dev/drbd0             20G  173M   19G   1% /data


注意:DRBD的英文全称就是Distributed Replicated Block Device(分布式块设备复制),
个人认为,说白了就是对/dev/sdb1的复制。而且Secondary节点的/dev/drbd0是不能进行挂
载的
阅读(815) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~