Linux/Python学习论坛-京峰教育

 找回密码
 立即注册

一键登录:

搜索
热搜: 活动 交友 discuz
查看: 1215|回复: 0

CentOS6和CentOS5上配置DRBD服务

[复制链接]

238

主题

288

帖子

1925

积分

超级版主

Rank: 8Rank: 8

积分
1925
QQ
发表于 2015-3-18 11:44:27 | 显示全部楼层 |阅读模式
主DRBD: CentOS6.3
备DRBD: CentOS5.4


在CentOS6中,添加elrepo源,因为默认源没有drbd
[root@cclove ~]# rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org
[root@cclove ~]# rpm -Uvh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
[root@cclove ~]# ▊




CentOS6, 安装drbd,装完目测需要重启,因为安装了一个新的内核,而使用新的内核需要重启,那就重启吧,会自动启动新的内核的
[root@cclove ~]# yum install drbd83  kmod-drbd83
[root@cclove ~]# init 6
[root@cclove ~]# Connection to c6 closed by remote host.
Connection to c6 closed.
cclove@LK ~ $ ▊




重启后查看载入的drbd的模块
[root@cclove ~]# uname -a
Linux cclove.station.cclove.me 2.6.32-358.2.1.el6.x86_64 #1 SMP Wed Mar 13 00:26:49 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@cclove ~]# modprobe -l | grep drbd
weak-updates/drbd83/drbd.ko
[root@cclove ~]# lsmod | grep drbd
drbd                  345459  0
[root@cclove ~]# ▊






CentO5, 安装drbd,装完目测需要重启,因为安装了一个新的内核,而使用新的内核需要重启,那就重启吧,会自动启动新的内核的
[root@centos5 ~]# yum install kmod-drbd83 drbd83 -y
[root@centos5 ~]# init 6
[root@centos5 ~]# Connection to c5 closed by remote host.
Connection to c5 closed.
cclove@LK ~ $ ▊




重启后查看载入的drbd的模块
[root@centos5 ~]# uname -a
Linux centos5.station.cclove.me 2.6.18-348.3.1.el5 #1 SMP Mon Mar 11 19:39:25 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@centos5 ~]# modprobe -l | grep drbd
/lib/modules/2.6.18-348.3.1.el5/weak-updates/drbd83/drbd.ko
[root@centos5 ~]# lsmod | grep drbd
drbd                  300440  0
[root@centos5 ~]# ▊




CentOS6中准备了一块磁盘给drdb,如果是分区也可以
通常来说,主DRBD的磁盘空间会小于辅DRBD,如果等于也可以
[root@cclove ~]# fdisk -l /dev/sdb


Disk /dev/sdb: 7516 MB, 7516192768 bytes
255 heads, 63 sectors/track, 913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


[root@cclove ~]# ▊




配置drbd
看/etc/drbd.conf文件, 它只是包含了/etc/drbd.d/global_common.conf,那么编辑/etc/drbd.d/global_common.conf就可以了
[root@cclove ~]# cat /etc/drbd.conf
# You can find an example in  /usr/share/doc/drbd.../drbd.conf.example


include "drbd.d/global_common.conf";
include "drbd.d/*.res";
[root@cclove ~]# cp /etc/drbd.d/global_common.conf{,.bak}
[root@cclove ~]# cat > /etc/drbd.d/global_common.conf
global
{
        usage-count no;
}


common
{
        syncer
        {
                # 同步的速率,官方的建议是根据带宽以及磁盘速率的最小者的百分之三十来设置
                rate 100K;
                #rate 100M;
        }
}


# 资源名字为cclove
resource cclove
{
        # 使用DRBD的第三种协议,收到远程主机写入确认后认为写入完成
        protocol C;
        handlers
        {
                # 把原配置文件的相应行取消注释
                pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
                pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
                local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
                fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
                split-brain "/usr/lib/drbd/notify-split-brain.sh root";
                out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
        }


        net
        {
                # 验证方式
                cram-hmac-alg "sha1";
                # 共享密钥
                shared-secret "www.cclove.me";
        }


        disk
        {
                on-io-error detach;
                # 使用dopd(drbd outdate-peer daemon)保证在数据不同步的时候不切换
                fencing resource-only;
        }


        startup
        {
                wfc-timeout 120;
                degr-wfc-timeout 120;
        }


        device /dev/drbd0;


        on cclove.station.cclove.me
        {
                disk            /dev/sdb;
                address         192.168.1.112:7788;
                # 元数据的存放方式
                meta-disk       internal;
        }


        on centos5.station.cclove.me
        {
                disk            /dev/sdb;
                address         192.168.1.110:7788;
                meta-disk       internal;
        }
}
[root@cclove ~]# ▊




用drbdadm创建DRBD元数据信息,它会读取配置文件然后在指定块设备创建元数据
[root@cclove ~]# drbdadm create-md all
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[root@cclove ~]# ▊




如果块设备有文件系统则会失败
[root@cclove ~]# dd if=/dev/zero of=/dev/sdb count=100 bs=1M
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.746218 s, 141 MB/s
[root@cclove ~]#
[root@cclove ~]# drbdadm create-md all
md_offset 7516188672
al_offset 7516155904
bm_offset 7515926528


Found ext3 filesystem
     7340032 kB data area apparently used
     7339772 kB left usable by current configuration


