Heartbeat+DRBD+NFS高可用

一、环境

系统:     CentOS 6.4x64 最小化安装

node1:     192.168.1.13

node2:     192.168.1.14

vip:      192.168.1.15

nfs:      192.168.1.10

二、基础配置

node1和node2的操作一样

#关闭iptables和selinux
[[email protected] ~]# getenforce
Disabled                        #确保这项是正确的
[[email protected] ~]# service iptables stop

#配置本地hosts解析
[[email protected] ~]# echo "192.168.1.13  node1" >>/etc/hosts
[[email protected] ~]# echo "192.168.1.14  node2" >>/etc/hosts
[[email protected] ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.13  node1
192.168.1.14  node2

#配置epel源
[[email protected] ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[[email protected] ~]# sed -i ‘[email protected]#[email protected]@g‘ /etc/yum.repos.d/epel.repo
[[email protected] ~]# sed  -i ‘[email protected]@#[email protected]‘ /etc/yum.repos.d/epel.repo

#同步时间
[[email protected] ~]# yum install ntp -y
[[email protected] ~]# echo "*/10 * * * * /usr/sbin/ntpdate asia.pool.ntp.org  &>/dev/null" >/var/spool/cron/root
[[email protected] ~]# ntpdate asia.pool.ntp.org
21 Jun 17:32:45 ntpdate[1561]: step time server 211.233.40.78 offset -158.552839 sec
[[email protected] ~]# hwclock -w

#配置ssh互信
[[email protected] ~]# ssh-keygen
[[email protected] ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

三、安装配置heartbeat

(1).安装heartbeat

#在ha-node1和ha-node2都执行安装操作
[[email protected] ~]# yum install heartbeat -y

(2).配置ha.cf

[[email protected] ~]# cd /usr/share/doc/heartbeat-3.0.4/
[[email protected] heartbeat-3.0.4]# cp authkeys ha.cf haresources /etc/ha.d/
[[email protected] heartbeat-3.0.4]# cd /etc/ha.d/
[[email protected] ha.d]# ls
authkeys  ha.cf  harc  haresources  rc.d  README.config  resource.d  shellfuncs
[[email protected] ha.d]# egrep -v "^$|^#" /etc/ha.d/ha.cf 
logfile	/var/log/ha-log
logfacility	local1
keepalive 2
deadtime 30
warntime 10
initdead 120
mcast eth0 225.0.10.1 694 1 0
auto_failback on
node node1
node node2
crm no

(3).配置authkeys

[[email protected] ha.d]# dd if=/dev/random bs=512 count=1 | openssl md5
0+1 records in
0+1 records out
21 bytes (21 B) copied, 3.1278e-05 s, 671 kB/s
(stdin)= 4206bd8388c16292bc03710a0c747f59
[[email protected] ha.d]# grep -v ^# /etc/ha.d/authkeys 
auth 1
1 md5 4206bd8388c16292bc03710a0c747f59
#将认证文件权限修改成600
[[email protected] ~]# chmod 600 /etc/ha.d/authkeys

(4).配置haresource

[[email protected] ha.d]# grep -v ^# /etc/ha.d/haresources 
node1 IPaddr::192.168.1.15/24/eth0

(5).启动heartbeat

[[email protected] ha.d]# scp authkeys haresources  ha.cf node2:/etc/ha.d/

#node1启动服务
[[email protected] ~]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO:  Resource is stopped
Done.

[[email protected] ~]# chkconfig heartbeat off
#说明:关闭开机自启动,当服务器重启时,需要人工去启动

#node2启动服务
[[email protected] ~]# /etc/init.d/heartbeat start

#查看结果
[[email protected] ~]# ip a |grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.13/24 brd 192.168.1.255 scope global eth0
    inet 192.168.1.15/24 brd 192.168.1.255 scope global secondary eth0     #vip在主节点上
[[email protected] ~]# ip a |grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.14/24 brd 192.168.1.255 scope global eth0    #备节点上没有vip

(6).测试heartbeat

正常状态

#node1信息
[[email protected] ~]# ip a |grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.13/24 brd 192.168.1.255 scope global eth0
    inet 192.168.1.15/24 brd 192.168.1.255 scope global secondary eth0     #vip在主节点上

#node2信息
[[email protected] ~]# ip a |grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.14/24 brd 192.168.1.255 scope global eth0    #备节点上没有vip

模拟主节点宕机后的状态信息

#在主节点node1停止heartbeat服务
[[email protected] ~]# /etc/init.d/heartbeat stop
Stopping High-Availability services: Done.
[[email protected] ~]# ip a |grep eth0               #主节点的heartbeat服务停止后,vip资源被抢走
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.13/24 brd 192.168.1.255 scope global eth0
    
#在备节点node2查看资源
[[email protected] ~]# ip a |grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.14/24 brd 192.168.1.255 scope global eth0
    inet 192.168.1.15/24 brd 192.168.1.255 scope global secondary eth0

恢复主节点的heartbeat服务

[[email protected] ~]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO:  Resource is stopped
Done.

#主节点的heartbeat服务恢复后,将资源接管回来了
[[email protected] ~]# ip a |grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.13/24 brd 192.168.1.255 scope global eth0
    inet 192.168.1.15/24 brd 192.168.1.255 scope global secondary eth0
    
#查看备节点
[[email protected] ~]# ip a |grep eth0         #vip资源已移除
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.14/24 brd 192.168.1.255 scope global eth0

四、安装部署DRBD

(1).对硬盘进行分区,node1和node2的操作一样

[[email protected] ~]# fdisk /dev/sdb
#说明:/dev/sdb分成2个分区/dev/sdb1和/dev/sdb2,/dev/sdb1=19G
[[email protected] ~]# partprobe /dev/sdb

#对分区进行格式化
[[email protected] ~]# mkfs.ext4 /dev/sdb1
说明:sdb2分区为meta data分区,不需要格式化操作
[[email protected] ~]# tune2fs -c -1 /dev/sdb1
说明:设置最大挂载数为-1,关闭强制检查挂载次数限制

(2).安装DRBD

由于我们的系统是CentOS6.4的,所以我们还需要安装内核模块,版本需要和uname -r保持一致,安装包我们从系统安装软件中提取出来,过程略。node1和node2的安装过程一样,这里只给出node1的安装过程

#安装内核文件
[[email protected] ~]# rpm -ivh kernel-devel-2.6.32-358.el6.x86_64.rpm kernel-headers-2.6.32-358.el6.x86_64.rpm 
[[email protected] ~]# yum install drbd84 kmod-drbd84 -y

(3).配置DRBD

a.修改全局配置文件

[[email protected] ~]# egrep -v "^$|^#|^[[:space:]]+#" /etc/drbd.d/global_common.conf
global {
	usage-count no;
}
common {
	protocol C;
	handlers {
	}
	startup {
	}
	options {
	}
	disk {
                on-io-error detach;
		no-disk-flushes;
		no-md-flushes;
		rate 200M;
	}
	net {
		sndbuf-size 512k;
        	max-buffers     8000;
        	unplug-watermark   1024;
        	max-epoch-size  8000;
        	cram-hmac-alg "sha1";
        	shared-secret "weyee2014";
        	after-sb-0pri disconnect;
        	after-sb-1pri disconnect;
        	after-sb-2pri disconnect;
        	rr-conflict disconnect;
	}
}

b.增加资源

[[email protected] ~]# cat /etc/drbd.d/nfsdata.res
resource nfsdata {
    on node1 {
        device /dev/drbd1;
        disk    /dev/sdb1;
        address 192.168.1.13:7789;
        meta-disk /dev/sdb2 [0];
    }
    on node2 {
        device /dev/drbd1;
        disk  /dev/sdb1;
        address 192.168.1.14:7789;
        meta-disk /dev/sdb2 [0];
 
    }
}

c.将配置文件复制到node2上,重启系统加载drbd模块,初始化meta数据

[[email protected] ~]# scp global_common.conf nfsdata.res node2:/etc/drbd.d/
[[email protected] ~]# depmod
[[email protected] ~]# modprobe drbd
[[email protected] ~]# lsmod |grep drbd
drbd                  365931  0 
libcrc32c               1246  1 drbd

#在node1初始化meta数据
[[email protected] ~]# drbdadm create-md nfsdata
initializing activity log
NOT initializing bitmap
Writing meta data...
New drbd meta data block successfully created.

#在node2上加载模块,初始化meta数据
[[email protected] ~]# depmod
[[email protected] ~]# modprobe drbd
[[email protected] ~]# lsmod |grep drbd
drbd                  365931  0 
libcrc32c               1246  1 drbd
[[email protected] ~]# drbdadm create-md nfsdata
initializing activity log
NOT initializing bitmap
Writing meta data...
New drbd meta data block successfully created.

d.在node1和node2上启动drbd

#node1操作
时间: 2024-08-05 18:10:23

Heartbeat+DRBD+NFS高可用的相关文章

Heartbeat+Drbd+NFS高可用实现

继续之前的操作,来完成heartbeat+drbd+nfs高可用的实现. heartbeat+drbd还是使用原来的环境即可,然而需要添加一台nfs客户端,客户端的信息如下: 主机名 IP地址 角色 server136.contoso.com 192.168.49.136 nfs客户端 一.环境准备 1)注意:因为我的客户端是192.168.49.0/24端,所以这里需要把VIP改为这个网段,所以先修改两个节点的haresources文件,将VIP修改为192.168.49.100.可以根据实际

(转)Heartbeat+DRBD+NFS高可用案例

原文:http://9861015.blog.51cto.com/9851015/1939521--------------------------------Heartbeat+DRBD+NFS高可用案例 9.4 部署DRBD 的需求描述 9.4.1业务需求描述 假设两台服务器Rserver-1/Lserver-1, 其实际IP分别为192.168.236.143(Rserver)和192.168.236.192(Lserver) 配置目标:两台服务器分别配置好DRBD服务后.实现在Rserv

Heartbeat+DRBD+NFS高可用案例

9.4 部署DRBD 的需求描述 9.4.1业务需求描述 假设两台服务器Rserver-1/Lserver-1, 其实际IP分别为192.168.236.143(Rserver)和192.168.236.192(Lserver) 配置目标:两台服务器分别配置好DRBD服务后.实现在Rserver-1机器上/dev/sdb 分区上写入数据.数据会时时的同步到Lserver-1机器上面.一旦服务器Rserver-1机器宕机或硬盘损坏导致数据不可用.Lserver-1机器上的数据此时是picdata-

15、 Heartbeat+DRBD+MySQL高可用架构方案与实施过程细节

15. Heartbeat+DRBD+MySQL高可用架构方案与实施过程细节 参考自:http://oldboy.blog.51cto.com/2561410/1240412 heartbeat和keepalived应用场景及区别 很多网友说为什么不使用keepalived而使用长期不更新的heartbeat,下面说一下它们之间的应用场景及区别: 1.对于web,db,负载均衡(lvs,haproxy,nginx)等,heartbeat和keepalived都可以实现 2.lvs最好和keepa

Heartbeat+DRBD+MySQL高可用方案

Heartbeat+DRBD+MySQL高可用方案 =============================================================================== 概述: =============================================================================== 方案介绍  1.方案介绍及优缺点 ★方案介绍 本方案采用Heartbeat双机热备软件来保证数据库的高稳定性和连续性,数

Heartbeat+DRBD+MySQL高可用方案【转】

转自Heartbeat+DRBD+MySQL高可用方案 - yayun - 博客园 http://www.cnblogs.com/gomysql/p/3674030.html 1.方案简介 本方案采用Heartbeat双机热备软件来保证数据库的高稳定性和连续性,数据的一致性由DRBD这个工具来保证.默认情况下只有一台mysql在工作,当主mysql服务器出现问题后,系统将自动切换到备机上继续提供服务,当主数据库修复完毕,又将服务切回继续由主mysql提供服务. 2.方案优缺点 优点:安全性高.稳

Heartbeat+Drbd+MySQL高可用

一.环境介绍 继续使用之前heartbeat+drbd+nfs的环境,192.168.49.0/24网段用来ssh远程连接,172.16.49.0/24用来做心跳连接,并且也做drbd同步数据使用.因为中间做了好多改变,这里再次给出环境的配置情况. 主机名 角色 IP地址 heartbeat01.contoso.com heartbeat+drbd+mysql(节点1) eth0:192.168.49.133 eth1:172.16.49.133 heartbeat02.contoso.com

Heartbeat+DRBD+MFS高可用

http://ly36843.blog.51cto.com/3120113/1676308 一.环境 系统           CentOS 6.4x64最小化安装 mfs-master       192.168.3.33 mfs-slave       192.168.3.34 vip          192.168.3.35 mfs-chun        192.168.3.36 mfs-client      192.168.3.37 二.基础配置 1 2 3 4 5 6 7 8 9

centos7.5部署heartbeat+DRBD+mysql高可用方案

做双机热备方案需要用到Hearbeat和存储设备(如果没存储设备,可以用DRBD代替,但是最好用存储设备). Heartbeat:如果热备服务器在规定的时间内没有收到主服务器心跳消息那么热备服务器会认为主服务器宕机了,热备服务器就开始工作启动IP.服务等也就是启动故障转移程序.启动故障转移程序的同时并取得主服务器上相关资源服务的控制权,接替主服务器继续不间断的提供服务,从而达到资源及服务高可用性的目的. DRBD(代替存储设备):Distributed Replicated Block Devi