高可用性集群解释:
一般是指当集群中有某个节点失效的情况下,其上的任务会自动转移到其他正常的节点上。还指可以将集群中的某节点进行离线维护再上线,该过程并不影响整个集群的运行。
今天来做个Heartbeat+DRBD+NFS的高可用文件系统
1、实验VMware虚拟机2台 同时安装CentOS 6.6 x86_64的系统
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 |
[root@ZhongH6100 ~] eth0=172.16.6.100 eth1=172.16.6.101 [root@ZhongH6100 ~] ZhongH6100.wxjr.com.cn [root@ZhongH6100 ~] CentOS release 6.6 (Final) [root@ZhongH6100 ~] [root@ZhongH7100 ~] eth0=172.16.7.100 eth1=172.16.7.101 [root@ZhongH7100 ~] ZhongH7100.wxjr.com.cn [root@ZhongH7100 ~] CentOS release 6.6 (Final) [root@ZhongH7100 ~] |
2、修改主机名、指定hostname能被两主机互相访问、同步时间#下面实验的时候大家仔细看命令是在哪个服务器上执行的仔细区分
是[root@ZhongH6100 ~]还是[root@ZhongH7100 ~]
如果是[root@ZhongH100 ~]那么就是两台机器都需要运行的
1 2 3 4 5 6 7 8 |
[root@ZhongH6100 ~] [root@ZhongH6100 ~] [root@ZhongH7100 ~] [root@ZhongH7100 ~] [root@ZhongH6100 ~] [root@ZhongH7100 ~] [root@ZhongH100 ~] |
3、安装DRBD
DRBD简介DRBD的全称为:DistributedReplicatedBlockDevice(DRBD)分布式块设备复制DRBD是由内核模块和相关脚本而构成,用以构建高可用性的集群。其实现方式是通过网络来镜像整个设备。它允许用户在远程机器上建立一个本地块设备的实时镜像。与心跳连接结合使用,也可以把它看作是一种网络RAID。DRBD工作机制Drbd负责接收数据,把数据写到本地磁盘,然后发送给另一个主机。另一个主机再将数据存到自己的磁盘中。目前,drbd每次只允许对一个节点进行读写访问,这对于通常的故障切换高可用性集群来讲已经足够用了。以后的版本将支持两个节点进行读写存取。DRBD协议说明A数据一旦写入磁盘并发送到网络中就认为完成了写入操作。B收到接收确认就认为完成了写入操作。C收到写入确认就认为完成了写入操作DRBD官方下载地址:http://oss.linbit.com/drbd/
下载 : DRBD-8.4.3.tar.gz
①、准备工作
1 2 3 4 5 |
[root@ZhongH100 ~] [root@ZhongH100 ~] [root@ZhongH100 ~] 2.6.32-504.16.2.el6.centos.plus.x86_64 [root@ZhongH100 ~] |
②、编译安装DRBD
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 |
[root@ZhongH100 ~] [root@ZhongH100 tmp] [root@ZhongH100 tmp] [root@ZhongH6100 drbd-8.4.3] --datarootdir= /usr/local/share/ --with-utils --with-km [root@ZhongH100 drbd-8.4.3] [root@ZhongH100 drbd-8.4.3] [root@ZhongH100 drbd-8.4.3] [root@ZhongH100 drbd-8.4.3] [root@ZhongH100 drbd-8.4.3] [root@ZhongH100 drbd-8.4.3] [root@ZhongH100 drbd-8.4.3] [root@ZhongH100 drbd] [root@ZhongH100 drbd] [root@ZhongH100 drbd] [root@ZhongH100 drbd] [root@ZhongH100 drbd] drbd 310172 0 libcrc32c 1246 1 drbd |
③、准备同步使用的磁盘
准备一个分区以备后面实验用,下面是我在sdb磁盘上新建了一个sdb1的主分区大小事30G
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
[root@ZhongH100 drbd] [root@ZhongH100 drbd] 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 First cylinder (1-7832, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-7832, default 7832): +30G Command (m for help): p Disk /dev/sdb : 64.4 GB, 64424509440 bytes 255 heads, 63 sectors /track , 7832 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: 0x000a8ddb Device Boot Start End Blocks Id System /dev/sdb1 1 3917 31463271 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re- read partition table. Syncing disks. [root@ZhongH100 drbd] |
④、制作环境变量文件、备份原始配置文件、修改配置文件、定义节点上的资源
1 2 3 4 5 |
[root@ZhongH100 drbd] [root@ZhongH100 drbd.d] /etc/drbd/drbd .d [root@ZhongH100 drbd.d] [root@ZhongH100 drbd.d] |
1 2 3 4 5 |
[root@ZhongH100 drbd.d] [root@ZhongH100 drbd.d] 总用量 8 -rw-r--r-- 1 root root 1836 5月 23 21:36 global_common.conf -rw-r--r-- 1 root root 1836 5月 23 21:45 global_common.conf_20150523_backup |
⑤、修改全局配置文件
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
[root@ZhongH100 drbd.d] [root@ZhongH100 drbd.d] global { usage-count no; } common { 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" ; } startup { wfc-timeout 120; degr-wfc-timeout 120; } disk { on-io-error detach; fencing resource-only; } net { cram-hmac-alg "sha1" ; shared-secret "mydrbdlab" ; } syncer { rate 100M; } } |
⑥、定义节点上的资源
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 |
[root@ZhongH100 drbd.d] resource web { on ZhongH6100.wxjr.com.cn { device /dev/drbd0 ; disk /dev/sdb1 ; address 172.16.6.101:7789; meta-disk internal; } on ZhongH7100.wxjr.com.cn { device /dev/drbd0 ; disk /dev/sdb1 ; address 172.16.7.101:7789; meta-disk internal; } } |
⑦、初始化资源
1 2 3 4 5 |
[root@ZhongH100 drbd.d] Writing meta data... initializing activity log NOT initializing bitmap New drbd meta data block successfully created. |
⑧、启动DRBD服务
01 02 03 04 05 06 07 08 09 10 11 12 |
[root@ZhongH100 drbd.d] Stopping all DRBD resources: . Starting DRBD resources: [ create res: web prepare disk: web adjust disk: web adjust net: web ] outdated-wfc-timeout has to be shorter than degr-wfc-timeout outdated-wfc-timeout implicitly set to degr-wfc-timeout (120s) . [root@ZhongH100 drbd.d] |
查看节点 此时节点都是Secondary
1 2 3 |
[root@ZhongH6100 drbd.d] Secondary /Secondary [root@ZhongH6100 drbd.d] |
1 2 3 |
[root@ZhongH7100 drbd.d] Secondary /Secondary [root@ZhongH7100 drbd.d] |
由于默认没有主次节点之分,因而需要设置两个主机的主次节点,选择需要设置为主节点的主机,然后执行如下命令:
drbdadm — –overwrite-data-of-peer primary web #命令解释:调整当前节点上的web资源为主节点
⑨、调整172.16.6.101/172.16.6.100也就是node1也主节点
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[root@ZhongH6100 drbd.d] Secondary /Secondary [root@ZhongH6100 drbd.d] [root@ZhongH6100 drbd.d] 0:web /0 SyncSource Primary /Secondary UpToDate /Inconsistent C r---n- [>....................] sync 'ed: 1.4% (30328 /30724 )M [root@ZhongH6100 drbd.d] version: 8.4.3 (api:1 /proto :86-101) GIT- hash : 89a294209144b68adb3ee85a73221f964d3ee515 build by root@ZhongH6100.wxjr.com.cn, 2015-05-23 21:36:33 0: cs:SyncSource ro:Primary /Secondary ds:UpToDate /Inconsistent C r---n- ns:2462744 nr:0 dw:0 dr:2466464 al:0 bm:150 lo:0 pe:3 ua:3 ap:0 ep:1 wo:f oos:29001596 [>...................] sync 'ed: 7.9% (28320 /30724 )M finish: 0:04:44 speed: 101,772 (91,136) K /sec [root@ZhongH6100 drbd.d] Primary /Secondary [root@ZhongH6100 drbd.d] version: 8.4.3 (api:1 /proto :86-101) GIT- hash : 89a294209144b68adb3ee85a73221f964d3ee515 build by root@ZhongH6100.wxjr.com.cn, 2015-05-23 21:36:33 0: cs:SyncSource ro:Primary /Secondary ds:UpToDate /Inconsistent C r----- ns:9051136 nr:0 dw:0 dr:9051808 al:0 bm:551 lo:3 pe:8 ua:3 ap:0 ep:1 wo:f oos:22419324 [====>...............] sync 'ed: 28.8% (21892 /30724 )M finish: 0:04:06 speed: 90,776 (74,732) K /sec |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
[root@ZhongH6100 drbd.d] SyncSource |
⑩、在主节点上创建文件系统、挂载主节点上的文件系统、在主节点分区中新建个文件
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
[root@ZhongH6100 drbd.d] mke2fs 1.41.12 (17-May-2010) 文件系统标签=drbdweb 操作系统:Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1966560 inodes, 7865567 blocks 393278 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=4294967296 241 block groups 32768 blocks per group, 32768 fragments per group 8160 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 33 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@ZhongH6100 drbd.d] [root@ZhongH6100 drbd.d] [root@ZhongH6100 drbd.d] [root@ZhongH6100 drbd.d] Hello World Legion 2015-05-23 22:45:07 [root@ZhongH6100 drbd.d] |
⑪、更换node1为从节点、node2为主节点卸载DRBD分区且更换node1为从节点
1 2 3 4 5 |
[root@ZhongH6100 drbd.d] [root@ZhongH6100 drbd.d] [root@ZhongH6100 drbd.d] Secondary /Secondary [root@ZhongH6100 drbd.d] |
1 2 3 4 5 6 |
[root@ZhongH7100 drbd.d] [root@ZhongH7100 drbd.d] Primary /Secondary [root@ZhongH7100 drbd.d] 0:web /0 Connected Primary /Secondary UpToDate /UpToDate C r----- [root@ZhongH7100 drbd.d] |
⑫、挂载节点二,查看文件是否同步了 HOHO~~
01 02 03 04 05 06 07 08 09 10 11 12 |
[root@ZhongH7100 drbd.d] [root@ZhongH7100 drbd.d] [root@ZhongH7100 drbd.d] 总用量 20 drwx------ 2 root root 16384 5月 23 22:41 lost+found -rw-r--r-- 1 root root 39 5月 23 22:45 testDRBDfile [root@ZhongH7100 drbd.d] 2015年 05月 23日 星期六 22:55:00 CST [root@ZhongH7100 drbd.d] Hello World Legion 2015-05-23 22:45:07 [root@ZhongH7100 drbd.d] |
到此我们的DRBD的两个节点就配置好了,也测试成功能同步了
原地址:http://www.dwhd.org/20150523_150831.html