Device size would be truncated, which
would corrupt data and result in
'access beyond end of device' errors.
You need to either
   * use external meta data (recommended)
   * shrink that filesystem first
   * zero out the device (destroy the filesystem)
Operation refused.


Command 'drbdmeta 0 v08 /dev/sdb internal create-md' terminated with exit code 40
drbdadm create-md cclove: exited with code 40
[root@cclove ~]# ▊




用0填充一下开头部分就好了
[root@cclove ~]# dd if=/dev/zero of=/dev/sdb count=100 bs=1M
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.746218 s, 141 MB/s
[root@cclove ~]# ▊




在centos5上,/etc/drdb.conf就是彻底的空了
[root@centos5 ~]# cat /etc/drbd.conf
#
# please have a a look at the example configuration file in
# /usr/share/doc/drbd83/drbd.conf
#




[root@centos5 ~]# ▊




那么就把centos6的/etc/drbd.d/global_common.conf复制到centos5的/etc/drbd.conf
[root@cclove ~]# scp /etc/drbd.d/global_common.conf centos5.station.cclove.me:/etc/drbd.conf
root@centos5.station.cclove.me's password:
global_common.conf                                      100% 1467     1.4KB/s   00:00   
[root@cclove ~]# ▊




在centos5上初始化元数据
[root@centos5 ~]# drbdadm create-md all
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[root@centos5 ~]# ▊




在两台机子同时开启drbd服务
[root@cclove ~]# service drbd start
Starting DRBD resources: [ d(cclove) s(cclove) n(cclove) ]...
[root@cclove ~]# ▊




[root@centos5 ~]# service drbd start
Starting DRBD resources: [ d(cclove) s(cclove) n(cclove) ].
[root@centos5 ~]# ▊




在任意机子1秒查看一次/proc/drbd,也就是查看drbd的状态
[root@centos5 ~]# watch -n 1 cat /proc/drbd
Every 1.0s: cat /proc/drbd                                       Wed Mar 20 15:16:40 2013


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: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:7339772




把centos6设置为主DRBD
[root@cclove ~]# drbdadm primary all
[root@cclove ~]# ▊




或者这样把centos6设置为主DRBD
[root@cclove ~]# drbdadm -- --overwrite-data-of-peer primary all
[root@cclove ~]# ▊




DRBD的状态是正在同步,速率是100KB,也就是我们设定的速度
Every 1.0s: cat /proc/drbd                                       Wed Mar 20 15:19:37 2013


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:SyncTarget ro:Secondary/Primary ds:Inconsistent/UpToDate C r-----
    ns:0 nr:66432 dw:66432 dr:0 al:0 bm:4 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:7273340
        [>....................] sync'ed:  1.0% (7100/7164)M
        finish: 1:30:54 speed: 1,320 (1,276) want: 100 K/sec




同步完成后,可以看到,是UpToDate
[root@cclove ~]# cat /proc/drbd
version: 8.3.15 (api:88/proto:86-97)
GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by phil@Build64R6, 2012-12-20 20:09:51
0: cs:Connected rorimary/Secondary ds:UpToDate/UpToDate C r-----
    ns:7162364 nr:0 dw:0 dr:7163028 al:0 bm:438 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[root@cclove ~]# ▊




在CentOS5中也是一样的
[root@centos5 ~]# 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:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
    ns:0 nr:7162364 dw:7162364 dr:0 al:0 bm:438 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[root@centos5 ~]# ▊




当/proc/drbd文件的ro字段是Primary/Secondary的时候,也就是本机是住远端是辅的时候可以进行挂载操作
[root@cclove ~]# mkfs.ext3 /dev/drbd0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
458752 inodes, 1834943 blocks
91747 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1879048192
56 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632


Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@cclove ~]# mount /dev/drbd0 /mnt
[root@cclove ~]# echo 'Hello cc!' > /mnt/cclove
[root@cclove ~]# ▊




设备切换的时候先把主DRBD变成辅的
[root@cclove ~]# umount /mnt
[root@cclove ~]# drbdadm secondary all
[root@cclove ~]# ▊




再把辅的变成主的
[root@centos5 ~]# drbdadm primary all
[root@centos5 ~]# mount /dev/drbd0 /mnt
[root@centos5 ~]# cat /mnt/
cclove      lost+found/
[root@centos5 ~]# cat /mnt/cclove
Hello cc!
[root@centos5 ~]# ▊




还有就是把主DRBD的服务停掉
[root@centos5 ~]# echo 'Good luck, cc!' > /mnt/cc
[root@centos5 ~]# service drbd stop
Stopping all DRBD resources:
.
[root@centos5 ~]# ▊




然后在辅DRBD中强制把辅转为主
[root@cclove ~]# drbdadm -- --overwrite-data-of-peer primary all
[root@cclove ~]# mount /dev/drbd0 /mnt
[root@cclove ~]# cat /mnt/cc
Good luck, cc!
[root@cclove ~]# ▊




这时再把原来的主DRBD服务开启,会发现变成了辅DRBD
[root@centos5 ~]# 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:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
    ns:0 nr:36 dw:36 dr:0 al:0 bm:2 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[root@centos5 ~]# ▊


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|京峰教育,只为有梦想的人 ( 京ICP备15013173号 )

GMT+8, 2020-1-26 06:25 , Processed in 0.037375 second(s), 12 queries , Redis On.

快速回复 返回顶部 返回列表