您的位置:首页 > 运维架构 > Linux

基于CentOS6.3_x64的drbd8.4.2安装配置

2014-12-13 15:48 357 查看
主机资源:

NameIP配置备注
Master192.168.20.151sda/10G,sdb/10G; 
Slave192.168.20.152sda/10G,sdb/10G; 
********************************************

DRBD下载地址:http://oss.linbit.com/drbd/

********************************************

一、系统基本配置

master、slave都做如下配置。

 

1.配置/etc/hosts文件:

~]# vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.20.151 master
192.168.20.152 slave

 

2.禁用selinux:

~]# sed -i "7s/enforcing/disabled/" /etc/selinux/config

 

3.禁用或卸载iptables,这里我们将iptables卸载:

~]# rpm -e iptables --nodeps

 

4.运行yum update升级内核:

~]# yum update

Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net

………

5.格式化/dev/sdb

 

~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x00034d1a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         157     1048576   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             157        1306     9231360   83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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

~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xf048a83b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n                               #创建新分区                      
Command action
   e   extended
   p   primary partition (1-4)
p                                                                    #创建主分区
Partition number (1-4): 1                               #输入分区号这里是1
First cylinder (1-1305, default 1): 回车               #分区开始的磁柱
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): 回车               #分区结束的磁柱
Using default value 1305

Command (m for help): w                             #保存刚才的配置操作
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

.............. 

5.重启:

~]# reboot

…………

The system is going down for reboot NOW!

 

二、安装DRBD 8.4.2(主备节点配置相同)

1.主备节点安装drbd编译环境:

~]# yum -y install gcc flex wget make kernel-devel kernel-headers git libxslt rpm-build automake autoconf

2.下载DRBD安装文件

~]# wget http://oss.linbit.com/drbd/8.4/drbd-8.4.2.tar.gz

3.解压并安装DRBD文件

~]# tar -zvxf drbd-8.4.2.tar.gz

~]# cd drbd-8.4.2

drbd-8.4.2]# ./configure --prefix=/usr/local/drbd --with-km

drbd-8.4.2]# make KDIR=/usr/src/kernels/`uname -r`/

drbd-8.4.2]# make install

4.安装配置DRBD驱动模块

drbd-8.4.2]# cd drbd

drbd-8.4.2]# make clean

drbd]# make KDIR=/usr/src/kernels/`uname -r`/

drbd]# cp drbd.ko /lib/modules/`uname -r`/kernel/lib/

drbd]# depmod              #创建模块依赖关系的列表

drbd]# cp /usr/local/drbd/etc/rc.d/init.d/drbd /etc/rc.d/init.d/

drbd]# chkconfig --add drbd

drbd]# chkconfig drbd on

 

四、定义DRBD 配置文件 [b](主备节点配置相同)[/b]

~]# cp /usr/local/drbd/etc/drbd.d/global_common.conf /usr/local/drbd/etc/drbd.d/global_common-bak.conf

~]# vi /usr/local/drbd/etc/drbd.d/global_common.conf

global {
        usage-count yes;                         # 是否参加DRBD使用者统计.默认是yes
        # minor-count dialog-refresh disable-ip-verification
}

common {
        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";
        }

        startup {
                wfc-timeout 30;
                degr-wfc-timeout 30;
                outdated-wfc-timeout 30;
        }

        options {
                # cpu-mask on-no-data-accessible
        }

        disk {
                on-io-error detach;
                fencing resource-and-stonith;
                resync-rate 50M;                 # 设置主备节点同步时的网络速率最大值,单位是字节.
        }

        net {
                protocol C;                 # 使用协议C.表示收到远程主机的写入确认后,则认为写入完成.
                cram-hmac-alg sha1;                  # 设置主备机之间通信使用的信息算法.
                shared-secret "123456";
        }
}

~]# vi /usr/local/drbd/etc/drbd.d/redis.res

resource redis{  
        on master {  
                device          /dev/drbd1; #逻辑设备的路径  
                disk            /dev/sdb;  #物理设备  
                address         192.168.20.151:7788;  #IP和监听端口
                meta-disk       internal;  
        }  
        on slave {  
                device          /dev/drbd1;  
                disk            /dev/sdb;  
                address         192.168.20.152:7788;  
                meta-disk       internal;  
        }  


~]# modprobe drbd                     #载入DRBD模块

~]# lsmod |grep drbd                  #确认DRBD模块载入成功

drbd                  314184  0 
libcrc32c               1246  1 drbd

~]# drbdadm create-md redis                 #创建元数据

  --==  Thank you for participating in the global usage survey  ==--
The server's response is:

you are the 4070th user to install this version
md_offset 10737414144
al_offset 10737381376
bm_offset 10737053696

Found some data

 ==> This might destroy existing data! <==

Do you want to proceed?
[need to type 'yes' to confirm] yes

Writing meta data...
initializing activity log
NOT initializing bitmap
New drbd meta data block successfully created.
success

~]# mkdir -p /usr/local/drbd/var/run/drbd

~]#  drbdadm up redis                             #启用资源

Device '1' is configured!
Command 'drbdmeta 1 v08 /dev/sdb internal apply-al' terminated with exit code 20

~]# cat /proc/drbd                                #查看DRBD状态

version: 8.4.2 (api:1/proto:86-101)
GIT-hash: 7ad5f850d711223713d6dcadc3dd48860321070c build by , 2012-12-31 20:26:02

 1: 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:f oos:10485404

~]# mkdir /drbd                                   #为DRBD分区挂载创建路径

**********************************************************************************************************************

设置主节点Primary node(master配置)

~]# drbdadm primary --force redis               #设置master角色为Primary

~]# mkfs.ext4 /dev/drbd1                          #格式化drbd1(逻辑设备)

mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621351 blocks
131067 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2684354560
80 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

正在写入inode表: 完成                            
Creating journal (32768 blocks):
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first.  Use tune2fs -c or -i to override.

~]# mount /dev/drbd1 /drbd                             #挂载DRBD分区

~]# df -h
文件系统              容量  已用  可用 已用%% 挂载点
/dev/sda3             8.7G  1.1G  7.3G  13% /
tmpfs                 497M     0  497M   0% /dev/shm
/dev/sda1             194M   64M  120M  35% /boot
/dev/drbd1            9.9G  151M  9.2G   2% /drbd

 

五、同步测试:

mater操作:

~]# ls
anaconda-ks.cfg  drbd-8.4.2  drbd-8.4.2.tar.gz  install.log  install.log.syslog

~]# cp drbd-8.4.2.tar.gz /drbd

~]# ll /drbd

总用量 676
-rw-r--r-- 1 root root 675803 12月 31 21:14 drbd-8.4.2.tar.gz
drwx------ 2 root root  16384 12月 31 21:07 lost+found

~]# umount /dev/drbd1                    #卸载挂载的DRBD分区

~]# drbdadm secondary redis              #主节点角色降级



slave操作:

~]# drbdadm primary redis                   #备节点设置成primary角色

~]# mount /dev/drbd1 /drbd              #备节点挂载DRBD分区

~]# df -h
文件系统              容量  已用  可用 已用%% 挂载点
/dev/sda3             8.7G  1.1G  7.3G  13% /
tmpfs                 497M     0  497M   0% /dev/shm
/dev/sda1             194M   64M  120M  35% /boot
/dev/drbd1            9.9G  152M  9.2G   2% /drbd

~]# ll /drbd
总用量 676
-rw-r--r-- 1 root root 675803 12月 31 21:14 drbd-8.4.2.tar.gz
drwx------ 2 root root  16384 12月 31 21:07 lost+found

测试完成~!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  DRBD 配置