Heartbeat+DRBD+NFS
添加路由心跳线
master: # route add -host 10.20.23.111 dev eth2 # echo "/sbin/route add -host 10.20.23.111 dev eth2" >>/ect/rc.local
backup # route add -host 10.20.23.115 dev eth2 # echo "/sbin/route add -host 10.20.23.115 dev eth2" >>/ect/rc.local
配置heartbeat
1、安装heartbeat(主备操作一致) # yum install heartbeat* 2、配置文件 1) 主配置文件 # cat >/etc/ha.d/ha.cf<<EOF debugfile /var/log/ha-debug logfile /var/log/ha-log logfacility local0 keepalive 2 deadtime 30 warntime 10 initdead 60 mcast eth1 225.0.0.1 694 1 0 auto_failback on node master node backup EOF 2) 认证配置 # cat >/etc/ha.d/authkeys <<EOF auth 1 1 sha1 c4f9375f9834b4e7f0a528cc65c055702bf5f24a EOF # chmod 600 /etc/ha.d/authkeys 3) 资源配置 # cat >/etc/ha.d/haresources <<EOF master IPaddr::10.0.0.73/25/eth0 EOF 3、启动主的heartbeat # /etc/init.d/heartbeat start 4、查看vip # ip add|grep 10.0.0. 5、测试 # /etc/init.d/heartbeat stop #停掉主 # ip add|grep 10.0.0. #查看备vip 6、主备切换 # /usr/share/heartbeat/hb_standby # /usr/share/heartbeat/hb_takeover
配置drbd
1、主备各添加一块5G磁盘 2、对新磁盘进行分区 # fdisk -l # parted /dev/sdb mklabel gpt #调整分区表 # parted /dev/sdb mkpart primary ext4 0 1000 #增加一个分区 # parted /dev/sdb mkpart primary ext4 1001 -1 #增加一个分区 # parted /dev/sdb p #查看分区结果 3、格式化 # mkfs.ext4 /dev/sdb1 # tune2fs -c -1 /dev/sdb1 #取消磁盘检查 4、安装DRBD软件 # yum install drbd kmod-drbd84 -y # modprobe drbd #加载到内核 # lsmod | grep drbd 5、开机加载到内核 # echo "modprobe drbd" >>/etc/rc.local # echo "modprobe drbd" >/etc/sysconfig/modules/drbd.modules # chmod 755 /etc/sysconfig/modules/drbd.modules 6、编辑配置文件(主备配置一致) # vim 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.0.82:7788; #监听地址,心跳IP meta-disk /dev/sdb2[0]; #存放meta信息 } on backup { device /dev/drbd0; disk /dev/sdb1; address 10.0.0.83:7788; meta-disk /dev/sdb2[0]; } } 7、初始化drbd # drbdadm create-md data # drbdadm up all 或 # /etc/init.d/drbd start 8、查看状态 # cat /proc/drbd # /etc/init.d/drbd status 9、同步DRBD数据 # drbdadm -- --overwrite-data-of-peer primary data 10、挂载drbd # mount /dev/drbd0 /data
配置nfs
1、安装nfs # yum install -y rpcbind nfs-utils 2、配置nfs共享目录 # cat /etc/exports /data 10.0.0.0/24(rw,sync,all_squash) 3、启动rpcbind和nfs服务 # /etc/init.d/rpcbind start; chkconfig rpcbind off # /etc/init.d/nfs start; chkconfig nfs off 4、查看并挂载 # rpcinfo -p 127.0.0.1 #查看状态 # showmount -e 10.0.0.72 # mount -t nfs 10.0.0.72:/data /data/data1 # df -h
整合Heartbeat、DRBD和NFS服务
1、修改heartbeat配置文件 # vim haresources master drbddisk::data Filesystem::/dev/drbd0::/data::ext4 nfsd IPaddr::10.0.0.72/25/eth0 2、编辑管理nfs脚本 # vim /etc/ha.d/resource.d/nfsd #!/bin/bash case $1 in start) /etc/init.d/nfs restart ;; stop) for proc in rpc.mountd rpc.rquotad nfsd nfsd do killall -9 $proc done ;; esac # chmod +x /etc/ha.d/resource.d/nfsd 3、测试nfs高可用 # /etc/init.d/heartbeat stop # /etc/init.d/heartbeat start NFS有2分钟左右的延迟,通过编写脚本,umount和mount命令控制
QQ:328864113 微信:wuhg2008