基于drbd的大数据同步搭建
一:环境准备:
master:10.0.0.72 backup:10.0.0.71
1.主备各添加一块磁盘,2G,3G。
[root@backup ~]# cat /etc/hosts 10.0.0.72 master 10.0.0.71 backup [root@backup ~]# uname -a Linux backup 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux [root@master ~]# uname -a Linux master 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux [root@master ~]# /etc/init.d/iptables stop [root@backup ~]# /etc/init.d/iptables stop [root@backup ~]# setenforce 0 [root@master ~]# setenforce 0 or sed -i 's/SELINUX=enforcing/SELINUX=disabled' /etc/selinux/config
时间同步:
[root@master ~]# ntpdate 10.0.2.2 29 Aug 09:26:22 ntpdate[2288]: step time server 10.0.2.2 offset -28524.389257 sec [root@backup ~]# ntpdate 10.0.2.2 29 Aug 09:26:55 ntpdate[2255]: step time server 10.0.2.2 offset 13332955.402534 sec
添加路由:
master: route add -host 10.20.23.72 dev eth2 echo "/sbin/route add -host 10.20.23.72 dev eth2" >>/ect/rc.local backup route add -host 10.20.23.71 dev eth2 echo "/sbin/route add -host 10.20.23.71 dev eth2" >>/ect/rc.local 检查: route -n
2.对新磁盘进行分区
[root@master ~]# fdisk -l Disk /dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 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@backup ~]# fdisk -l Disk /dev/sdb: 3221 MB, 3221225472 bytes 255 heads, 63 sectors/track, 391 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
备注:16T以上可以使用e2fsprogs进行格式化,或者改成xfs格式
大于2T分区格式化:parted
master,backup都要操作:
master: [root@master ~]# yum install -y parted [root@master ~]# parted /dev/sdb mklabel gpt yes ##调整分区表 Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue? Information: You may need to update /etc/fstab. [root@master ~]# parted /dev/sdb mkpart primary ext4 0 1000 ignore #增加一个分区 Warning: The resulting partition is not properly aligned for best performance. Information: You may need to update /etc/fstab. [root@master ~]# parted /dev/sdb mkpart primary ext4 1001 2000 Yes ignore #增加一个分区 Warning: You requested a partition from 1001MB to 2000MB. The closest location we can manage is 1001MB to 1001MB. Is this still acceptable to you? Warning: The resulting partition is not properly aligned for best performance. Information: You may need to update /etc/fstab. [root@master ~]# parted /dev/sdb p #查看分区结果 Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 2147MB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 17.4kB 1000MB 1000MB primary 2 1001MB 2000MB 998MB primary [root@master ~]# ls /dev/sdb* /dev/sdb /dev/sdb1 /dev/sdb2
备上同样操作
格式化分区:
meta data分区无需格式化
[root@master ~]# mkfs.ext4 /dev/sdb1 [root@master ~]# tune2fs -c -1 /dev/sdb1 #取消磁盘检查 tune2fs 1.41.12 (17-May-2010) Setting maximal mount count to -1 [root@backup ~]# mkfs.ext4 /dev/sdb1 [root@backup ~]# tune2fs -c -1 /dev/sdb1 tune2fs 1.41.12 (17-May-2010) Setting maximal mount count to -1
二:安装DRBD软件:
操作在主备节点上同时操作: master,backup都安装DRBD rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm yum install d r b d kmod-drbd84 -y [root@master src]# rpm -qa d r b d 84-utils kmod-d r b d 84 d r b d84-utils-8.9.8-1.el6.elrepo.x86_64 kmod-drbd84-8.4.9-1.el6.elrepo.x86_64 [root@backup ~]# rpm -qa drbd84-utils kmod-drbd84 drbd84-utils-8.9.8-1.el6.elrepo.x86_64 kmod-drbd84-8.4.9-1.el6.elrepo.x86_64
加载到内核中:
master: [root@master ~]# lsmod | grep drbd [root@master ~]# modprobe drbd [root@master ~]# lsmod | grep drbd drbd 374888 0 libcrc32c 1246 1 drbd backup: [root@backup ~]# lsmod | grep drbd [root@backup ~]# modprobe drbd [root@backup ~]# lsmod | grep drbd drbd 374888 0 libcrc32c 1246 1 drbd echo "modprobe drbd" >>/etc/rc.local or echo "modprobe drbd" >/etc/sysconfig/modules/drbd.modules #加载到内核模块中 chmod 755 /etc/sysconfig/modules/drbd.modules
三:编辑drbd.conf
global { usage-count no; ##是否参加DRBD使用者统计,默认是yes } common { ##通用配置 syncer { rate 100M; ##设置主备节点同步时的网络速率最大值 verify-alg crc32c; } } # primary for drbd1 resource data { ##data是资源名字 protocol C; ##协议 disk { ##磁盘错误控制 on-io-error detach; ##分离 } on master { ##节点hostname device /dev/drbd0; disk /dev/sdb1; ##drbd0对应的磁盘 address 10.0.10.247:7788; ##通讯监听地址,心跳IP meta-disk /dev/sdb2[0]; ##存放meta信息 } on backup { device /dev/drbd0; disk /dev/sdb1; address 10.0.10.248:7788; meta-disk /dev/sdb2[0]; } }
主备配置一致.
master,backup一起执行,初始化drbd
[root@master etc]# drbdadm create-md data initializing activity log NOT initializing bitmap Writing meta data... New drbd meta data block successfully created. [root@backup ~]# drbdadm create-md data
启动drbd:
drbdadm up all or /etc/init.d/drbd start
执行结果输出:
Starting DRBD resources: [ create res: data prepare disk: data adjust disk: data adjust net: data ]
查看启动状态:
cat /proc/drbd or /etc/init.d/drbd status [root@master etc]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.4.9-1 (api:1/proto:86-101) GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15 m:res cs ro ds p mounted fstype 0:data Connected Secondary/Secondary Inconsistent/Inconsistent C [root@backup ~]# cat /proc/drbd version: 8.4.9-1 (api:1/proto:86-101) GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r----- ns:0 nr:0 dw:0 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:976548
master提升为主:
在master执行
drbdadm -- --overwrite-data-of-peer primary data
查看备节点:
说明drbd主备搭建完成,然后可以通过drbd的主备进行数据的同步工作。
嗨、骚年、快来消灭0回复。