什么是DRBD Distribution replicated block device
)是一种基于块设备(block)在不同服务器上进行同步和镜像数据的软件,通过它可以同步复制或者异步镜像
rsync+inotyfi基于物理文件。DRBD工作在内核 当中的,类似于一种驱动模块。DRBD工作的位置在文件系统的
buffer cache和磁盘调度器之间,通过tcp/ip发给另外一台主机到对方的tcp/ip最终发送给对方的drbd,再由
对方的drbd存储在本地对应磁盘 上,类似于一个网络RAID-1功能。在高可用(HA)中使用DRBD功能,
可以代替使用一个共享盘阵。本地(主节点)与远程主机(备节点)的数据可以保 证实时同步。
当本地系统出现故障时,远程主机上还会保留有一份相同的数据,可以继续使用
DRBD原理
DRBD软件工作的位置是在文件系统层级以下,比文件系统更加靠近操作内核及IO栈,在基于DRBD的高可用的两台主机之中,当我们写入到本地磁盘系统时
数据还会被实时的发送到网络中的另一台主机,并以相同的形式记录在另一个磁盘系统中,使得本地与远程主机的
数据保持实时数据同步
这时,如果本地系统出现故障,那么远程主机上还会保留和主节点相同的数据备份可以继续使用
不但数据不会丢失,还会提升数据用户的访问体验,drbd服务作用类似磁盘整列的raid1一样
在高可用ha方案中使用drbd功能,可以代替使用一个共享盘阵,因为数据同时存在于本地的主机和远程节点上,
发生故障转移切换时,远程主机只要使用备用机上面的那一份数据,就可以继续提供服务而不会发生
故障前不一致的问题
drbd工作在磁盘分区和lv逻辑卷上
有两种模式
实时(本地和远程都写完,才成功返回)协议和异步(写完到本地就返回成功)
异步分两种
协议A 异步复制协议 ,本地成功写完就成功,数据放在buffer中,易丢失
协议B 内存同步复制协议,本地写成功,并将数据发到远程后立即返回,若双机掉电就要丢失
协议C 同步复制同步 本地和远程都写完,才成功返回
生产模式
1.单主模式:及主备模式典型的高可用方案
2.复主模式:需要采用共享cluster文件系统,需要从2个节点并发访问数据的场合
同步工具介绍
rsync(实时同步工具sersync,inotify,lsyncd)
scp
nc
nfs网络文件系统
union双机同步
csync2多机同步
软件自身同步机制(mysql,oracle,mongdb,ttserver,redis)文件同步到主库,在同步到从库
drbd
生产场景中会有许多基于drbd的同步解决方案
heartbeat+drbd+drbd+nfs/mfs/gfs
heartbeat+drbd+mysql/oracle
主备模式
名称 接口 ip 用途
master eth0 192.168.0.107 外网管理ip,用于wlan的转发
eth1 192.168.1.107 心跳直连
vip 192.168.0.7 用于提供程序挂载服务
master eth0 192.168.0.108 外网管理ip,用于wlan的转发
eth1 192.168.1.108 心跳直连
vip 192.168.0.8 用于提供程序挂载服务
其他配置如heartbeat一样
[root@data-1-1 ~]# /etc/init.d/iptables stop
[root@data-1-1 ~]# setenforce 0
[root@data-1-2 ~]# /etc/init.d/iptables stop
[root@data-1-2 ~]# setenforce 0
设置主机名改hosts
添加两台的心跳线路由如heartbeat
添加磁盘-》编辑虚拟机设置 磁盘-》硬盘->下一步->scsi->创建新的虚拟磁盘 0.5g&将虚拟磁盘拆分多个文件
备用节点一个g
添加磁盘-》编辑虚拟机设置 磁盘-》硬盘->下一步->scsi->创建新的虚拟磁盘 1g&将虚拟磁盘拆分多个文件
[root@data-1-1 ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x0008aced
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 2358 18631680 83 Linux
/dev/sda3 2358 2611 2031616 82 Linux swap / Solaris
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@data-1-1 ~]# fdisk /dev/sdb
Command (m for help): p#######
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdab6013b
Device Boot Start End Blocks Id System
Command (m for help): n######
Command action
e extended
p primary partition (1-4)
p ########
Partition number (1-4): 1#####
First cylinder (1-512, default 1): ###
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-512, default 512): +384M####3
Command (m for help): p#####
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdab6013b
Device Boot Start End Blocks Id System
/dev/sdb1 1 385 394224 83 Linux
Command (m for help): n#####
Command action
e extended
p primary partition (1-4)
Partition number (1-4): 2
p########
First cylinder (386-512, default 386): ########
Using default value 386
Last cylinder, +cylinders or +size{K,M,G} (386-512, default 512): ########33
Using default value 512
Command (m for help): p#########
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdab6013b
Device Boot Start End Blocks Id System
/dev/sdb1 1 385 394224 83 Linux
/dev/sdb2 386 512 130048 83 Linux
Command (m for help): w######
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@data-1-1 ~]# partprobe生效
root@data-1-2 ~]# 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 0x234fcf08.
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): m###
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p###
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x234fcf08
Device Boot Start End Blocks Id System
Command (m for help): n######
Command action
e extended
p primary partition (1-4)
p############
Partition number (1-4): 1######
First cylinder (1-130, default 1): ####
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): +768M#####3
p####
Partition number (1-4): 2#####
First cylinder (100-130, default 100): ###
Using default value 100
Last cylinder, +cylinders or +size{K,M,G} (100-130, default 130): #####
Using default value 130
Command (m for help): p#####
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x234fcf08
Device Boot Start End Blocks Id System
/dev/sdb1 1 99 795186 83 Linux
/dev/sdb2 100 130 249007+ 83 Linux
Command (m for help): w####
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@data-1-2 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Device Mount point 预期大小 作用
/dev/sdb1 /data 2665G 存储全站图片数据
/dev/sdb2 meta data分区 1G DRDB同步的状态信息